Matlab code calculation error
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
AH
le 9 Avr 2024
Change this line Half_max_mag = abs(HH)/sqrt(2); to Half_max_mag = max(abs(HH))/sqrt(2);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Analog Filters dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!