Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB code help, The following is my code beta=4.08858; M=36; n=0:M; wc=0.2*pi;

ID: 2291806 • Letter: M

Question

MATLAB code help,

The following is my code

beta=4.08858;
M=36;
n=0:M;
wc=0.2*pi;
I0=besseli(0,beta);
betaMod=beta.*sqrt(1-(2.*n./M-1).^2);
wn=besseli(0,betaMod)./I0;
hd=sin(wc.*(n-M/2))./(pi.*(n-M/2));
hn=hd.*wn;

%% b
figure
subplot(2,1,1)
stem(hn)
title('Windowed impulse response')
ylabel('h[n]')
xlabel('n')
subplot(2,1,2)
stem(hd)
title('Desired impulse response')
ylabel('hd[n]')
xlabel('n')

%% c
hnNormal=hn./max(abs(hn));
figure
subplot(2,1,1)
stem(hn)
title('Impulse response')
ylabel('h[n]')
xlabel('n')
ylim([-0.5 1])
subplot(2,1,2)
stem(hnNormal)
title('Normalized impulse response')
ylabel('h[n]')
xlabel('n')

%% d
[HN,w1]=freqz(hnNormal);
figure
plot(w1,10.*log10(abs(HN)))
title('Frequency response')
ylabel('Magnitude(dB)')
xlabel('pi*rad/sample')

The code is working perfectly until part d. The code will still run but there is nothing my frequency response graph, and when I open the HN in the workspace, the value stored were NaN+iNaN. Can someone help me solve this problem?

Explanation / Answer

In your code "[HN,w1]=freqz(hnNormal);" this line is erroneous.

Standard  MATLAb code is "[H,W] = freqz(B,A,N)" where B and A are numarator and denominator of a nth order polynomial. It seems the variable "hnNormal" has no denominator part in it.