BÁO cáo THÍ NGHIỆM 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

22 9 0
BÁO cáo THÍ NGHIỆM 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

Đ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 KHOA ĐIỆN – ĐIỆN TỬ BỘ MÔN ĐIỆN TỬ -o0o - BÁO CÁO THÍ NGHIỆM XỬ LÍ SỐ TÍN HIỆU GVHD: Huỳnh Văn Phận SVTH: Nguyễn Văn Thường MSSV: 1915443 TP HỒ CHÍ MINH, THÁNG NĂM 2022 download by : skknchat@gmail.com Thực hành 1: Viết file-M thực chương trình lưu với tên BAI1_NHOML07_PlotGraph.m Yêu cầu 1: Ghi nhớ lệnh matlab chương trình Bài làm: Code: 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ị: download by : skknchat@gmail.com Thực hành 2: Viết file-M thực chương lưu với tên Bai1_NHOML07_.m Yêu cầu 1: Ghi nhớ lệnh matlab chương trình Bài làm: Code: 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 download by : skknchat@gmail.com 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'); legend('Computing', 'fft Matlab'); Đồ thị: Thực hành 3: Viết chương trình thực biến đổi IDFT chuỗi X(k) = 10, 2 , 2, 2 theo cách Lưu lại với tên Bai1_NHOML07_IDFT.m Bài làm: Code: 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 download by : skknchat@gmail.com % Using IDFT Matlab xn_2 = ifft(Xk,L); disp(xn_2); Kết quả: 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 hai cách lưu với tên Bai1_NHOML07_conv.m Bài làm; Code: 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 download by : skknchat@gmail.com end yn xn = [1, 3, 5, 3, 6, 3]; hn = [1, 4, 7, 2, 8]; conv(xn,hn); Kết quả: Thực hành 5: Viết file-M vẽ đáp ứng 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_NHOML07_freqz.m Bài làm: Code: clear all; % 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); download by : skknchat@gmail.com 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ị: Thực hành 6: Viết chương trình Matlab thực yêu cầu sau: 1) Tạo chu kỳ mẫu tín hiệu với Hz, tần số lẫy mẫu 8000 Hz download by : skknchat@gmail.com 2) Tạo mẫu tín hiệu lấy mẫu với 20 chu kỳ T 3) Tạo tín hiệu sinc với Hz, (s) lấy mẫu tần số 500 Hz Bài làm: Tạo chu kỳ mẫu tín hiệu với Hz, tần số lẫy mẫu 8000 Hz Code: 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(2,2,1) hold on plot(t, s1); xlabel('Time (sec)'); ylabel('Amplitude'); subplot(2,2,2) hold on plot(0:N-1, s1); xlabel('Sampling index n'); ylabel('Amplitude'); % Spectrum plot figure(1) subplot(2,2,3) stem((0:N/2-1)*Fs/N, Xk_Man(1:N/2) / N); xlabel('Frequency (Hz)'); ylabel('Amplitude'); title('Nhom 1'); subplot(2,2,4); download by : skknchat@gmail.com plot((0:N/2-1)*Fs/N, Xk_Pha(1:N/2) ); xlabel('Frequency (Hz)'); ylabel('Phase'); Đồ thị: Tạo mẫu tín hiệu lấy mẫu với 20 chu kỳ T Code: 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]; download by : skknchat@gmail.com 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(2,2,1) grid on hold on plot(t, s2); xlabel('Time (sec)'); ylabel('Amplitude'); subplot(2,2,2) grid on hold on plot(0:N-1, s2); xlabel('Sampling index n'); ylabel('Amplitude'); % Spectrum plot figure(1) subplot(2,2,3) stem((0:N/2-1)*Fs/N, Xk_Man(1:N/2) / N); grid on xlabel('Frequency (Hz)'); ylabel('Amplitude'); subplot(2,2,4) plot((0:N/2-1)*Fs/N, Xk_Pha(1:N/2) ); grid on xlabel('Frequency (Hz)'); ylabel('Phase'); Đồ thị: download by : skknchat@gmail.com Tạo tín hiệu sinc với Hz, (s) lấy mẫu tần số 500 Hz Code: 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) download by : skknchat@gmail.com 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) ); xlabel('Frequency (Hz)'); ylabel('Pha'); Đồ thị: Thực hành 7: Thực thiết kế lọc FIR chắn dải với thông số VD Lấy hệ số viết chương trình vẽ đáp ứng tần số lọc Lưu download by : skknchat@gmail.com lại với tên Bai_1_NHOML07_bs2700_freqz Sử dụng hàm semiology thay cho plot đưa nhận xét khác biệt Bài làm: download by : skknchat@gmail.com a) Đáp ứng tần số hàm plot: Code: b = bs2700.tf.num; a = bs2700.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'); Kết quả: b) Đáp ứng tần số hàm semiology: Code: b = bs2700.tf.num; a = bs2700.tf.den; [H_matlab,w]=freqz(b,a); download by : skknchat@gmail.com H_matlab_manitude= abs (H_matlab); H_matlab_phase = angle(H_matlab); semilogy(w,H_matlab_manitude); title('dap ung tan so ham plot'); Kết quả: 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.m Sử dụng hàm semilogy thay cho plot Bài làm : download by : skknchat@gmail.com a) Đáp ứng tần số hàm plot : Code : b = bs1750.tf.num; a = bs1750.tf.den; [H_matlab,w]=freqz(b,a); download by : skknchat@gmail.com H_matlab_manitude= abs (H_matlab); H_matlab_phase = angle(H_matlab); plot(w,H_matlab_manitude); title('dap ung tan so ham plot'); Kết : b) Đáp ứng tần số hàm semilogy : Code : b = bs1750.tf.num; a = bs1750.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 plot'); Kết ; download by : skknchat@gmail.com 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: Code: %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; plot(w/pi*5000,abs(h), 'r-.'); Kết quả: download by : skknchat@gmail.com - Bộ lọc IIR: Code: %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-.'); Kết quả: download by : skknchat@gmail.com 10 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: Code: %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; plot(w/pi*5000,abs(h), 'r-.'); download by : skknchat@gmail.com Kết quả: Dải 11 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: Code: %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]; download by : skknchat@gmail.com 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; plot(w/pi*5000,abs(h), 'r-.'); Kêt quả: Dải download by : skknchat@gmail.com ... chu kỳ m? ??u tín hiệu với Hz, tần số lẫy m? ??u 8000 Hz download by : skknchat@gmail.com 2) Tạo m? ??u tín hiệu lấy m? ??u với 20 chu kỳ T 3) Tạo tín hiệu sinc với Hz, (s) lấy m? ??u tần số 500 Hz Bài l? ?m: Tạo... graph Đồ thị: download by : skknchat@gmail.com Thực hành 2: Viết file- M thực chương lưu với tên Bai1_NHOML07_ .m Yêu cầu 1: Ghi nhớ lệnh matlab chương trình Bài l? ?m: Code: clc; close all; xn = [1,...1 Thực hành 1: Viết file- M thực chương trình lưu với tên BAI1_NHOML07_PlotGraph .m Yêu cầu 1: Ghi nhớ lệnh matlab chương trình Bài l? ?m: Code: x = 0:pi/20:2*pi; % Define vector x from to 2pi

Ngày đăng: 24/04/2022, 12:45

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

Tài liệu liên quan