Thực hành Tín hiệu và hệ thống | HQT-FoEEE-PU
Chữa bài tập - Thực hành tuần 3
Ex1: Biểu diễn hàm nhảy bậc dưới dạng liên tục và rời rạc với -5 ≤ t, n ≤5.
%% discrete-time step function, buoc nhay tai vi tri k = 2
n=-5:1:5;
n0=2
du=stepfun(n,n0)
figure()
plot(n,du,'r*','linewidth',2)
title ('discrete-time step function')
xlabel('time n')
ylabel('u[n-2]')
%% Ve tren 1 hinh
figure()
subplot(211)
plot(t,u,'linewidth',2);
axis([-6 6 -0.1 1.1]); % xlim([-6 6]); ylim([-0.1 1.1]);
grid on
subplot(212)
% plot(k,du,'r*','linewidth',2)
stem(k,du,'linewidth',2);
axis([-6 6 -0.1 1.1]);grid on
Ex2: Biểu diễn tín hiệu sau:
x(n) = 2Δ(n + 2) - Δ(n - 4), -5≤ n ≤5
clear;clc;close all;
% x(n)=2d(n+2)-d(n-4), -5<=n<=5
n = [-5:5];
x = 2*impseq(-2,-5,5)-impseq(4,-5,5);
figure()
stem(n,x);
title('Chuoi x(n)=2\delta(n+2)-\delta(n-4)')
xlabel('n'); ylabel('x(n)'); axis([-5,5,-2,3]);
%% y(k)=p4(k+3)+d(k-2), -5<=k<=5
clear;clc;close all;
k=[-10:no-3 no-2:no+2 no+3:10];
p4k=[zeros(1,8+no) ones(1,5) zeros(1,8-no)];
ip1= 3*impseq(2,-10,10);
yk= p4k + 3*impseq(2,-10,10);
figure()
stem(k,yk);
axis([-10 10 -0.1 3.1]); grid on
Thực hành Tín hiệu và hệ thống | HQT-FoEEE-PU
Ex3: Lấy mẫu của tín hiệu x(t) = cos(2πf0t), trong đó f0 = 1000, 0 ≤ t ≤50 sử
dụng các tần số lấy mẫu fs1=10000, fs2=1500. Vẽ tín hiệu rời rạc thu được. Nhận
xét về các tín hiệu rời rạc thu được.
clear;clc;close all;
f0=1000;
%Frequency of sin
fs1=10000; %Sampling Frequency Fs>2F0
fs2=1500;
%Sampling Frequency Fs<2F0
% T0= 1/f0;
% T1= 1/fs1;
% T2= 1/fs2;
n=0:1:50;
x1=cos(2*pi*f0*n/fs1);
x2=cos(2*pi*f0*n/fs2);
%%
figure()
subplot(2,1,1)
plot(n,x1)
subplot(2,1,2)
hold on
plot(n,x1)
% thamsodothi;
stem(n,x1,'r')
plot(n,x2,'-bd')
legend('Original function','Sampling With
Fs>2F0','Sampling With Fs<2F0');
Ex4: Sử dụng Matlab để ghi âm tín hiệu và lưu vào máy tính. Gợi ý, sử dụng các
hàm audiorecorder, recordblocking, getaudiodata, audiowrite.
clear;clc;close all
% Record your voice for 10 seconds.
fs=1000;
recObj = audiorecorder(fs,16,1);
disp('Start speaking.')
recordblocking(recObj, 10);
disp('End of Recording.');
% Play back the recording.
play(recObj);
% Store data in double-precision array.
myRecording = getaudiodata(recObj);
% Plot the waveform.
plot(myRecording)