Effacer les filtres
Effacer les filtres

Matlab code calculation error

2 vues (au cours des 30 derniers jours)
Jacob
Jacob le 8 Avr 2024
Commenté : Jacob le 10 Avr 2024
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

Réponse acceptée

AH
AH le 9 Avr 2024
Change this line Half_max_mag = abs(HH)/sqrt(2); to Half_max_mag = max(abs(HH))/sqrt(2);
  1 commentaire
Jacob
Jacob le 10 Avr 2024
That worked Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by