Professional Documents
Culture Documents
Hà Nội, 2023
`1
Bài 1. Tín hiệu liên tục
I. Hàm bước nhảy đơn vị (unit step) và hàm dốc đơn vị (ramp)
Bài 1:
% y=ustep(t)
function
y=ustep(t,a);
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>=-a
y(i)=1;
end
end
Bài 2:
% y=uramp(t)
function y=uramp(t,b)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>=-b
y(i)=t(i)+b
end
end
`2
`3
Bài 3:
+ 5u(t+2)
>> t=[-10:0.01:10];
>> x1=5*ustep(t,-2);
>> plot(t,x1);
>> xlabel('x');
>> ylabel('y');
+ 3r(t+5)
>> t=[-10:0.01:10];
>> x2=3*uramp(t,5);
>> plot (t,x2);
>> xlabel('x');
>> ylabel('y');
`4
+y(t)=2r(t+2.5)-5r(t)+3r(t-2)+u(t-4)
>> t=[-10:0.01:10];
>> y=2*uramp(t,2.5)-5*uramp(t,0)+3*uramp(t,-2)+ustep(t,-4);
>> plot (t,y);
>> xlabel('x');
>> ylabel('y');
`5
+y(t)=sin(t)*[u(t+3)-u(t-3)]
>> t=[-10:0.01:10];
>> y=sin(t).*[ustep(t,3)-ustep(t,-3)];
>> plot (t,y);
>> xlabel('x');
>> ylabel('y');
`6
Bài 4:
+)
>> t=[-10:0.01:10];
>> y=1/2*uramp(t,4)+1/2*uramp(t,-4)-uramp(t,0);
>> plot(t,y);
>> xlabel('x');
>> ylabel('y');
`7
+)
>> t=[-10:0.01:10];
>> y=1/2*uramp(t,4)+1/2*uramp(t,-4)-uramp(t,0)+ustep(t,8)-ustep(t,-8);
>> plot(t,y);
>> xlabel('x');
>> ylabel('y');
`8
II.Tín hiệu chẵn, lẻ
Bài 1:
function [ye,yo] =
evenodd(y) yr = fliplr(y);
ye = 0.5*(y + yr);
yo = 0.5*(y - yr);
end
Bài 2:
>> t=[-10:0.01:10];
>> y=2*uramp(t,2.5)-5*uramp(t,0)+3*uramp(t,-2)+ustep(t,-4);
>> evenodd(y);
>> yr=fliplr(y);
>> ye=0.5*(y+yr);
>> yo=0.5*(y-yr);
>> plot(t,ye,'r-.','linewidth',1);
>> hold on;
>> plot(t,yo,'g--','linewidth',1);
>> xlabel('t');
>> ylabel('y');
>> plot(t,y,'k','linewidth',1);
`9
>> legend('yo','ye','y');
>> grid on;
`11
IV.Năng lượng, công suất của 1 tín hiệu
>> syms t;
>> T=20;
>> u(t)=heaviside(t);
>> x(t)=exp(-t)*cos(2*pi*t)*u(t);
>> f=(abs(x(t))).^2;
>> E=int(f,t,-T/2,T/2)
E =(exp(-20)*(2*pi^2 + 1)*(exp(20) - 1))/(2*(4*pi^2 + 1))
>> P=int(f,t,-T/2,T/2)/T
P =(exp(-20)*(2*pi^2 + 1)*(exp(20) - 1))/(40*(4*pi^2 + 1))
`12
Bài 2:
>> t=-10:0.01:10;
>> x=exp(-(abs(t)));
>> x1=exp(-(abs(t.*2)));
>> x2=exp(-(abs(t./2)));
>> plot(t,x,'k','linewidth',2);
>> hold on;
>> plot(t,x1,'r','linewidth',2);
>> plot(t,x2,'g','linewidth',2);
>> legend ('x(t)','x(2t)','x(0.5t)');
>> title('x(t)=exp(-|t|)');
`13
Bài 3:
>> t=-10:0.01:10;
>> x=exp(-(abs(t)));
>> x1=exp(-(abs(-t)));
>> plot(t,x,'k','linewidth',2);
>> hold on;
>> plot(t,x1,'g--','linewidth',2);
>> legend ('x(t)','x(-t)');
>> title('x(t)=exp(-|t|)');
-8 0
`14
Bài 2. Hàm tuyến tính
`15
A2s=A2*s;
B2=A2s*s;
C2=B2*s;
C2s=C2*s;
D2=C2s*s;
D2s=D2*s;
E2=D2s*s;
F2=E2*s;
F2s=F2*s;
G2=F2s*s;
G2s=G2*s;
Fs=8000;
t=0:1/Fs:0.6;
t2=0:1/Fs:1.2;
N=300;
A=2;
nC=A*exp(-0.5*t).*cos(2*pi*C*t);
nC2=A*exp(-0.5*t2).*cos(2*pi*C*t2);
nG=A*exp(-0.5*t).*cos(2*pi*G*t);
nG2=A*exp(-0.5*t2).*cos(2*pi*G*t2);
nA=A*exp(-0.5*t).*cos(2*pi*A2*t);
nF=A*exp(-0.5*t).*cos(2*pi*F*t);
nE=A*exp(-0.5*t).*cos(2*pi*E*t);
nD=A*exp(-0.5*t).*cos(2*pi*D*t);
nD2=A*exp(-0.5*t2).*cos(2*pi*D*t2);
x=[nC, nC, nG, nG, nA, nA, nG2, ...
nF, nF, nE , nE, nD, nD, nC2];
sound(x,Fs);
Bài 2: Tiến kèn Trumpet.
a. Xây dựng note B của kèn Trumpet với số liệu cho trước.
clc
clear all
Fs = 44100;
t = linspace(0,1,Fs);
B = 494;
F = [B 2*B 3*B 4*B 5*B 6*B 7*B 8*B 9*B];
C = [0.1155 0.3417 0.1789 0.1232 0.0678 0.0473 0.026 0.0045 0.002];
`16
Bài 2: Tiến kèn Trumpet.
b.Xây dựng note B của kèn Trumpet với số liệu cho trước.
clc
clear all
Fs = 44100;
t = linspace(0,1,Fs);
B = 494;
F = [B 2*B 3*B 4*B 5*B 6*B 7*B 8*B 9*B];
C = [0.1155 0.3417 0.1789 0.1232 0.0678 0.0473 0.026 0.0045 0.002];
Th = [-2.1299 1.6727 -2.5454 0.6607 -2.0390 2.1597 -1.0467 1.8581 -
2.3925];
x = C*cos(2*pi*F'*t - Th'*ones(1,Fs));
sound(x,Fs);
c. Vẽ đồ thị của x(t) trong vòng 3 chu kì đầu
Do tần số của B là 494HZ và được được lưu 44100 samples mỗi giây nên
44100 / 494 là số samples của 1 chu kì.
>> plot(t(1:268),x(1:268));
>>grid on
`17
d. Lặp lại a và b với góc pha = 0.
clc
clear all
Fs = 44100;
t = linspace(0,1,Fs);
B = 494;
F = [B 2*B 3*B 4*B 5*B 6*B 7*B 8*B 9*B];
C = [0.1155 0.3417 0.1789 0.1232 0.0678 0.0473 0.026 0.0045 0.002];
x = C*cos(2*pi*F'*t);
sound(x,Fs);
>> plot(t(1:268),x(1:268));
>> axis tight
>> grid on
>> title("Tiếng kèn trumpet với góc theta=0")
>> xlabel t
>> ylabel x(t)
`18
Nhận xét:
Pha dao động có sự thay đổi lệch hoàn toàn so tín hiệu gốc do dịch pha
ban đầu.
Biên độ có sự thay đổi nhỏ, tần số không bị ảnh hưởng.
Âm thanh vẫn tương tự như âm gốc.
`19
Bài 3. Tích chập, phép biến đổi Fourier và lọc tín hiệu
I. Tích chập và lọc tín hiệu âm thanh bằng bộ lọc thông thấp lý tưởng.
% doc file
[data, Fs]=audioread('female_voice.wav');
data = data(:, 1)';
% Fs: tan so trich mau; Ts: Thoi gian trich
mau Ts = 1/Fs;
`20
function [f,X]=FourierTransform(t,x)
% computes the Fourier transform of signal x(t)
% ns: length(x)=number signal points
% dt: signal point spacing
%
% Transform computed with N points, where
N=2*ns ns=size(x,2); dt=t(2)-t(1);
N=2*ns; df=1/(N*dt);
xp=zeros(1,N); nns=sum(t<0);
xp(1:ns-nns)=x(nns+1:ns); xp(N-nns+1:N)=x(1:nns);
Xf=dt*fft(xp); n2=ceil(N/2);
if n2==N/2; X(1:n2-1)=Xf(n2+2:N); X(n2:N)=Xf(1:n2+1);
f=(-n2+1)*df:df:n2*df; no=n2;
else; X(1:n2-1)=Xf(n2+1:N); X(n2:N)=Xf(1:n2);
f=(-n2+1)*df:df:(n2-1)*df; end;
`21
% doc file
[data, Fs]=audioread('female_voice.wav');
data = data(:, 1)';
% Fs: tan so trich mau; Ts: Thoi gian trich
mau Ts = 1/Fs;
`22
Hình 1
=> Nhận xét:
Từ độ thị ta thấy hầu hết năng lượng phân bổ ở vùng có tần số thấp.
Phần có tần số cao được coi là nhiễu và cần loại bỏ
h=(568*exp(-300*t)-485*exp(-243*t).*cos(176*t)...
+668*exp(-243*t).*sin(176*t)-83*exp(-93*t).*cos(285*t)...
-255*exp(-
93*t).*sin(285*t));
[f,Hf]=FourierTransform(t,h)
; figure(2)
subplot(2,2,[1 2])
plot(t,h,'linewidth',1)
; grid;
axis([0 0.5 -50 150]);
title("Bo loc tin hieu dien tim");
xlabel('t (sec)'); ylabel('h(t)');
subplot(2,2,3)
plot(f,abs(Hf),'k','linewidth',1);
grid; axis([-150 150 0 1.2]);
xlabel('f (Hz)'); ylabel('|H(j2\pi
f)|'); subplot(2,2,4)
angleH=unwrap(angle(Hf))+2*pi;
`23
plot(f,angleH,'k','linewidth',1);
grid; axis([-150 150 -10 10]);
xlabel('f (Hz)'); ylabel('\angle H(f)');
Hình 2
=> Nhận xét:
Yf=Xf.*Hf;
figure(3)
subplot(2,1,1)
plot(f,abs(Yf),'r','linewidth',1);
grid; `24
axis([-150 150 0 0.12]);
title("Tin hieu dien tim sau xư
ly"); xlabel('f (Hz)'); ylabel('|
[t2,y]=IFourierTransform(f,Yf);
subplot(2,1,2)
plot(t2,y,'r','linewidth',1);
grid;
axis([0 2.5 -0.5 1.5]);
xlabel('t (sec)'); ylabel('y(t)');
Hình 3
=> Nhận xét:
Sau khi qua bộ lọc, hầu hết nhiễu với tần số cao đều đã được khử đi.
Đồ thị tín hiệu theo thời gian trông rõ ràng hơn so hình 1.
`25