Matlab code calculation error
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
AH
am 9 Apr. 2024
Change this line Half_max_mag = abs(HH)/sqrt(2); to Half_max_mag = max(abs(HH))/sqrt(2);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!