1. Trang chủ
  2. » Luận Văn - Báo Cáo

Báo cáo bài 1 TN xử lý số tín hiệu

23 47 1

Đ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

Nội dung

Báo cáo bài 1 TN Xử Lý Số Tín Hiệu online Đại học Bách Khoa Thành phố Hồ chí Minh (HCMUT) Giới thiệu tổng quan về Matlab và một số lệnh chức năng cơ bản.Giới thiệu công cụ SPTool trong hỗ trợ thiết kế bộ lọc số.Thực thi chương trình trên Matlab với các lệnh cơ bản về xử lý tín hiệu rời rạc.

ĐẠI HỌC QUỐC GIA THÀNH PHỐ HỒ CHÍ MINH TRƯỜNG ĐẠI HỌC BÁCH KHOA KHOA ĐIỆN - ĐIỆN TỬ BÁO CÁO THÍ NGHIỆM BỘ MÔN: XỬ LÝ SỐ TÍN HIỆU Nhóm: L10 GIẢNG VIÊN HƯỚNG DẪN: HUỲNH VĂN PHẬN Năm học: 2020 – 2021 Thực hành 1: Viết file-M Bai1_NHOMx_PlotGraph.m thực chương trình lưu với tên 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 Kết quả: 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 clc; close all; xn = L = Xk = that [1, 2, 3, 4, 5, 6]; length(xn); %find the length of the sequence zeros(1,L); %initialize an array of same size as of input sequence %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 DFT 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'); legend('Computing', 'fft Matlab'); Kết quả: 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 clc; close 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 %IDFT of the sequence for n = 0:L-1 for k = 0:L-1 xn(n+1) = xn(n+1) + Xk(k+1)*exp(2j*pi*k*n/L); end xn(n+1) =(1/L)*xn(n+1); end % Using IFFT Matlab xn_2 = ifft(Xk,L); %Plotting input sequence t=0:L-1; % Find the magnitudes of individual DFT points Xk_magnitude = abs(Xk); % plot the magnitude response subplot(1,4,1); stem(t,Xk_magnitude,'bo-'); hold on; ylabel ('Amplitude'); xlabel ('K'); title('Magnitude Response'); Xk_phase = angle(Xk); % plot the magnitude sequence subplot(1,4,2); stem(t,Xk_phase,'bo-'); hold on; ylabel ('Phase'); xlabel ('K'); t=0:L-1; % Find the magnitudes of individual DFT points xn_magnitude = abs(xn); xn_2_magnitude = abs(xn_2); % plot the magnitude response subplot(1,4,3); stem(t,xn_magnitude,'bo-'); hold on; stem(t,xn_2_magnitude,'r* '); hold on; ylabel ('Amplitude'); xlabel ('n'); title('Magnitude Response'); % Find the phases of individual DFT points xn_phase = angle(xn); xn_2_phase = angle(xn_2); % plot the magnitude sequence subplot(1,4,4); stem(t,xn_phase,'bo-'); hold on; stem(t,xn_2_phase,'r* '); hold on; axis([0 -1 1]); ylabel ('Phase'); xlabel ('n'); title ('Phase Response'); legend('Computing', 'ifft Matlab'); 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 cách, lưu với tên Bai1_NHOMx_conv.m clc; close all; 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_2=conv(xn,hn); t=0:Ly-1; % Find the magnitudes of individual DFT points yn_magnitude = abs(yn); yn_2_magnitude = abs(yn_2); % plot the magnitude response subplot(1,1,1); stem(t,yn_magnitude,'bo-'); hold on; stem(t,yn_2_magnitude,'r* '); hold on; ylabel ('Amplitude'); xlabel ('y(n)'); Kết quả: 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_NHOMx_freqz.m clc; close all; omega = 0:pi/10:pi; H = (5 + 2*exp(-1j*omega))./(1-0.8*exp(-1j*omega)); H_magnitude = abs(H); H_phase = angle(H); a = [1, -0.8]; b = [5, 2]; [H_matlab,w] = freqz(b,a); H_matlab_magnitude = abs(H_matlab); H_matlab_phase = angle(H_matlab); subplot(1,2,1); plot(omega,H_magnitude,'b-');hold on; axis([0 pi 35]); plot(w,H_matlab_magnitude,'r ');hold on; axis([0 pi 35]); ylabel ('Amplitude'); xlabel ('w'); title('Magnitude Response'); subplot(1,2,2); plot(omega,H_phase,'b-');hold on; axis([-2*pi 2*pi -2 2]); plot(w,H_matlab_phase,'r ');hold on; axis([-2*pi 2*pi -2 2]); ylabel ('phase'); xlabel ('w'); title('Phase Response'); Kết quả: 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 s1  cos  2 f 1t  với f  400 Hz, tần số lẫy mẫu 8000 Hz clc; % Signal Genergating Fs = 8e3; % Sampling frequency kHz Ts = 1/Fs; % Sampling period F_xt = 400; % Frequency of signal 300 Hz T_sim = 0.0125; % Signal duration in seconds 50 ms t = : Ts : T_sim; xn = cos(2 * pi * F_xt * t); 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'); title('Nhom: L10 | MSSV: 1915642'); subplot(1,2,2); hold on; plot(0:N-1, xn); xlabel('Sampling index - n'); ylabel('Amplitude'); title('Nhom: L10 | MSSV: 1915642'); %% Spectrum plot figure(2) subplot(1,2,1); stem((0:N-1)*Fs/N, Xk_Man(1:N) / N); xlabel('Frequency (Hz)'); ylabel('Amplitude'); title('Nhom: L10 | MSSV: 1915642'); subplot(1,2,2); plot((0:N-1)*Fs/N, Xk_Pha(1:N) ); xlabel('Frequency (Hz)'); ylabel('Phase'); title('Nhom: L10 | MSSV: 1916542'); Kết quả: - chu kỳ tín hiệu theo giây (s) n 10 - Phổ tần số 11 T �t  3T � s3  � elsewhere � Tạo mẫu tín hiệu lấy mẫu với 20 chu kỳ T clc; clear; T_sim=1; Fs=20; Ts=T_sim/20; F_xt=1/T_sim; t=0:Ts:T_sim-Ts; for i=0:length(t)-1 if t(i+1)>=T_sim/4 && t(i+1)> sptool 16 clc; close all; Fs=8000; h = bs2700.tf.num; w=0:pi/20:pi; [H_matlab, w] = freqz(h); H_matlab_manitude = abs(H_matlab); subplot(1,2,1); plot(w,H_matlab_manitude); ylabel ('Magnitude'); xlabel ('w'); title('Dap ung tan so bo loc (plot)'); subplot(1,2,2); semilogy(w,H_matlab_manitude); ylabel ('Magnitude(dB)'); xlabel ('w'); title('Dap ung tan so bo loc (semilogy)'); Kết quả: 17 Nhận xét: Dùng hàm plot để vẽ theo thang tuyến tính semilogy theo thang đo dB, ta thấy dùng hàm semilogy kết gần với lọc ta thiết kế 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 >>sptool clc; close all; Fs=8000; [z,p,k] = tf2zp(bs1750.tf.num, bs1750.tf.den); sos = zp2sos(z,p,k); w = 0:pi/20:pi; [H_matlab, w] = freqz(sos); H_matlab_manitude = abs(H_matlab); subplot(1,2,1); plot(w/2/pi*Fs,H_matlab_manitude); ylabel ('Magnitude(dB)'); 18 xlabel ('w'); title('Dap ung tan so bo loc (plot)'); subplot(1,2,2); semilogy(w/2/pi*Fs,H_matlab_manitude); ylabel ('Magnitude(dB)'); xlabel ('w'); title('Dap ung tan so bo loc (semilogy)'); Kết quả: 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ụ - Ví dụ 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; Fs=10000; FN=Fs/2; cof = remez(n-1,f,m); % frequency response with 256 points [h w] = freqz(cof,1,256); % plot magnitude of the filter plot(f * FN,m, 'b'); hold on; plot(w/pi*FN,abs(h), 'r-.'); Kết quả: 19 - Ví dụ 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; Fs=10000; FN=Fs/2; [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 * FN,m, 'g'); hold on; plot(w/pi*FN,abs(h), 'r-.'); Kết quả: 20 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 %multibandfir63.m: Multiband FIR filter with 63 coefficients f = [0 0.18 0.2 0.3 0.32 0.48 0.5 0.6 0.62 1]; m = [1 0 1 0 1]; n = 62; Fs=10000; FN=Fs/2; cof = remez(n-1,f,m); % frequency response with 256 points [h w] = freqz(cof,1,256); % plot magnitude of the filter plot(f * FN,m, 'b'); hold on; plot(w/pi*FN,abs(h), 'r-.'); Kết quả: 21 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 %multibandfir63.m: Multiband FIR filter with 63 coefficients f = [0 0.18 0.2 0.3 0.32 0.48 0.5 0.6 0.62 1]; m = [1 0 1 0 1]; n = 62; Fs=10000; FN=Fs/2; [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 * FN,m, 'g'); hold on; plot(w/pi*FN,abs(h), 'r-.'); Kết quả: 22 23 ... stem((0:N -1) *Fs/N, Xk_Pha (1: N) ); xlabel('Frequency (Hz)'); ylabel('Phase'); title('Nhom: L10 | MSSV: 19 15642'); 12 Kết quả: - Xung tín hiệu chu kỳ T - Phổ tần số 13 Tạo tín hiệu sinc tần số 500... subplot (1, 2,2); plot((0:N -1) *Fs/N, Xk_Pha (1: N) ); xlabel('Frequency (Hz)'); ylabel('Phase'); title('Nhom: L10 | MSSV: 19 16542'); Kết quả: - chu kỳ tín hiệu theo giây (s) n 10 - Phổ tần số 11 T �t... title('Nhom: L10 | MSSV: 19 15642'); figure(2); subplot (1, 2 ,1) ; stem((0:N -1) *Fs/N, Xk_Man (1: N)/N); xlabel('Frequency (Hz)'); ylabel('Amplitude'); title('Nhom: L10 | MSSV: 19 15642'); subplot (1, 2,2) stem((0:N -1) *Fs/N,

Ngày đăng: 10/03/2022, 11:06

TỪ KHÓA LIÊN QUAN

w