Plotting multiple Magnitudes in one plot (2024)

3 views (last 30 days)

Show older comments

Mehdi Jaiem on 21 Jan 2021

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot

Commented: Mathieu NOE on 21 Jan 2021

Accepted Answer: Star Strider

Open in MATLAB Online

Hello everyone,

I intend to use freqz() function I need to plot the magnitude for different border frequencies. But first I need to determine the cut off frequencies.

I used this code but which seems to not give me even a close response to this

%% INitializing Matlab Environment

close all;

clc;

clearvars;

%% 1.1

b=log10(8000);%stop frequency and 100Hz is the pass frequency

yc1=logspace(2,b,23);

yd=stem(yc1);

grid on

xlabel('Borders','FontSize',12);

ylabel('F (Hz)','FontSize',12);

set(gca,'YScale', 'log')

%%

m={};

n={};

h={};

ph={};

j={};

fs=21e3 %sampling frequency

for i= 1:1:23

[u,o] = butter(1,[2*100/fs, (2*yc1(i))/fs],'bandpass');

m{i}=u;

n{i}=o;

%freqz(m{i},n{i});

[h{i},ph{i}]=freqz(m{i},n{i});

figure

subplot(2,1,1)

hold on

plot(ph{i},20*log10(abs(h{i})));

end

hold off

grid

set(gca,'XLim',[0 1e4],'XTick',10.^(0:4),'YLim',[-12 0],'YTick',-12:2:0,'XScale', 'log')

Any Idea on what I am missing ?

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot#answer_603088

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot#answer_603088

Open in MATLAB Online

Put the figure call before the loop, and remove the subplot call:

figure

hold on

for i= 1:1:23

[u,o] = butter(1,[2*100/fs, (2*yc1(i))/fs],'bandpass');

m{i}=u;

n{i}=o;

%freqz(m{i},n{i});

[h{i},ph{i}]=freqz(m{i},n{i});

plot(ph{i},20*log10(abs(h{i})));

end

hold off

This does not exactly produce the plot you posted, however it will get you closer.

I leave the other details to you.

2 Comments

Show NoneHide None

Mehdi Jaiem on 21 Jan 2021

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot#comment_1276758

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot#comment_1276758

Edited: Mehdi Jaiem on 21 Jan 2021

Thank you it solves at least the multiplot issue !

Star Strider on 21 Jan 2021

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot#comment_1276768

As always, my pleasure!

Sign in to comment.

More Answers (1)

Mathieu NOE on 21 Jan 2021

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot#answer_603118

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot#answer_603118

Open in MATLAB Online

hello

according to the picture, your code needed a revision, see below

the bandwith of your filters (BW) should be proportionnal to the center frequency to have identical roll off curves when plotted in log axis

you can test with a fixed constant bandwith , it's no the right option

hope it helps !

%% INitializing Matlab Environment

close all;

clc;

clearvars;

%% 1.1

b=log10(8000);%stop frequency and 100Hz is the pass frequency

BW = 100; % fixed bandwith (Hz)

yc1=logspace(2,b,23);

yd=stem(yc1);

grid on

xlabel('Borders','FontSize',12);

ylabel('F (Hz)','FontSize',12);

set(gca,'YScale', 'log')

%%

fs=21e3 %sampling frequency

for i= 1:1:23

BW = 100; % fixed bandwith (Hz) : NO !!!

% BW should be proportionnal to center frequencies (not fixed)

BW = yc1(i)/5;

f_low = yc1(i) - BW/2;

f_high = yc1(i) + BW/2;

[B,A] = butter(1,[f_low, f_high]*2/fs,'bandpass');

freq = logspace(log10(f_low/4),log10(f_high*4),100),

[h]=freqz(B,A,freq,fs);

figure(2)

hold on

semilogx(freq,20*log10(abs(h)));

end

hold off

grid

set(gca,'XLim',[0 1e4],'XTick',10.^(0:4),'YLim',[-12 0],'YTick',-12:2:0,'XScale', 'log')

2 Comments

Show NoneHide None

Mehdi Jaiem on 21 Jan 2021

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot#comment_1276858

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot#comment_1276858

Open in MATLAB Online

Awesome thank you!

I have to review some notons then since I am new to this topic.

But there are two ine that I did not understand:

BW = yc1(i)/5; %why did you divide by 5

