?? fre_sample_fir1.m
字號:
% Name:fre_sample_fir1.m
clear,close all;
N=input('Type in the length N=');
wp=input('Type in the passband edge frequency(in radians) wp=');
ws=input('Type in the stopband edge frequency(in radians) wp=');
wc=(wp+ws)/2;
L=ceil(wc*N/(2*pi));
k=0:N-1;
M=2*pi/N;
H=u(k)-u(k-L);
phai=-pi*k*(N-1)/N;
%H(L+1)=0.5;%H(L+2)=0.1065;%H(L+2)=0.031;
H=H.*exp(i*phai);
kc=fix(N/2);
for i=0:kc;
H(N-(i))=conj(H(i+2));
end
subplot(221)
k=0:2*pi/N:2*pi-2*pi/N;
stem(k/pi,abs(H),'k.')
axis([0,2,0,max(abs(H))]);grid on
xlabel('Frequency *pi')
title('The |H(k)|of a FIR lowpass filter')
h=ifft(H,N);
subplot(222)
k=0:N-1;
stem(k,h,'k.'),axis([0,N-1,1.1*min(real(h)),1.1*max(real(h))])
xlabel('Time index n')
title('The impulse response h(n) of the FIR filter')
grid on
subplot(223)
n=0:2*pi/512:2*pi-2*pi/512;
Hd=fft(h,512);
plot(n/(pi),abs(Hd))
hold on,grid on
k=0:2*pi/N:2*pi-2*pi/N;
plot(k/pi,abs(H),'k.'),axis([0,1,0,1.2*max(abs(H))])
xlabel('Frequency *pi')
subplot(224)
plot(n/pi,20*log10(abs(Hd)/max(abs(Hd))),'k-')
title('The frequency response in dB')
axis([0,1,-80,0])
grid on
xlabel('Frequency *pi')
figure(2)
subplot(224)
plot(n/pi,20*log10(abs(Hd)/max(abs(Hd))),'k-')
title('The frequency response in dB')
axis([0,1,-80,0])
grid on
xlabel('Frequency *pi')
subplot(221)
phi=atan((imag(Hd)+eps)./(real(Hd))+eps);
plot(n/(2*pi),phi,'k'),axis([0,.5,-pi/2,pi/2])
xlabel('Frequency *pi')
grid on
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -