THÔNG TIN TÀI LIỆU
ĐẠ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 XỬ LÝ SỐ TÍN HIỆU BÀI 1: GIỚI THIỆU MATLAB CƠ BẢN THỰC HÀNH Viết file-M thực đoạn chương trình sau - Code Matlab: clc; clear all; 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 subgraphs in row columns % and with subplot position plot(x,y,'r-'); % plot x versus y axis ([0 2*pi -1 1]); xlabel ('x (pi)'); ylabel ('y=sinx'); title ('Graph of continuous sine from to 2pi'); subplot(1,2,2); stem(x,y,'g-'); axis([0 2*pi -1 1]); xlabel ('x (pi)'); ylabel ('y=sinx'); title ('Graph of discrete sine from to 2pi'); - Kết mô phỏng: 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 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 FFT Matlab Xk_2 = fft(xn,L); THỰC HÀNH Viết file-M thực chương trình sau - Code Matlab: - Kết mô phỏng: %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'); THỰC HÀNH Viết chương trình thwujc biến đổi IDFT chuỗi X(k) = [10, -2+2i, -2, -2-2i] theo cách - Code Matlab: - Kết mô phỏng: 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) + (1/L)*xk(k+1)*exp(1j*2*pi*k*n/L); end end % Using IDFT Matlab Xn_2 = ifft(xk,L); stem(0:L-1,Xn,'b-'); hold on; stem(0:L-1,Xn_2,'r* '); THỰC HÀNH 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 - Code Matlab: clc; clear all; xn = [1,3,5,3,6,3]; hn = [1,4,7,2,8]; % tinh tich chap 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 fprintf('yn = '); disp(yn); % dung ham conv yn_2 = conv(xn,hn); fprintf('\n yn_2 ='); disp(yn_2); stem(0:Ly-1,yn,'b-'); hold on; stem(0:Ly-1,yn_2,'r* '); - Kết mô phỏng: THỰC HÀNH Viết file-M vẽ đáp ứng tần số hệ thống có hàm truyền theo cách - Code Matlab: clc; clear all; w = 0:pi/10:pi; % tinh toan dap ung tan so H = (5 + 2*exp(-1j*w))./(1-0.8*exp(-1j*w)); H_manitude = abs(H); H_phase = angle(H); subplot(2,2,1); semilogy(w,H_manitude,'r-'); grid on; title('Amplitude tinh toan'); xlabel('w (pi)'); subplot(2,2,2); plot(w,H_phase,'b-'); grid on; title('Phase tinh toan'); xlabel('w (pi)'); % su dung ham matlab a = [1,-0.8]; b = [5,2]; [H_matlab,w] = freqz(b,a); H_matlab_mantitude = abs(H_matlab); H_matlab_phase = angle(H_matlab); subplot(2,2,3); semilogy(w,H_matlab_mantitude,'r-'); grid on; xlabel('w (pi)'); title('Amplitude ham matlab'); subplot(2,2,4); plot(w,H_matlab_phase,'b-'); grid on; xlabel('w (pi)'); title('Phase ham matlab'); - Kết mô phỏng: THỰC HÀNH 6_1 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 ) f = với 400 Hz, tần số lẫy mẫu 8000 Hz - Code matlab: clc; clear all; % Signal Genergating Fs = 8e3; % Sampling frequency kHz Ts = 1/Fs; % Sampling period F_xt = 400; % Frequency of signal 300 Hz T_xt = 1/F_xt; t = : Ts : 5*T_xt; 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'); 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) / N); xlabel('Frequency (Hz)'); ylabel('Amplitude'); subplot(1,2,2); plot((0:N-1)*Fs/N, Xk_Pha(1:N) ); xlabel('Frequency (Hz)'); ylabel('Phase'); - Kết mô phỏng: 1 T ≤ t < 3T s3 = elsewhere THỰC HÀNH 6_2 Tạo mẫu tín hiệu lấy mẫu với 20 chu kỳ T - Code Matlab: clc; clear all; Fs = 20; Ts = 1/Fs; T = 1; t = : Ts : T-Ts; xn = [0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0]; L = length(xn); Xk = fft(xn,L); Xk_Man = abs(Xk); Xk_Pha = angle(Xk); %% Signal plot figure(1) subplot(1,2,1) plot(t, xn); xlabel('Time (sec)'); ylabel('Amplitude'); subplot(1,2,2) plot(0:L-1,xn); xlabel('Sampling index - n'); ylabel('Amplitude'); %% Spectrum plot figure(2) subplot(1,2,1) stem((0:L-1)*Fs/L, Xk_Man(1:L) / L); xlabel('Frequency (Hz)'); ylabel('Amplitude'); subplot(1,2,2) stem((0:L-1)*Fs/L, Xk_Pha(1:L) ); xlabel('Frequency (Hz)'); ylabel('Phase'); - Kết mô phỏng: THỰC HÀNH 6_3 Tạo tín hiệu sinc s = sinc ( 2π f ( t − 0.5) ) lấy mẫu tần số 500 Hz - Code Matlab: clc; clear all; Fs = 500; Ts = 1/Fs; F = 40; T_sim = 1; t = 0:Ts:1-Ts; xn = sinc(2 * pi * F * (t-0.5)); N = length(xn); Xk = fft(xn, N); Xk_Man = abs(Xk); Xk_Pha = angle(Xk); %% Signal plot figure(1) subplot(2,1,1) plot(t, xn); grid on; xlabel('Time (sec)'); ylabel('Amplitude'); title('Truoc lay mau '); subplot(2,1,2) plot(0:N-1, xn,'r-'); grid on; xlabel('Sampling index - n'); ylabel('Amplitude'); title('Sau lay mau'); %% Spectrum plot figure(2) subplot(2,1,1) stem((0:N-1)*Fs/N, Xk_Man(1:N) / N); xlabel('Frequency (Hz)'); ylabel('Amplitude'); title('Bien do'); subplot(2,1,2) stem((0:N-1)*Fs/N, Xk_Pha(1:N)); xlabel('Frequency (Hz)'); ylabel('Phase'); title('Pha'); với f = 40 Hz, ≤ t < (s) - Kết mô phỏng: THỰC HÀNH 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 - Code Matlab: - Kết mô phỏng: h = bs2700.tf.num; [H_matlab,w] = freqz(h); H_matlab_manitude = abs(H_matlab); H_matlab_phase = angle(H_matlab); subplot(2,1,1); semilogy(w,H_matlab_manitude,'r'); %plot xlabel('w(pi)'); title('do thitheo semilogy'); subplot(2,1,2); plot(w,H_matlab_manitude,'b-'); xlabel('w(pi)'); title('do thi plot'); THỰC HÀNH Thực việc thiết kế lọc IIR 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 - Code Matlab : - Kết mô : [z,p,k] = tf2zp(bs1750.tf.num, bs1750.tf.den); sos = zp2sos(z,p,k); [H_matlab,w] = freqz(sos); H_matlab_mantitude = abs(H_matlab); H_matlab_phase = angle(H_matlab); subplot(2,1,1); semilogy(w,H_matlab_mantitude,'r'); xlabel('w (pi)'); subplot(2,1,2); plot(w,H_matlab_mantitude,'b-'); xlabel('w (pi)'); 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 - Code Matlab: - Kết mô clc; clear all; : 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; 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, 'g'); hold on; plot(w/pi*5000,abs(h), 'r-.'); 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 - Code Matlab: - Kết mô : clc; clear all; 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; [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, 'g'); hold on; plot(w/pi*5000,abs(h), 'r-.'); ... ? ?1 T ≤ t < 3T s3 = elsewhere THỰC HÀNH 6_2 Tạo mẫu tín hiệu lấy mẫu với 20 chu kỳ T - Code Matlab: clc; clear all; Fs = 20; Ts = 1/ Fs; T = 1; t = : Ts : T-Ts; xn = [0,0,0,0,0 ,1, 1 ,1, 1 ,1, 1 ,1, 1 ,1, 1,0,0,0,0,0];... sequence for n = 0:L -1 for k = 0:L -1 Xn(n +1) = Xn(n +1) + (1/ L)*xk(k +1) *exp(1j*2*pi*k*n/L); end end % Using IDFT Matlab Xn_2 = ifft(xk,L); stem(0:L -1, Xn,'b-'); hold on; stem(0:L -1, Xn_2,'r* '); THỰC... = 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 fprintf('yn = '); disp(yn); % dung ham
Ngày đăng: 28/08/2022, 22:37
Xem thêm: