code from digital signal processing using matlab, 3rd edition

M = 25;
alpha = (M-1)/2;
n = 0:M-1;
hd = (2/pi)*((sin((pi/2)*(n-alpha)).^2)./(n-alpha));
hd(alpha+1)=0;
w_han = '(hann(M))';
h = hd .* w_han.';
[Hr,w,c,L] = Hr_Type3(h);
subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response')
axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('hd(n)')
subplot(2,2,2);
stem(n,w_han);
title('Hann Window');
axis([-1 M 0 1.2]); xlabel ' n '); ylabel('w(n)')
subplot(2,2,3); stem(n,h);title('Actual Impulse Response')
axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('h(n)')
w = w'; Hr = Hr';
w = [-fliplr(w), w(2:501)]; Hr = [-fliplr(Hr), Hr(2:501)];
subplot(2,2,4);plot(w/pi,Hr); title('Amplitude Response');grid;
xlabel('frequency in pi units'); ylabel('Hr'); axis([-1 1 -1.1 1.1]);

2 件のコメント

Image Analyst
Image Analyst 2020 年 12 月 27 日
編集済み: Image Analyst 2020 年 12 月 27 日
What about it? Do you have a question about it? Doesn't run for me because you forgot to include Hr_Type3(). Please supply the function Hr_Type3() if you want us to try the code.
muhammad nur adri nawi
muhammad nur adri nawi 2020 年 12 月 27 日
function [Hr,w,c,L] = Hr_Type3(h)
M=length(h);
L=(M-1)/2;
c=[2*h(L+1:-1:1)];
n=[0:1:L];
w=[0:1:500]'*pi/500;
Hr=sin(w*n)*c';
end

サインインしてコメントする。

 採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 12 月 27 日
編集済み: KALYAN ACHARJYA 2020 年 12 月 27 日

0 投票

Note: Here This
w_han = '(hann(M))';
To this > May be Hanning Window here
w_han =hann(M)';
Complete Code:
M = 25;
alpha = (M-1)/2;
n = 0:M-1;
hd = (2/pi)*((sin((pi/2)*(n-alpha)).^2)./(n-alpha));
hd(alpha+1)=0;
w_han =hann(M)';
h = hd .* w_han.';
[Hr,w,c,L] = Hr_Type3(h);
subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response')
axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('hd(n)')
subplot(2,2,2);
stem(n,w_han);
title('Hann Window');
axis([-1 M 0 1.2]); xlabel ' n '); ylabel('w(n)')
subplot(2,2,3); stem(n,h);title('Actual Impulse Response')
axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('h(n)')
w = w'; Hr = Hr';
w = [-fliplr(w), w(2:501)]; Hr = [-fliplr(Hr), Hr(2:501)];
subplot(2,2,4);plot(w/pi,Hr); title('Amplitude Response');grid;
xlabel('frequency in pi units'); ylabel('Hr'); axis([-1 1 -1.1 1.1]);

3 件のコメント

muhammad nur adri nawi
muhammad nur adri nawi 2020 年 12 月 27 日
Error in example (line 6)
w_han =hann(M)';
why I got this error?
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 12 月 27 日
Error message ?
As I have tried with this also
w_han =hann(M);
No coding error in my case
muhammad nur adri nawi
muhammad nur adri nawi 2020 年 12 月 27 日
ok ..got it, it seems that my matlab got problem..thank you

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by