39
TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI KHOA ĐIỆN TỬ VIỄN THÔNG BÁO CÁO THÍ NGHIỆM XỬ LÝ SỐ TÍN HIỆU Giáo viên hướng dẫn : NGUYỄN VIỆT ANH Sinh viên thực hiện : ĐỖ THÀNH THẮNG SHSV : 20072672 Lớp : ĐIỆN TỬ 11-K52 Hà Nội 04/2010

Đỗ Thành Thắng_ báo cáo xử lý số

Embed Size (px)

Citation preview

TRNG I HC BCH KHOA H NI KHOA IN T VIN THNG

BO CO TH NGHIM X L S TN HIU

Gio vin hng dn : NGUYN VIT ANH Sinh vin thc hin : THNH THNG SHSV Lp : 20072672 : IN T 11-K52

H Ni 04/2010

Bo co x l s tn hiu

BI 1: M PHNG H THNG V TN HIU RI RC BNG MATLAB A. Tn hiu v h thng ri rc min n1.1 Vit chng trnh con to mt dy thc ngu nhin xut pht t n1 n n2 v c gi tr ca bin theo phn b GAUSS vi trung bnh bng 0, phng sai bng 1. Yu cu chng trnh con c cc tham s u vo v u ra c nhp theo lnh vi c php : [x,n] = randnseq(n1,n2);function [x,n] = randnseq(n1,n2) %Generates x(n) = a^n; n1 > [Hr,w,c,L] = Hr_Type1(h) -> cho b lc FIR loi 1function [Hr,w,a,L] = Hr_Type1(h) % Computes Amplitude response Hr(w) of a Type-1 LP FIR filter % ----------------------------------------------------------% [Hr,w,a,L] = Hr_Type1(h) % Hr = Amplitude Response % w = frequencies between [0 pi] over which Hr is computed % a = Type-1 LP filter coefficients % L = Order of Hr % h = Type-1 LP filter impulse response

Page 10

Bo co x l s tn hiu% M = length(h); L = (M-1)/2; a = [h(L+1) 2*h(L:-1:1)]; n = [0:1:L]; w = [0:1:500]'*pi/500; Hr = cos(w*n)*a';

>> [Hr,w,c,L] = Hr_Type2(h) -> cho b lc FIR loi 2function [Hr,w,b,L] = Hr_Type2(h) % Computes Amplitude response Hr(w) of a Type-2 LP FIR filter % ----------------------------------------------------------% [Hr,w,b,L] = Hr_Type2(h) % Hr = Amplitude Response % w = frequencies between [0 pi] over which Hr is computed % b = Type-2 LP filter coefficients % L = Order of Hr % h = Type-2 LP filter impulse response % M = length(h); L = M/2; b = 2*h(L:-1:1); n = [1:1:L]; n = n-0.5; w = [0:1:500]'*pi/500; Hr = cos(w*n)*b';

>> [Hr,w,c,L] = Hr_Type3(h) -> cho b lc FIR loi 3function [Hr,w,c,L] = Hr_Type3(h) % Computes Amplitude response Hr(w) of a Type-3 LP FIR filter % ----------------------------------------------------------% [Hr,w,c,L] = Hr_Type3(h) % Hr = Amplitude Response % w = frequencies between [0 pi] over which Hr is computed % c = Type-3 LP filter coefficients % L = Order of Hr % h = Type-3 LP filter impulse response % 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';

Page 11

Bo co x l s tn hiu >> [Hr,w,c,L] = Hr_Type4(h) -> cho b lc FIR loi 4function [Hr,w,d,L] = Hr_Type4(h) % Computes Amplitude response Hr(w) of a Type-4 LP FIR filter % ----------------------------------------------------------% [Hr,w,d,L] = Hr_Type4(h) % Hr = Amplitude Response % w = frequencies between [0 pi] over which Hr is computed % d = Type-4 LP filter coefficients % L = Order of Hr % h = Type-4 LP filter impulse response % M = length(h); L = M/2; d = 2*h(L:-1:1); n = [1:1:L]; n = n-0.5; w = [0:1:500]'*pi/500; Hr = sin(w*n)*d';

