Professional Documents
Culture Documents
f1=300;f2=600;f3=900;f4=1100;Fs=2400;
T=1/Fs;t=0:T:1;
x1=2*sin(2*pi*f1*t);
x2=4*sin(2*pi*f2*t);
x3=2*cos(2*pi*f3*t);
x4=3*cos(2*pi*f4*t);
figure(1)
subplot(221); plot(t,x1); title('tin hieu x1 theo mien thoi gian');axis([0,0.1,0.05,1]);
subplot(222); plot(t,x2); title('tin hieu x2 theo mien thoi gian');axis([0,0.1,0.05,1]);
subplot(223); plot(t,x3); title('tin hieu x3 theo mien thoi gian');axis([0,0.1,0.05,1]);
subplot(224); plot(t,x4); title('tin hieu x4 theo mien thoi gian');axis([0,0.1,0.05,1]);
figure(2)
x=x1+x2+x3+x4;
subplot(511);plot(t,x);title('th x trong mien thoi gian')
x_fft=fft(x);
subplot(512);plot(abs(x_fft));grid on;
title('tin hieu x trong mien tan so');
fc1=450;fc2=1000;N=60;
wn1=2*fc1/Fs; wn2=2*fc2/Fs;
b=fir1(N,[wn1 wn2],'stop');w=0:2*pi/511:pi;
h=freqz(b,1,w);
subplot(513);plot(w/pi,abs(h));
title('dap ung tan so cua bo loc');grid on
y=filter(b,1,x);
y_fft=fft(y);subplot(514);plot(abs(y_fft));
title('tin hieu sau loc y trong mien tan so');
subplot(515);plot(t,y);title('th y trong mien thoi gian');
//sử dụng cửa sổ tam giác
ws=0.5*pi;wp=0.7*pi;
delta=abs(ws-wp);wc=(ws+wp)/2;
M=ceil(6.2*pi/delta)+1;
n=[0:1:(M-1)];
hd=thongthap(wc,M);
w_bar=(bartlett(M))';
h=hd.*w_bar;
subplot(331);stem(n,w_bar);
title('Cua so tam giac');grid on;
xlabel('n');ylabel('w(c)');
subplot(332);stem(n,hd);
title('Dap ung xung li tuong');grid on;
xlabel('n');ylabel('hd(n)');
subplot(333);stem(n,h);
title('Dap ung xung thuc te');grid on;
xlabel('n');ylabel('h(n)');
w=0:pi/511:pi;
h1=freqz(h,1,w);
subplot(334);plot(w/pi,real(h1));
title('Phan thuc cua h(e^{j/omega})');grid on;
xlabel('\omega/\pi');ylabel('Bien do');
subplot(335);plot(w/pi,imag(h1));
title('Phan ao cua h(e^{j/omega})');grid on;
xlabel('\omega/\pi');ylabel('Bien do');
subplot(336);plot(w/pi,abs(h1));
title('Pho bien do');grid on;
xlabel('\omega/\pi');ylabel('Bien do');
subplot(337);plot(w/pi,angle(h1));
title('Pho pha');grid on;
xlabel('\omega/\pi');ylabel('Pha do bang radian');
subplot(338);zplane(h,1);
title('Diem cuc-khong');grid on;
xlabel('Thuc');ylabel('Ao');
//sử dụng pp hamming
Viết hàm thông thấp trước
function hd=thongthap(wc,N)
alpha=(N-1)/2;
n=[0:1:(N-1)];
m=n-alpha+eps;
hd=sin(wc*m)./(pi*m);
sử dụng hamming như sau
wp = 0.2*pi;ws=0.4*pi;
deltaw=abs(ws-wp);
M=ceil(6.6*pi/deltaw)+1;
w_ham=hamming(M);
wc=(ws+wp)/2;
hd=thongthap(wc,M);
h=hd.*w_ham';
w=0:pi/511:pi;
h1=freqz(h,1,w);
plot(w/pi,abs(h1));grid on