BÁO cáo THÍ NGHIỆM 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 ghi nhớ các lệnh matlab trong chương trình trên

23 4 0
BÁO cáo THÍ NGHIỆM 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 ghi nhớ các lệnh matlab trong chương trình trên

Đ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 1812400 Hồ Anh Khoa 1812643 Nguyễn Hồng Long 1812899 Ngày thí nghiệm: 02/10/2021  Thực hành 1: Viết file-M thực chương trình lưu với tên Bai1_NHOMx_PlotGraph.m Yêu cầu 1: 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 subplot(1,2,1); % Create a graph with two sub-graphs in row column and with subplot posi 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');  Xk Thực hành 3: Viết chương trình thực biến đổi IDFT chuỗi 10, 2i, 2, 2i theo cách Lưu lại với tên clc; clear all; Xk = L = length(Xk); xn = zeros(1,L); [10,-2+2j,-2,-2-2j]; %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_2 = 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_2_magnitude = abs(xn_2); % Plot the magnitude response subplot(1,3,2); stem(t,xn_magnitude,'bo-'); hold on; stem(t,xn_2_magnitude,'r* ') ; hold on; ylabel ('Amplitude'); xlabel ('K'); title('Magnitude Response'); %Find the phases of individual IDFT points xn_phase = angle(xn); xn_2_phase = angle(xn_2) %Plot the magnitude sequence subplot(1,3,3); stem(t,xn_phase,'bo-'); hold on; stem(t,xn_2_phase,'r* '); hold on; ylabel ('Phase'); xlabel ('K'); title ('Phase Response'); legend('Computing', 'idft Matlab');  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];  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 toán đáp ứng tần số ii) sử dụng hàm Matlab, lưu với tên Bai1_NHOMx_freqz.m Yêu cầu: Vẽ đáp ứng miền tần số Matlab lọc có hàm truyền sau 0.4z H z Ta có đáp ứng tần số H % 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'); 0.8z  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 tín hiệu Tạo mẫu tín hiệu s tần số 500 Hz Tạo tín hiệu sinc s4 Tạo chu kỳ mẫu tín hiệu s1 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); plot((0:N/2-1)*Fs/N, Xk_Pha(1:N/2) ); clc clear % Signal Genergating Fs = 1e3; % Sampling frequency kHz Ts = 1/Fs; % Sampling period F_xt = 300; % Frequency of signal 300 Hz T_sim = 0.02; % Signal duration in seconds 50 ms t = : Ts : T_sim - Ts; s2 = [0 0 0 1 1 1 1 1 0 0 0]; N = length(s2); % DFT length = signal length Xk = fft(s2, N); % DFT of signal Xk_Man = abs(Xk); Xk_Pha = angle(Xk); % Signal plot figure(1) subplot(1,2,1) grid on hold on plot(t, s2); xlabel('Time (sec)'); ylabel('Amplitude'); subplot(1,2,2) grid on hold on plot(0:N-1, s2); 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); grid on xlabel('Frequency (Hz)'); ylabel('Amplitude'); subplot(1,2,2) plot((0:N/2-1)*Fs/N, Xk_Pha(1:N/2) ); grid on xlabel('Frequency (Hz)'); ylabel('Phase'); Tạo tín hiệu sinc số 500 Hz clc clear % Signal Genergating Fs = 5e2; % Sampling frequency 500hz Ts = 1/Fs; % Sampling period F_xt = 40; % Frequency of signal 40 Hz T_sim = 1; t = : Ts : T_sim - Ts; xn = sinc(2 * pi * F_xt * (t-0.5)); 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'); subplot(1,2,2) plot((0:N/2-1)*Fs/N, Xk_Pha(1:N/2) );  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 through 16 0.0015 Columns 17 through 24 -0.0095 Columns 25 through 32 -0.0000 Columns 33 through 40 -0.0421 Columns 41 through 48 0.0542 Columns 49 through 56 0.0542 Columns 57 through 64 -0.0421 Columns 65 through 72 -0.0000 Columns 73 through 80 -0.0095 Columns 81 through 88 0.0015 Column 89 -0.0004 - Đáp ứng tần số hàm plot: - Đáp ứng tần số hàm semilogy:  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 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 = 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:  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 25003000, 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 %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;  Thực hành 11 : Thiết kế lọc IIR chắn đa dải 1000-1500 25003000, 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 %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 1: Viết file- M thực chương trình lưu với tên Bai1_ NHOMx_ PlotGraph .m Yêu cầu 1: 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... 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_ NHOMx_ freqz .m Yêu cầu: Vẽ đáp ứng miền tần số Matlab. .. Bài l? ?m 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");

Ngày đăng: 13/01/2022, 06:05

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

Tài liệu liên quan