1. 程式人生 > 實用技巧 >時域離散訊號與系統的變換域分析

時域離散訊號與系統的變換域分析

時域離散訊號與系統的變換域分析

Contents

1.序列的基本運算

(1)產生餘弦訊號x(n)=cos(0.04*pi*n)及帶噪訊號y(n)=x(n)+a*w(n),0<=n<=N-1。(噪聲採用randn函式,a及N自定。)

clear;
N=80;
n=0:N-1;
xn=cos(0.04*pi*n);
wn=randn(1,N);
a=0.2;
yn=xn+a*wn;
subplot(2,1,1);
stem(xn,'.r');
axis([0,80,-2,2]);
title('CosineSignal')
subplot(2,1,2);
stem(yn,'.r');
axis([0,80,-2,2]);
title('NoisySignal')

(2)已知x1(n)=2n-1,1<=n<=5,x2(n)=2n-2(2<=n<=6),求兩個序列的和、乘積、序列x1的移位序列(移位方向及位數自定),序列x2的翻轉序列,畫出原序列及運算結果圖。

clear;
n1=1:5;
x1n=2*n1-1;
subplot(3,2,1);
stem(n1,x1n,'.r');
axis([0,8,0,20]);
title('x1(n)');
n2=2:6;
x2n=2*n2-2;
subplot(3,2,2);
stem(n2,x2n,'.r');
axis([0,8,0,20]);
title('x2(n)');
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1n=zeros(1,length(n));
y2n=zeros(1,length(n));
y1n((n>=min(n1))&(n<=max(n1)))=x1n;
y2n((n>=min(n2))&(n<=max(n2)))=x2n;
ynadd=y1n+y2n;
subplot(3,2,3);
stem(ynadd,'.r');
axis([0,8,0,20]);
title('x1(n)+x2(n)');
ynmult=y1n.*y2n;
subplot(3,2,4);
stem(ynmult,'.r');
axis([0,8,0,80]);
title('x1(n)*x2(n)');
n0=2;
n1shift=n1+n0;
x1nshift=x1n;
subplot(3,2,5);
stem(n1shift,x1nshift,'.r');
axis([0,8,0,20]);
title('x1(n)shift');
n2shift=-fliplr(n2);
x2nshift=fliplr(x2n);
subplot(3,2,6);
stem(n2shift,x2nshift,'.r');
axis([-8,0,0,20]);
title('x2(n)shift');

2.序列的傅立葉變換

(1)已知序列x(n)=0.5^n*u(n)。試求它的傅立葉變換,並且畫出其幅度、相角、實部和虛部的波形,並分析其含有的頻率分量主要位於高頻區還是低頻區。

clear;
w=(0:500)*pi/500;
X=exp(1i*w)./(exp(1i*w)-0.5*ones(1,501));
magX=abs(X);
angX=angle(X);
realX=real(X);
imagX=imag(X);
subplot(2,2,1);
plot(w/pi,magX);
title('MagnitudePart');
xlabel('frequencyinpiunits');
ylabel('Magnitude');
subplot(2,2,2);
plot(w/pi,angX);
title('AnglePart');
xlabel('frequencyinpiunits');
ylabel('Radians');
subplot(2,2,3);
plot(w/pi,realX);
title('RealPart');
xlabel('frequencyinpiunits');
ylabel('Real');
subplot(2,2,4);
plot(w/pi,imagX);
title('ImaginaryPart');
xlabel('frequencyinpiunits');
ylabel('Imaginary');

(2)令模擬訊號xa(t)=e^(-1000|t|),求其傅立葉變換Xa(jOmega),畫出其幅度頻譜。然後分別用fs=1kHz和fs=5kHz對其進行取樣並離散化,求出離散時間訊號的傅立葉變換X(e^jw),畫出相應的幅度頻譜,總結以上3個訊號幅度頻譜的聯絡與差異,並分析其原因。