freq = logspace(log10(f_low/4),log10(f_high*4),100) % what is the perpose of 100?

semilogx(freq,20*log10(abs(h))); % I read about semilogx but I did not understand it. why not plot ?

Mathieu NOE on 21 Jan 2021

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot#comment_1277028

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/723128-plotting-multiple-magnitudes-in-one-plot#comment_1277028

BW = yc1(i)/5; %why did you divide by 5

bandwith is a fraction of center frequency , the higher the division factor, the narrower the filter ; just adapt to your own needs

freq = logspace(log10(f_low/4),log10(f_high*4),100) % what is the perpose of 100?

this is the length we want for freq vector; try another value , like 10, and see the plot being not so smooth

semilogx(freq,20*log10(abs(h))); % I read about semilogx but I did not understand it. why not plot ?

try plot to see the difference

Sign in to comment.

Sign in to answer this question.

See Also

Categories

Signal ProcessingSignal Processing ToolboxDigital and Analog FiltersAnalog Filters

Find more on Analog Filters in Help Center and File Exchange

Tags

  • freqz
  • bandpass

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Plotting multiple Magnitudes in one plot (8)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

Plotting multiple Magnitudes in one plot (2024)

FAQs

How do you plot multiple things on the same plot in Matlab? ›

Combine Plots in Same Axes

By default, new plots clear existing plots and reset axes properties, such as the title. However, you can use the hold on command to combine multiple plots in the same axes. For example, plot two lines and a scatter plot. Then reset the hold state to off.

How do you plot multiple lines on the same graph in Matlab? ›

Plot Multiple Lines

Use the figure command to open a new figure window. You can plot multiple lines using the hold on command. Until you use hold off or close the window, all plots appear in the current figure window.

How to plot 2 graphs in one? ›

In Matplotlib, we can draw multiple graphs in a single plot in two ways. One is by using subplot() function and other by superimposition of second graph on the first i.e, all graphs will appear on the same plot.

How to find corner frequency in bode plot in Matlab? ›

The standard transfer function of a Bode magnitude plot is: T F = K ( 1 + s ω 1 ) ( 1 + s ω 2 ) … s n ( 1 + s ω 3 ) ( 1 + s ω 4 ) … Here, ω1, ω2, ω3, ω4, … are the corner frequencies.

How to plot multiple data points in MATLAB? ›

plot(x1, y1), hold on, plot(x2, y2), plot(x3, y3), ... etc, would work, as long as there are all the correspending yn to all xn, they (x1, x2, x3 etc) can also be different lenghts (only x1 and y1 need to be the same and so on).

How to plot two variables in MATLAB? ›

Here is a sample code to plot your functions:
  1. % Define the functions.
  2. f1 = @(x, y) x.^3 - y.^2 - 1;
  3. f2 = @(x, y) 0.5 + cos(x).*tanh(y);
  4. % Create a new figure.
  5. figure;
  6. % Plot the first function.
  7. fimplicit(f1, [-2, 2, -2, 2], 'r');
  8. hold on;
Mar 5, 2024

How do you plot multiple vertical lines in MATLAB? ›

Direct link to this answer
  1. In Matlab r2018b or later, you can use xline() to plot vertical lines or yline for horizontal lines.
  2. In MATLAB R2021a or later.
  3. xline and yline accept a vector of values to plot multiple lines.
  4. Specify the line style or add a line label using the 2nd and 3rd inputs xline(xvalue,LineSpec,label).
Sep 25, 2016

How to plot multiple axis in MATLAB? ›

To plot two sets of data with separate x- and y-axes, create two separate axes objects in a tiled chart layout. Within one of the axes objects, move the x-axis to the top of the plot box, and move the y-axis to the right side of the plot box.

How to plot 3 graphs in one figure R? ›

R makes it easy to combine multiple plots into one overall graph, using either thepar( ) or layout( ) function. With the par( ) function, you can include the option mfrow=c(nrows, ncols) to create a matrix of nrows x ncols plots that are filled in by row. mfcol=c(nrows, ncols) fills in the matrix by columns.

What is the magnitude of the Bode plot? ›

In a bode plot, the magnitude of the impedance and phase is plotted as a function of frequency on a log scale. The bode plot explicitly shows the frequency at which each data point was taken.

Is corner frequency the same as cutoff frequency? ›

