Matlab code calculation error
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
AH
2024년 4월 9일
Change this line Half_max_mag = abs(HH)/sqrt(2); to Half_max_mag = max(abs(HH))/sqrt(2);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!