BÁO cáo THÍ NGHIỆM bài môn xử lí số tín hiệu viết file m thực hiện chương trình trên và lưu với tên bai1 NHOMx plotgraph m

31 11 0
BÁO cáo THÍ NGHIỆM bài môn xử lí số tín hiệu viết file m thực hiện chương trình trên và lưu với tên bai1 NHOMx plotgraph m

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

ĐẠI HỌC QUỐC GIA TP HỒ CHÍ MINH TRƯỜNG ĐẠI HỌC BÁCH KHOA BÁO CÁO THÍ NGHIỆM BÀI Mơn: Xử lí số tín hiệu GVDH :Huỳnh Văn Phận Nhóm Nguyễn Quang Huy Hồ Anh Khoa Nguyễn Hoàng Long - 1812400 1812643 1812899 Ngày thí nghiệm: 02/10/2021 Thực hành : Viết file-M thực chương trình lưu với tên Bai1_NHOMx_PlotGraph.m Yêu cầu : Ghi nhớ lệnh matlab chương trình Bài làm x = 0:pi/20:2*pi; % Define vector x from to 2pi with step size pi/100 y = sin(x); % Define vector y subplot(1,2,1); % Create a graph with two sub-graphs in row column and with subplot position plot(x,y,'b-'); % Plot x versus y axis([0 2*pi -1 1]); xlabel('x (pi)'); ylabel('y=sin(x)'); %Label of x-axis and y-axis title('Graph of Continuous Sine from to 2pi'); %Title of graph subplot(1,2,2);stem(x,y,'r-') %Plot p versus q with subplot position axis([0 2*pi -1 1]); xlabel('x (pi)'); ylabel('y=sin(x)'); %Label of p-axis and q-axis title('Graph of Discrete Sine from to 2pi'); %Title of graph Thực hành 2: Viết file-M thực chương trình lưu với tên Bai1_NHOMx_DFT.m ’ ’ Bài làm clc; close all; xn = [1, 2, 3, 4, 5, 6]; L = length(xn); %find the length of the sequence Xk = zeros(1,L); %initialize an array of same size as that %DFT of the sequence for k = 0:L-1 for n = 0:L-1 Xk(k+1) = Xk(k+1) + xn(n+1)*exp(-1j*2*pi*k*n/L); end end % Using FFT Matlab Xk_2 = fft(xn,L); %Plotting input sequence t=0:L-1; subplot(1,3,1); stem(t,xn); ylabel ('Amplitude'); xlabel ('Time Index'); title('Input Sequence'); t=0:L-1; % Find the magnitudes of individual DFT points Xk_magnitude = abs(Xk); Xk_2_magnitude = abs(Xk_2); % plot the magnitude response subplot(1,3,2); stem(t,Xk_magnitude,'bo-'); hold on; stem(t,Xk_2_magnitude,'r* '); hold on; ylabel ('Amplitude'); xlabel ('K'); title('Magnitude Response'); % Find the phases of individual DFT points Xk_phase = angle(Xk); Xk_2_phase = angle(Xk_2); % plot the magnitude sequence subplot(1,3,3); stem(t,Xk_phase,'bo-'); hold on; stem(t,Xk_2_phase,'r* '); hold on; ylabel ('Phase'); xlabel ('K'); title ('Phase Response'); MultibandFIR63.m X I multibandllR63 m Bai1_Nhom1_DFT_Khoa.m X + oiiName n iEỂ■ỈValue New Open Save EĐ a FILE ans Hb o :: Size _ T_ Ũ Find Go To [1,7,24,4 6, 1«89dou -r 1x10 1x89 NAVIGATE MATLAB Drive Đ BAITN1 Khoa 256x1cau9.m 256x com E1MultibandFIR63.m TN1_cau4.asv multibandllR63.m Đ □ Đ Đ □ phulud.asv phulud.m test.m 11 n Bookmark ble bs2 Polder 1x1 1x1 Current 7000 struct H cof 1x63dou 1x63 Name ble den 1x63dou 1x63 □ fflf baitapl asv ble [0,0.1000 1x10 ,0 baitapl m40 F_xt 1x1 □ EB FsBAITN1_Khoa_cau9.asv 500 1x1 aH h n ( ( ( < ( clc; close all; xn = [1, 2, 3, 4, 5, 6]; L = length(xn); %find the length of the sequence xk = zeros(lJL); %inỉtỉalize an array of same sỉze as that %*» E i %DFT of the sequence ? > Run step stop for k = 0:L-1 for n = 0:L-1 n _ 's Run and Advance 10 Xk(k+1) = Xk(k+1) Ractor Run + xn(n+l)*exp(-lj*2*pỉ*k*n/L); -• = - Section 'Ềs Run t0 End 11 end CODE SECTION 12 end 13 14 16 17 % Using FFT Matlab xk_2 = fft(xn,L); %Plotting ỉnput sequence t=0:L-l; subplot(l,3,l); 18 19 stem(tixn); ylabel ('Amplitude'); 20 21 xlabel ('Time Index'); tỉtle('Input Sequence'); 22 23 24 25 26 t=0:L-l; % Fỉnd the magnỉtudes of individual DFT points xk_magnitude = abs(xk); Xk_2_magnỉtude = abs(xk_2); % plot the magnỉtude response 15 Command Window o ■ RUN ▼ Figure ■ Figure ❖ Thực hành 3: Viết chương trình thực biến đổi IDFT chuỗi X (k ) = [10, -2 + 2i, -2, -2 - 2i] theo cách Lưu lại với tên Bai1_NHOMx_IDFT.m Bài làm clc; clear all; Xk = [10,-2+2j,-2,-2-2j]; L = length(Xk); %find the length of the sequence xn = zeros(1,L); %initialize an array of same size as that of input sequence %DFT of the sequence for k = 0:L-1 for n = 0:L-1 xn(k+1)=xn(k+1)+((1/L)*(Xk(n+1)*exp((1i*2*pi*k*n)/L))); end end % Using IDFT Matlab xn = ifft(Xk,L); %Plotting input sequence t=0:L-1; subplot(1,3,1); Xk magnitude = abs(Xk); stem(t,Xk magnitude); ylabel ('Amplitude'); xlabel ('Time Index'); title('Input Sequence'); t=0:L-1; % Find the magnitudes of individual IDFT points xn magnitude = abs(xn); xn magnitude = abs(xn 2); % Plot the magnitude response subplot(1,3,2); stem(t,xn magnitude,'bo-'); hold on; stem(t,xn magnitude,'r* '); hold on; ylabel ('Amplitude'); xlabel ('K'); title('Magnitude Response'); %Find the phases of individual IDFT points xn phase = angle(xn); xn phase = angle(xn 2) %Plot the magnitude sequence subplot(1,3,3); stem(t,xn phase,'bo-'); hold on; stem(t,xn phase,'r* '); hold on; ylabel ('Phase'); xlabel ('K'); title ('Phase Response'); legend('Computing','idft Matlab'); Figure File Edit View Ịnsert Tools Desktop Window Help 10Q- Input Sequence Magnitude Response x 1Q-i7Phase Response —o Computing — idít Matlab 3.5 2.5 -2 < ọ 00 ro D u2 £ < ‘Ọ -8 1.5 -10 -12 0.5 Time Index 12 -14 L í; ❖ Thực hành 4: Viết file-M tìm ngõ y(n) hệ thống nhân với ngõ vào x(n) = [1, 3, 5, 3, 6, 3] đáp ứng xung h(n) = [1,4, 7, 2, 8] theo cách, lưu với tên bai1 _NHOMx_conv.m Bài làm xn = [1, 3, 5, 3, 6, 3]; hn = [1, 4, 7, 2, 8]; Lx = length(xn); N = length(hn); M = N - 1; Ly = Lx + M; yn = zeros(1, Ly); for n = : Ly-1 for m = max(0,n-Lx + 1):min(n,M) yn(n+1) = yn(n+1) + hn(m+1) * xn(n-m+1); end end yn xn = [1, 3, 5, 3, 6, 3]; hn = [1, 4, 7, 2, 8]; HOME PLOTS APPS EDITOR ■;j SI Racỉor VaH C4 Fĩnd ▼ •Jew Open Save Bookmark FILE C ODE ? ặ 10 11 12 13 14 15 lổ 17 18 S ection Advance NhomỊ conV m + nm+ 1) Command Window » bail_ 24 46 67 82 100 57 54 24 57 54 24 Mhoml_conv ỵn = 24 46 67 82 100 Run step Slop § Run to End SECTION ' TN1_cau4.m bai1 xn = [1, 3, 5, 3, 6, 3]; hn = [1, 4, 7, ĩ, 8]; Lx = length(xn); N = length(hn); M = N - 1; Ly = Lx + M; yn = zeros(l, Ly); for n = : Ly-1 for m = max(0jn-Lx + l):min(njM) yn(n+l) = yn(n+l) + hn(m+l) * xn end end BI xn = [1, 3, 5, 3, ỗ, 3]; hn = [1, 4, 7, 2, 8]; conv(xn,hn); RLE VERSIONS Run and NAVIGATE > MATLAB Drive > BAI_1_NHOM1_bs2700_freqz m PUBLISH |zị Section Break iỄI % RUN VIEW ” - © ■ ❖ Thực hành 5: Viết file-M vẽ đáp ứng tần số hệ thống có hàm truyền theo cách: i) tính tốn đáp ứng tần số ii) sử dụng hàm Matlab, lưu với tên Bai1_N HOMx_freqz m Yêu cầu: Vẽ đáp ứng miền tần số Matlab lọc có hàm truyền sau ( ) 1+ 0.4z 8-1 khoảng < (') < % Bài làm Ta có đáp ứng tần số H (o ) + 2e j 1- 0.8e- ' % Sket frequency response of filter - way omega = 0:pi/10:pi; H = (5 + 2*exp(-1j*omega))./(1-0.8*exp(-1j*omega)); H manitude = abs(H); H phase = angle(H); subplot(2,2,1); plot(omega,H manitude); title('Amplitude Response'); subplot(2,2,2); plot(omega,H phase); title('Phase Response'); % Sket frequency response of filter - way a = [1, -0.8]; b = [5, 2]; [H matlab, w] = freqz(b,a); H matlab manitude = abs(H matlab); H matlab phase = angle(H matlab); subplot(2,2,3); plot(omega,H manitude); title('Amplitude Response'); subplot(2,2,4); plot(omega,H phase); title( 'Phase Response'); Thực hành 6: Viết chương trình Matlab thực yêu cầu sau: Tạo chu kỳ mẫu tin hiệu S1 = COS(2K f1t vđi f = 400 Hz, tần số lẫy mẫu 8000 Hz ) Tạo mẫu tin [ì T < t < hiệu 1^0 3 Tạo tin hiệu sinc tần số 500 Hz /4 lấy mẫu vđi 20 chu kỳ T elsewhere ( s4 = Silic 2a f (t : -' vđi f = Hz, < t < (s) lấy mẫu 40 )) Bài làm Tạo chu kỳ mẫu tin hiệu ( sT = cos 2f vđi f1 = 400 Hz, tần số lẫy mẫu 8000 Hz ) clc clear % Signal Genergating Fs = 8e3; % Sampling frequency kHz Ts = 1/Fs; F_xt = 300; % Frequency of signal 300 Hz t = : Ts : 5*Ts; s1 = cos(2 * pi * F_xt * t); N = length(s1); % DFT length = signal length Xk = fft(s1, N); % DFT of signal Xk_Man = abs(Xk); Xk_Pha = angle(Xk); %% Signal plot figure(1) subplot(1,2,1) hold on plot(t, s1); xlabel('Time (sec)'); ylabel('Amplitude'); subplot(1,2,2) hold on plot(0:N-1, s1); xlabel('Sampling index - n'); ylabel('Amplitude'); %% Spectrum plot figure(2) subplot(1,2,1) stem((0:N/2-1)*Fs/N, Xk_Man(1:N/2) / N); xlabel('Frequency (Hz)'); ylabel('Amplitude'); title('Nhom 1'); subplot(1,2,2); s A m pli tu de Prcquency {H;j Tạo mẫu tín hiệu ( ( sinc 2ft f t - 0.5 )) với f4 clc clear % Signal Genergating Fs = 5e2; % Sampling Sampling period frequency 500hz Frequency of signal 40 Hz Ts = 1/Fs; F_xt = 40; T_sim = 1; T_sim - Ts; t = : Ts pi * F_xt * (t-0.5)); xn = sinc(2 * N = length(xn); % DFT length = signal length Xk = fft(xn, N); % DFT of signal Xk_Man = abs(Xk); Xk_Pha = angle(Xk); %% Signal plot figure(1) subplot(1,2,1) hold on plot(t, xn); xlabel('Time (sec)'); ylabel('Amplitude'); subplot(1,2,2) hold on plot(0:N-1, xn); xlabel('Sampling index - n'); ylabel('Amplitude'); %% Spectrum plot figure(2) subplot(1,2,1) stem((0:N/2-1)*Fs/N, Xk_Man(1:N/2) / N); xlabel('Frequency (Hz)'); ylabel('bien do'); = 40 Hz, < t < (s) lấy mẫu tần subplot(1,2,2) Hz, < t < (s) lấy mẫu tần Frequency (Hz) ❖ Thực hành 7: Thực việc thiết kế lọc FIR chắn dải với thơng số ví dụ Lấy hệ số viết chương trình vẽ đáp ứng tần số lọc Lưu lại với tên BAI_1_NHOMx_bs2700_freqz Sử dụng hàm semilogy thay cho plot đưa nhận xét khác biệt Bài làm - Nhập thơng số hình: Columns through -0.0004 Columns 0.0015 0.00 07 throug h: throug h -0.0095 0.00 79 Columns 25 throug h -0.0000 0.00 32 Columns 33 throug h -0.0421 0.01 20 Columns 41 throug h Columns 49 0.0542 0.0953 throug h throug h -0.0421 0.02 85 Columns 65 throug h -0.0000 0.00 27 Columns 73 throug h -0.0095 0.00 22 Columns 81 throug h 0.0015 Column 89 -0.0004 -0.0045 0.0018 -0.0000 0.0002 0.0005 0.0018 0.003 0.002 -0.0075 0.0061 0.0022 -0.0050 0.0027 0.0048 0.0285 -0.0821 0.0337 0.0520 0.0445 0.0953 -0.0632 0.0411 0.0120 0.0010 -0.0072 0.0032 -0.0091 0.0016 0.0079 0.0036 -0.0045 0.0014 -0.0002 -0.0003 0.0007 24 0.001 -0.0091 0.007 0.0006 32 -0.0072 0.001 0.015 -0.0226 40 0.041 -0.0632 0.022 0.0504 48 0.044 0.052 0.900 56 0.03 37 Columns 57 -0.0002 16 0.00 14 Columns 17 0.0542 -0.0003 -0.0821 0.050 0.022 64 0.004 -0.0226 0.015 72 -0.0050 0.000 0.007 80 0.006 -0.0075 0.002 88 0.000 0.000 -0.0000 - Đáp ứng tần số hàm plot: - Đáp ứng tần số hàm semilogy: BAI_1_Nhom1_bs2700_freqzm X + b = bs27000.tf.num; a = bs27000.tf.den; [H_matlabjW] = freqz(b,a); H_matlab_manitude = abs(H_matlab); H_matlab_phase = angle(H_matlab); semỉlogy(wJH_matlab_manitude); tỉtle("dap ung tan so ham semilogy") Command Window » BAI_lJ\lhoml_bs2700_freqz » BAI_l_Nhoml_bs2700_freqz » BAI_l_Nhoml_bs2700_freqz » b=filt2.tf.num ❖ Thực hành 8: Thực việc thiết kế lọc FIR chắn dải với thơng số ví dụ Lấy hệ số viết chương trình vẽ đáp ứng tần số lọc Lưu lại với tên BAI_1_NHOMx_bs2700_freqz Sử dụng hàm semilogy thay cho plot Bài làm 0.1730 + 0.98-4 91 0.1730 - 0.98491 0.1807 + 0.98351 0.1807 - 6.98351 0.2173 + 6.97611 0.2173 - 0.97611 0.2097 + 6.97781 0.2097 - 0.97781 0.1952 + 0.98681 0.1952 - 0.98081 0.1404 + 6.9716Ì 0.1464 - 6.97161 0.1560 + 6.98491 0.1560 - 0.98491 0.2420 ■+• 0.95181 0.2420 - 0.95181 0.2328 + 6.96961 0.2328 - 0.96961 6.1742 + 0.86851 0.1742 - 8.86851 p= k 0.8527 » 50$ - Zp2sos(z>pjk) SOS = 0.8527 1.0600 1.0600 1.6666 1.0606 -0.3329 -0.3614 -0.4194 -6.3466 -6.4345 0.8527 1.6666 1.6060 1.6606 1.0060 1—Current Filter Intormation Structure: pirect-Fọrm II, Second-Order Sections Order 10 Sections stable: Yes Source: Designed 1.0000 1.0000 1.6006 1.0066 1.0000 -0.3484 -6.2809 -6.4840 -6.3119 -0.4656 0.7846 6.9638 0.9645 6.9943 0.9944 Magnitude Response (dB) Frequency (kHz) ResponseType Lovvpass Fĩlter Order Prequency Specitications Magnítude Speciíĩcatĩons Units: • Speciíy order: 10 Highpass Bandpass '• Bandstop Ditterentiat or II Í T I nt Èi • IIR FIR Minìmum order d B Apass: Optĩons Astop: There are no optional parameters íor this design method Elliptic Equiripple [ Design Ẹilter ] 60 Qinninn Piltor b = filt2.tf.num; a = filt2.tf.den; [H_matlab,w]=freqz(b,a); H_matlab_manitude= abs (H_matlab); H_matlab_phase = angle(H_matlab); plot(w,H_matlab_manitude); title("dap ung tan so ham plot"); - Đáp ứng tần số hàm plot: b = fỈlt2.tf.num; a = filt2.tf.den; [H_matlab,w] = freqz(b,a); H_matlab_manitude = abs(Hmatlab); H_matlab_phase = angle(Hmatlab); plot(WjH matlabmanitude); title(”dap ung tan so ham plot”);| b = filt2.tf.num; a = filt2.tf.den; [H_matlab,w]=freqz(b,a); H_matlab_manitude= abs (H_matlab); H_matlab_phase = angle(H_matlab); semilogy (w,H_matlab_manitude); title("dap ung tan so ham semilogy"); - Đáp ứng tần số hàm semilogy: b = filt2.tf.num; a = filt2.tf.den; [H_matlab,w] = freqz(b,a); H_matlab_manitude = abs(H_matlab); H_matlab_phase = angle(Hmatlab); semilogy(w,H_matlab_manitude); title("dap ung tan so ham semilogy");| Thực hành 9: Thực chương trình thiết kế lọc thơng dải đa dải vẽ đáp ứng tần số với yêu cầu ví dụ Bài làm - Bộ lọc FIR: %multibandfir63.m: Multiband FIR filter with 63 coefficients f = [0 0.1 0.12 0.18 0.2 0.3 0.32 0.38 0.4 1]; m = [0 1 0 1 0]; n = 63; cof = remez(n-1,f,m); % frequency response with 256 points [h w] = freqz(cof,1,256); % plot magnitude of the filter plot(f * 5000,m, 'b'); hold on; Bộ lọc IIR: %multibandiir63.m: Multiband IIR filter with 63 coefficients f = [0 0.1 0.12 0.18 0.2 0.3 0.32 0.38 0.4 1]; m = [0 1 0 1 0]; n = 63; [num, den] = yulewalk(n-1,f,m); % frequency response with 256 points [h w] = freqz(num,den,256); % plot magnitude of the filter plot(f * 5000,m, 'b'); hold on; plot(w/pi*5000,abs(h), 'r-.'); grid on Thực hành 10: Thiết kế lọc FIR chắn đa dải 1000-1500 2500-3000, có bậc 62, tần số lấy mẫu 10 kHz Sau vẽ đáp ứng tần số lọc ❖ Bài làm Dải Tần số (Hz) Tần số chuẩn hóa f/FN Biên độ - 0.2 - 1000 1100 - 1400 0.22 - 0.28 1500 - 2500 0.3 - 0.5 2600 - 2900 0.52 - 0.58 3000 - 5000 0.6 - 1 %multibandfir62.m: Multiband FIR filter with 62 coefficients clc; clear all; f = [0 0.2 0.22 0.28 0.3 0.5 0.52 0.58 0.6 1]; m = [1 0 1 0 1]; n = 62; cof = remez(n-1,f,m); % frequency response with 256 points [h w] = freqz(cof,1,256); % plot magnitude of the filter plot(f * 5000,m, 'b'); hold on; — 11 J■ ỊÍỊ ị\ í! FíleFĩg Edit 41 ureView Ịnsert Tool De&ktop Window Ị ị Help Ú !1 ữ®KX’ -f j_L □ r! i' i1 i' A n A íi ị ji íị -í 11 _i_Ị_ ị i 4-i- i ❖ Thực hành 11 : Thiết kế lọc IIR chắn đa dải 1000-1500 2500-3000, có bậc 62, có tần số lấy mẫu 10 kHz Sau vẽ đáp ứng tần số lọc Bài làm Dải Tần số (Hz) - 1000 Tần số chuẩn hóa f/FN Biên độ - 0.2 1100 - 1400 0.22 - 0.28 1500 - 2500 0.3 - 0.5 2600 - 2900 0.52 - 0.58 3000 - 5000 0.6 - 1 %multibandfir62.m: Multiband IIR filter with 62 coefficients clc; clear all; f = [0 0.2 0.22 0.28 0.3 0.5 0.52 0.58 0.6 1]; m = [1 0 1 0 1]; n = 62; [num, den] = yulewalk(n-1,f,m); % frequency response with 256 points [h w] = freqz(num,den,256); % plot magnitude of the filter plot(f * 5000,m, 'b'); hold on; .. .Thực hành : Viết file- M thực chương trình lưu với tên Bai1_ NHOMx_ PlotGraph .m Yêu cầu : Ghi nhớ lệnh matlab chương trình Bài l? ?m x = 0:pi/20:2*pi; % Define vector x from to 2pi with... title('Graph of Discrete Sine from to 2pi'); %Title of graph Thực hành 2: Viết file- M thực chương trình lưu với tên Bai1_ NHOMx_ DFT .m ’ ’ Bài l? ?m clc; close all; xn = [1, 2, 3, 4, 5, 6]; L = length(xn);... -14 L í; ❖ Thực hành 4: Viết file- M t? ?m ngõ y(n) hệ thống nhân với ngõ vào x(n) = [1, 3, 5, 3, 6, 3] đáp ứng xung h(n) = [1,4, 7, 2, 8] theo cách, lưu với tên bai1 _NHOMx_ conv .m Bài l? ?m xn = [1,

Ngày đăng: 21/03/2022, 19:37

Mục lục

    2. Tạo mẫu tín hiệu

    Thực hành 2: Viết một file-M thực hiện chương trình trên và lưu với tên

    ❖ Thực hành 5: Viết một file-M vẽ đáp ứng tần số của hệ thống có hàm truyền trên theo

    Ta có đáp ứng tần số H (o )

    Thực hành 6: Viết các chương trình Matlab thực hiện các yêu cầu sau:

    - Đáp ứng tần số hàm plot:

    - Đáp ứng tần số hàm plot:

Tài liệu cùng người dùng

Tài liệu liên quan