Plotting multiple Magnitudes in one plot (2024)

5 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

  • Link

    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)
Top Articles
The Best Pulse Oximeter for Home Use
Best Pulse Oximeters Of 2024, According To Research
Somboun Asian Market
Hk Jockey Club Result
Encore Atlanta Cheer Competition
Ave Bradley, Global SVP of design and creative director at Kimpton Hotels & Restaurants | Hospitality Interiors
Buying risk?
Local Dog Boarding Kennels Near Me
Erskine Plus Portal
Classic Lotto Payout Calculator
Spartanburg County Detention Facility - Annex I
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
Craiglist Tulsa Ok
Destiny 2 Salvage Activity (How to Complete, Rewards & Mission)
Dtab Customs
Ess.compass Associate Login
1v1.LOL - Play Free Online | Spatial
CANNABIS ONLINE DISPENSARY Promo Code — $100 Off 2024
U Break It Near Me
V-Pay: Sicherheit, Kosten und Alternativen - BankingGeek
bode - Bode frequency response of dynamic system
Drift Boss 911
*Price Lowered! This weekend ONLY* 2006 VTX1300R, windshield & hard bags, low mi - motorcycles/scooters - by owner -...
Vegas7Games.com
Craigslist Pearl Ms
Lisas Stamp Studio
Yosemite Sam Hood Ornament
Imouto Wa Gal Kawaii - Episode 2
Sadie Sink Reveals She Struggles With Imposter Syndrome
Prey For The Devil Showtimes Near Ontario Luxe Reel Theatre
Scripchat Gratis
Parkeren Emmen | Reserveren vanaf €9,25 per dag | Q-Park
Kirk Franklin Mother Debra Jones Age
James Ingram | Biography, Songs, Hits, & Cause of Death
Rubmaps H
Springfield.craigslist
Clearvue Eye Care Nyc
Save on Games, Flamingo, Toys Games & Novelties
El agente nocturno, actores y personajes: quién es quién en la serie de Netflix The Night Agent | MAG | EL COMERCIO PERÚ
Facebook Marketplace Marrero La
Nsav Investorshub
Keir Starmer looks to Italy on how to stop migrant boats
Umiami Sorority Rankings
Crystal Glassware Ebay
Go Nutrients Intestinal Edge Reviews
Cch Staffnet
Solving Quadratics All Methods Worksheet Answers
Hcs Smartfind
Bumgarner Funeral Home Troy Nc Obituaries
When Is The First Cold Front In Florida 2022
Laurel Hubbard’s Olympic dream dies under the world’s gaze
Saw X (2023) | Film, Trailer, Kritik
Latest Posts
Article information

Author: Rev. Leonie Wyman

Last Updated:

Views: 5263

Rating: 4.9 / 5 (59 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Rev. Leonie Wyman

Birthday: 1993-07-01

Address: Suite 763 6272 Lang Bypass, New Xochitlport, VT 72704-3308

Phone: +22014484519944

Job: Banking Officer

Hobby: Sailing, Gaming, Basketball, Calligraphy, Mycology, Astronomy, Juggling

Introduction: My name is Rev. Leonie Wyman, I am a colorful, tasty, splendid, fair, witty, gorgeous, splendid person who loves writing and wants to share my knowledge and understanding with you.