2.3. Cho b lc FIR vi p ng xung nh sau: h(n) = { - 4,1, -1,-2,5,6,5,-1,-2,1,-4} a. Xc nh loi ca b lc. Tnh v biu din trn th: b. Dy p ng xung ca b lc c. Cc h s ca b lc d. Hm ln ca p ng tn s e. Phn b im cc v im khng

h = [-4,1,-1,-2,5,6,5,-2,-1,1,-4]; M = length(h); n =0:M-1; [Hr,w,a,L] = Hr_Type1(h); a, L amax = max(a)+1; amin = min(a)-1; %

Page 12

Bo co x l s tn hiusubplot(2,2,1); stem(n,h); axis([-1,2*L+1,amin,amax]); title('Impulse Response'); xlabel('n'); ylabel('h(n)'); % subplot(2,2,3); stem(0:L,a); axis([-1,2*L+1,amin,amax]); title('a(n) coefficients'); xlabel('n'); ylabel('a(n)'); % subplot(2,2,2); plot(w/pi,Hr); grid; title('Type-1 Amplitude Response'); xlabel('frequency in pi units'); ylabel('Hr'); % subplot(2,2,4); zplane(h,1);

2.4. `Cho b lc FIR vi p ng xung nh sau: h(n) = {-4,1,-1,-2,5,6,-5,1,2,-1,4} a. Xc nh loi ca b lc. Page 13

Bo co x l s tn hiu Vit chng trnh tnh v biu din trn th: b. Dy p ng xung ca b lc c. Cc h s ca b lc d. Hm ln ca p ng tn s e. Phn b im cc v im khngh = [-4,1,-1,-2,5,6,-6,-5,2,1,-1,4]; M = length(h); n =0:M-1; [Hr,w,d,L] = Hr_Type4(h); d, L dmax = max(d)+1; dmin = min(d)-1; % subplot(2,2,1); stem(n,h); axis([-1,2*L+1,dmin,dmax]); title('Impulse Response'); xlabel('n'); ylabel('h(n)'); % subplot(2,2,3); stem(1:L,d); axis([-1,2*L+1,dmin,dmax]); title('d(n) coefficients'); xlabel('n'); ylabel('d(n)'); % subplot(2,2,2); plot(w/pi,Hr); grid; title('Type-3 Amplitude Response'); xlabel('frequency in pi units'); ylabel('Hr'); % subplot(2,2,4); zplane(h,1);

Page 14

Bo co x l s tn hiu

2.5. Thit k b lc thng thp theo phng php ca s vi cc tham s u vo nh sau: P = 0,2 ; RP = 0,25dB S = 0,3 ; AS =50dB Tnh v biu din trn th: a. Dy p ng xung ca b lc l tng b. Dy hm ca s Hamming c. Hm ln tuyt i ca p ng tn s d. Hm ln tng i tnh theo dB ca p ng tn swp = 0.2*pi; ws =0.3*pi; tr_width = ws - wp; M = ceil(6.6*pi/tr_width) + 1 n = [0:1:M-1]; wc = (ws+wp)/2;

Page 15

Bo co x l s tn hiuhd = ideal_lp(wc,M); w_ham = (hamming(M))'; h = hd .* w_ham; [db,mag,pha,grd,w] = freqz_m(h,[1]); delta_w = 2*pi/1000; Rp = -(min(db(1:1:wp/delta_w+1))) As = -round(max(db(ws/delta_w+1:1:501))) %plot subplot(2,2,1); stem(n,hd); axis([0,M-1,-0.1,0.3]); title('Ideal Impulse Response'); xlabel('n'); ylabel('hd(n)'); % subplot(2,2,2); stem(n,w_ham); axis([0,M-1,0,1.1]); title('Hamming Window'); xlabel('n'); ylabel('w(n)'); % subplot(2,2,3); stem(n,h); axis([0,M-1,-0.1,0.3]); title('Actual Impulse Response'); xlabel('n'); ylabel('h(n)'); % subplot(2,2,4); plot(w/pi,db); grid; axis([0,1,-100,10]); title('Magnitude Response in dB'); xlabel('frequency in pi units'); ylabel('Decibels');

Page 16

Bo co x l s tn hiu

2.6. Thit k b lc thng thp theo phng php ly mu tn s vi cc tham s u vo nh sau: P = 0,2 ; RP = 0,25dB S = 0,3 ; AS =50dB Gi s rng ta chn p ng xung c chiu di 60 tng ng vi ly 60 mu tn s trong khong [0,2). Di thng c rng l 0,2 tng ng vi 7 mu nhn gi tr 1. Gi s tip rng qu trnh ti u ho ch ra nn chn di chuyn tip 2 mu nhn cc gi tr T1 = 0,5925 v T2 = 0,1099. Vy dy mu cc tn s c cho nh sau: H(k) = {1,1,1,1,1,1,1,T1,T2,0,,0,T2,T1,1,1,1,1,1,1} Tnh v biu din trn th: a. Dy cc mu tn s b. Dy p ng xung ca b lc thc t c. Hm ln tuyt i ca p ng tn s d. Hm ln tng i tnh theo dB ca p ng tn s Page 17

Bo co x l s tn hiu

M = 60; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l; Hrs [ones(1,7),0.5925,0.1099,zeros(1,43),0.1099,0.5925,ones(1,6)]; %Ideal Amp Res sampled Hdr = [1,1,0,0]; wdl = [0,0.2,0.3,1]; %Ideal Amp Res for plotting k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1; angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)]; H = Hrs.*exp(j*angH); h = real(ifft(H,M)); [db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type2(h); %plot subplot(2,2,1); plot(wl(1:31)/pi,Hrs(1:31),'o',wdl,Hdr); axis([0,1,-0.1,1.1]); title('Frequency Samples: M=40, T2 = 0.5925, T1 = 0.1099'); xlabel('frequency in pi units'); ylabel('Hr(k)'); % subplot(2,2,2); stem(l,h); axis([-1,M,-0.1,0.3]); title('Impulse Response'); xlabel('n'); ylabel('h(n)'); % subplot(2,2,3); plot(ww/pi,Hr,wl(1:31)/pi,Hrs(1:31),'o'); axis([0,1,-0.2,1.2]); title('Amplitude Response'); xlabel('frequency in pi units'); ylabel('Hr(w)'); % subplot(2,2,4); plot(w/pi,db); axis([0,1,-100,10]); grid title('Magnitude Response'); xlabel('frequency in pi units'); ylabel('Decibels');

=

Page 18

Bo co x l s tn hiu

2.7. Thit k b lc thng thp theo phng php lp (thut ton ca Parks v McClellan) vi cc tham s u vo nh sau: P = 0,2 ; RP = 0,25dB S = 0,3 ; AS =50dB Trc tin xut pht t di ca dy p ng M theo cng thc

Lp cng vic tm b lc ti u theo ngha Chebyshev (dng lnh firpm) v tng M sau mi ln lp tm ra b lc tho mn yu cu thit k, sau tnh v biu din trn th: a. Dy p ng xung ca b lc thc t b. Hm ln tuyt i ca p ng tn s c. Hm ln tng i tnh theo dB ca p ng tn s

Page 19

Bo co x l s tn hiu d. Hm sai s E()wp = 0.2*pi; ws =0.3*pi; Rp = 0.25; As = 50; delta_w = 2*pi/1000; wsi = ws/delta_w+1; delta1 = (10^(Rp/20)-1)/(10^(Rp/20)+1); delta2 = (1+delta1)*(10^(-As/20)); deltaH = max(delta1,delta2); deltaL = min(delta1,delta2); weights = [delta2/delta1 1]; deltaf = (ws-wp)/(2*pi); M = ceil((-20*log10(sqrt(delta1*delta2))-13)/(14.6*deltaf)+1) f = [0 wp/pi ws/pi 1]; m = [1 1 0 0]; h = firpm(M-1,f,m,weights); [db,mag,pha,grd,w] = freqz_m(h,[1]); Asd = -max(db(wsi:1:501)) % while Asd