In physics and electrical engineering, a cutoff frequency, corner frequency, or break frequency is a boundary in a system's frequency response at which energy flowing through the system begins to be reduced (attenuated or reflected) rather than passing through.

How to plot a Nyquist plot in MATLAB? ›

To create Nyquist plots with default options or to extract the standard deviation, real and imaginary parts of the frequency response data, use nyquist . h = nyquistplot( sys ) plots the Nyquist plot of the dynamic system model sys and returns the plot handle h to the plot.

How do you plot multiple images in the same figure in MATLAB? ›

You can use subimage in conjunction with subplot to create figures with multiple images, even if the images have different colormaps. subimage converts images to RGB for display purposes, thus avoiding colormap conflicts. subimage( X , map ) displays the indexed image X with colormap map in the current axes.

How to plot two functions on the same graph? ›

A pretty concise method is to concatenate the function values horizontally to make an array of shape (len(t), 3) and call plot() . t = np. linspace(0, 2*np. pi, 400) a = np.

How to plot multiple bar plots in MATLAB? ›

To plot a single series of bars, specify y as a vector of length m. The bars are positioned from 1 to m along the x-axis. To plot multiple series of bars, specify y as a matrix with one column for each series.

Which command you can plot multiple plots on the same graph? ›

In Matplotlib, subplots are a way to have multiple plots on the same figure. Subplots can be arranged in different configurations depending on your needs. The `plt. subplots()` function is used to create subplots.

Top Articles
Practical Introduction to Frequency-Domain Analysis - MATLAB & Simulink Example
Short-time Fourier transform - MATLAB stft
Methstreams Boxing Stream
Directions To Franklin Mills Mall
Farepay Login
Can ETH reach 10k in 2024?
Comforting Nectar Bee Swarm
Www.metaquest/Device Code
Overnight Cleaner Jobs
Myhr North Memorial
Craigslist Kennewick Pasco Richland
Barstool Sports Gif
Kagtwt
My.doculivery.com/Crowncork
Day Octopus | Hawaii Marine Life
Turbocharged Cars
Shooting Games Multiplayer Unblocked
How Much Is Tj Maxx Starting Pay
Job Shop Hearthside Schedule
Dc Gas Login
Playgirl Magazine Cover Template Free
Commodore Beach Club Live Cam
Wicked Local Plymouth Police Log 2022
Unterwegs im autonomen Freightliner Cascadia: Finger weg, jetzt fahre ich!
What Individuals Need to Know When Raising Money for a Charitable Cause
Apparent assassination attempt | Suspect never had Trump in sight, did not get off shot: Officials
Greensboro sit-in (1960) | History, Summary, Impact, & Facts
Impact-Messung für bessere Ergebnisse « impact investing magazin
Wood Chipper Rental Menards
How Do Netspend Cards Work?
Brenda Song Wikifeet
Ourhotwifes
Truis Bank Near Me
Litter-Robot 3 Pinch Contact & DFI Kit
Ark Unlock All Skins Command
Atlantic Broadband Email Login Pronto
D3 Boards
Ursula Creed Datasheet
Sc Pick 4 Evening Archives
140000 Kilometers To Miles
Ferguson Showroom West Chester Pa
Updates on removal of DePaul encampment | Press Releases | News | Newsroom
Cnp Tx Venmo
Atom Tickets – Buy Movie Tickets, Invite Friends, Skip Lines
Rs3 Nature Spirit Quick Guide
Quick Base Dcps
John M. Oakey & Son Funeral Home And Crematory Obituaries
Menu Forest Lake – The Grillium Restaurant
Elvis Costello announces King Of America & Other Realms
Craigslist Com Brooklyn
Tanger Outlets Sevierville Directory Map
Ssss Steakhouse Menu
Latest Posts
Article information

Author: Francesca Jacobs Ret

Last Updated:

Views: 6686

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Francesca Jacobs Ret

Birthday: 1996-12-09

Address: Apt. 141 1406 Mitch Summit, New Teganshire, UT 82655-0699

Phone: +2296092334654

Job: Technology Architect

Hobby: Snowboarding, Scouting, Foreign language learning, Dowsing, Baton twirling, Sculpting, Cabaret

Introduction: My name is Francesca Jacobs Ret, I am a innocent, super, beautiful, charming, lucky, gentle, clever person who loves writing and wants to share my knowledge and understanding with you.