%模擬對稱指數訊號及其頻譜
clear;
syms f t;
xa=exp(-1000*abs(t));
Xa=2000/((2*pi*f)^2+1000^2);%模擬訊號(對稱指數訊號)的傅立葉變換,請參見訊號與系統課程相關內容
subplot(3,2,1);
fplot(xa,[-0.01,0.01]);
axis([-0.01,0.01,0,1])
xlabel('time(s)');
ylabel('xa(n)');
title('Analogsignal');
subplot(3,2,2);
fplot(abs(Xa),[-2500,2500])
xlabel('frequency(Hz)')
ylabel('|Xa(jw)|');
title('模擬訊號幅度頻譜');
%下面為取樣頻率1kHz時的程式
T=0.001;%取樣間隔
n=-10:10;
x=exp(-1000*abs(n*T));%離散時間訊號
K=500;
k=0:K;
w=pi*k/K;%w為數字頻率
X=x*exp(-1i*n'*w);%計算離散時間傅立葉變換(序列的傅立葉變換)
X=real(X);
w=[-fliplr(w),w(2:K+1)];
X=[fliplr(X),X(2:K+1)];
subplot(3,2,3);
stem(n*T,x,'.r');%畫出取樣訊號(離散時間訊號)
xlabel('time(s)');
ylabel('x1(n)');
title('discretesignal');
subplot(3,2,4);
plot(w/pi,X);%畫出離散時間傅立葉變換
xlabel('frequency(radian/pi)');%橫座標為弧度
ylabel('x1(jw)');
title('DTFT');
%下面為取樣頻率5kHz時的程式
T=0.0002;%取樣間隔
n=-50:50;
x=exp(-1000*abs(n*T));%離散時間訊號
K=500;
k=0:K;
w=pi*k/K;%w為數字頻率
X=x*exp(-1i*n'*w);%計算離散時間傅立葉變換(序列的傅立葉變換)
X=real(X);
w=[-fliplr(w),w(2:K+1)];
X=[fliplr(X),X(2:K+1)];
subplot(3,2,5);
stem(n*T,x,'.r');%畫出取樣訊號(離散時間訊號)
xlabel('time(s)');
ylabel('x2(n)');
title('discretesignal');
subplot(3,2,6);
plot(w/pi,X);%畫出離散時間傅立葉變換
xlabel('frequency(radian/pi)');%橫座標為弧度
ylabel('x2(jw)');
title('DTFT');

3.序列的傅立葉變換性質分析

(1)已知序列x(n)=(0.9*e^(j*pi/3))^n,0<=n<=10,求其傅立葉變換,並討論其傅立葉變換的週期性和對稱性。

clear;
n=0:10;
x=(0.9*exp(1i*pi/3)).^n;
k=-4000:4000;
w=(pi/abs(max(k)/2))*k;
X=x*exp(-1i*n'*w);
magX=abs(X);
angX=angle(X);
subplot(2,1,1);
plot(w/pi,magX);
grid on;
xlabel('frequencyinpiunits');
ylabel('/X/');
title('MagnitudePart');
subplot(2,1,2);
plot(w/pi,angX/pi);
grid on;
xlabel('frequencyinpiunits');
ylabel('Radians/pi');
title('AnglePart');

(2)編寫程式驗證序列傅立葉變換頻移性質。

clear;
n=0:10;
x=(0.9*exp(1i*pi/3)).^n;
k=-4000:4000;
w=(pi/abs(max(k)/2))*k;
X=x*exp(-1i*n'*w);
magX=abs(X);
angX=angle(X);
subplot(2,2,1);
plot(w/pi,magX);
grid on;
xlabel('frequencyinpiunits');
ylabel('/X/');
title('MagnitudePart');
subplot(2,2,2);
plot(w/pi,angX/pi);
grid on;
xlabel('frequencyinpiunits');
ylabel('Radians/pi');
title('AnglePart');
w0=pi;
x=(0.9*exp(1i*pi/3)).^n;
k=-4000:4000;
w=(pi/abs(max(k)/2))*k;
X=x.*exp(1i*w0*n)*exp(-1i*n'*w);
magX=abs(X);
angX=angle(X);
subplot(2,2,3);
plot(w/pi,magX);
grid on;
xlabel('frequencyinpiunits');
ylabel('/X/');
title('MagnitudePart');
subplot(2,2,4);
plot(w/pi,angX/pi);
grid on;
xlabel('frequencyinpiunits');
ylabel('Radians/pi');
title('AnglePart');

4.時域差分方程的求解

(1)求解差分方程y(n)+a1y(n-1)+a2y(n-2)=b0x(n)+b1x(n-1)的零狀態響應和全響應。已知x(n)為單位取樣序列,y(-1)=1,y(-2)=2,a1=0.5,a2=0.06,b0=2,b1=3。

xn=[1,zeros(1,20)];
B=[2,3];
A=[1,0.5,0.06];
ys=[1,2];
xi=filtic(B,A,ys);
yn1=filter(B,A,xn);
yn2=filter(B,A,xn,xi);
subplot(2,1,1);
n1=0:length(yn1)-1;
stem(n1,yn1,'.');
axis([0,21,-3,3]);
subplot(2,1,2);
n2=0:length(yn2)-1;
stem(n2,yn2,'.');

5.離散系統的Z域分析

(1)利用系統函式H(z)分析系統的穩定性。假設系統函式如下式:H(z)=(z+9)(z-3)/(3*z^4-3.98*z^3+1.17*z^2+2.3418*z-1.5147),試判斷系統是否穩定。

%呼叫roots函式求極點,並判斷系統的穩定性
A=[3,-3.98,1.17,2.3418,-1.5147];
%H(z)的分母多項式係數
p=roots(A);%求H(z)的極點
pm=abs(p);%求H(z)的極點的模
if max(pm)<1
    disp('系統因果穩定');
else
    disp('系統不因果穩定')
end
系統因果穩定