Matlab code calculation error

1 回表示 (過去 30 日間)
Jacob
Jacob 2024 年 4 月 8 日
コメント済み: Jacob 2024 年 4 月 10 日
Hello,
I am trying to calculate the width of a bandpass filter with matlab code but I am coming up with the wrong calculation and I am not sure what I need to change in my matlab code to get the right calculation.
This is the code I am using below
L = 51;
wc=0.2*pi;
Beta=1;
nn=0:(L-1); % filter length
hh=Beta*cos(wc*nn); % filter impulse response , 2/L+1
ww=0:(pi/500):(0.5*pi);
HH=freqz(hh,1,ww);
max_mag = max(abs(HH));
Beta = 1/max_mag;
hh=Beta*cos(wc*nn);
HH=freqz(hh,1,ww);
Half_max_mag = abs(HH)/sqrt(2);
xlabel('Normalized radian frequency')
jkl=find(abs(HH)>=Half_max_mag);
w2 = max(ww(jkl))
w1 = min(ww(jkl))
bandwidth = w2-w1
figure(2)
subplot(2,1,1);
plot(ww/pi,abs(HH))
yline(max(abs(HH))/sqrt(2), '--g', '3db points')
xline(w1/pi, '--r', 'w1');
xline(w2/pi, '--b', 'w2');
subplot(2,1,2);
plot(ww/pi,angle(HH))
These are the Values I am getting with this code below.
W1 = 0
W2 = 1.5708
bandwidth = 1.5708
These are the Values I am supposed to be getting with this code below but I am not getting them and I can't figure out what code to change to get that happen.
W1 = 0.5777
W2 = 0.6842
bandwidth = 0.1065

採用された回答

AH
AH 2024 年 4 月 9 日
Change this line Half_max_mag = abs(HH)/sqrt(2); to Half_max_mag = max(abs(HH))/sqrt(2);
  1 件のコメント
Jacob
Jacob 2024 年 4 月 10 日
That worked Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by