?? 數字信號處理實驗matlab程序(一).txt
字號:
%實驗一上機內容(1)
a=[1 2 3 4 ];
b=[3 4 5 6];
c=a+b;
d=a-b;
e=a.*b;
f=a./b;
g=a.^b;
n=[0:3];
figure(1);clf
subplot(2,2,1);stem(n,a);title('a=[1 2 3 4 ]');
subplot(2,2,2);stem(n,b);title('b=[3 4 5 6]');
subplot(2,2,3);stem(n,c);title('a+b');
subplot(2,2,4);stem(n,d);title('a-b');
figure(2);clf
subplot(2,2,1);stem(n,e);title('a.*b');
subplot(2,2,2);stem(n,f);title('a./b');
subplot(2,2,3);stem(n,g);title('a.^b');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%實驗一上機內容(2.1)
n=[-5:10];
x=[n==0];
stem(n,x);title('單位采樣序列δ(n)');
%實驗一上機內容(2.2)
n=[0:15];
x=3*cos(0.125*pi*n+0.2*pi)+2*sin(0.25*pi*n+0.1*pi);
stem(n,x);title('x=3*cos(0.125*pi*n+0.2*pi)+2*sin(0.25*pi*n+0.1*pi)');
%實驗一上機內容(2.3)
n=[0:15];
x=3*cos(0.125*pi*n+0.2*pi)+2*sin(0.25*pi*n+0.1*pi);
N=16;
nxtide=0:4*16-1;
xtide=x(mod(nxtide,N)+1);
subplot(2,1,1);stem(n,x);axis([0 64 -6 4]);%可在figure中對坐標進行修飾。
title('x=3*cos(0.125*pi*n+0.2*pi)+2*sin(0.25*pi*n+0.1*pi)');
subplot(2,1,2);stem(nxtide,xtide);axis([0 64 -6 4]);
title('以16為周期進行延拓形成的周期序列');
%實驗一上機內容(2.4)
n=[0:15];
x=3*cos(0.125*pi*n+0.2*pi)+2*sin(0.25*pi*n+0.1*pi);
%將序列移位10位置后,進行累加,在每個周期的開始部分有混淆。
N=10;
xk=x;
for k=1:3;
xi=0;
for i=k
xi=[zeros(1,N*i) x];
xp=[xk zeros(1,N)];
end
xtide=xp+xi;
xp=xtide;
xk=xp;
ntide=[0:15+k*N];
end
subplot(2,1,1);stem(n,x);axis([0 45 -6 4]);%可在figure中對坐標進行修飾。
title('x=3*cos(0.125*pi*n+0.2*pi)+2*sin(0.25*pi*n+0.1*pi)');
subplot(2,1,2);stem(ntide,xtide);title('以10為周期進行延拓形成的周期序列');
%取前10個數據進行復制
%N=10;
%nxtide=0:4*10-1;
%xtide=x(mod(nxtide,N)+1);
%clf;
%subplot(2,1,1);stem(n,x);axis([0 40 -6 4]);%可在figure中對坐標進行修飾。
%title('x=3*cos(0.125*pi*n+0.2*pi)+2*sin(0.25*pi*n+0.1*pi)');
%subplot(2,1,2);stem(nxtide,xtide);title('以10為周期進行延拓形成的周期序列');
%實驗一上機內容(2.5)
n=[0:15];
x=(0.8).^n;
stem(n,x);title('x(n)=(0.8).^n');
%實驗一上機內容(2.5、6)
n=[0:15];
x=(0.8).^n;
subplot(4,1,1);stem(n,x);axis([-5 20 0 1]);title('x(n)=(0.8).^n');
n0=-fliplr(n); %使用MATLAB的函數實現翻轉。n=[0 1 2 3 4]becomes[-4 -3 -2 -1 0]
x0=fliplr(x);
subplot(4,1,2);stem(n0,x0);axis([-15 10 0 1]);title('x(-n)');
n1=n-4;x1=x;
subplot(4,1,3);stem(n1,x1);axis([-5 20 0 1]);title('x(n+4)左移');
n2=n+5;x2=x;
subplot(4,1,4);stem(n2,x2);axis([-5 20 0 1]);title('x(n-5)右移');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%實驗一上機內容(3)
function[x,n]=stepshift(n0,n1,n2)
%實現u(n-n0);n1<n0<n2
%--------------------
%n0為序列位置,n1為起點,n2為終點
%調用方式[x,n]=stepshift(n0,n1,n2)
%
if n1>n0|n0>n2|n1>n2
error('輸入位置參數不滿足n1<n0<n2')
else n=[n1:n2];
x=[(n-n0)>=0];
stem(n,x);
end
%將上述函數程序建立.m文件,以n1=2,n2=15,n0=5為例調用該函數。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%實驗一上機內容(4)
%Analog signal
dt=0.001;t=0:dt:0.6;xa=sin(20*pi*t); %信號頻率為fa=10HZ,周期為0.1秒
subplot(3,1,1);plot(t,xa);xlabel('單位:s');axis([0 0.6 -1 1]);
%Discrete-time Signal
Ts=0.0625;n=0:1:10;x=sin(20*pi*(n*Ts)); %fs=16Hz,Ts=Ta*fa/fs=0.1/1.6
subplot(3,1,2);stem(n,x);xlabel('以16Hz采樣獲得的序列x1(n)');axis([0 9.6 -1 1]);
Ts1=0.025;n1=0:1:24;x1=sin(20*pi*(n1*Ts1)); %fs=40Hz,Ts=0.1/4
subplot(3,1,3);stem(n1,x1);axis([0 24 -1 1]);xlabel('以40Hz采樣獲得的序列x2(n)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%實驗一上機內容(5)
%Discrete-time Signal x2(n)
Ts=0.025;n=0:1:24;x=sin(20*pi*(n*Ts)); Fs=1/Ts; nTs=n*Ts; %fs=40Hz,Ts=0.1/4
subplot(3,1,1);stem(n,x);axis([0 24 -1 1]);xlabel('以40Hz采樣獲得的序列x2(n)')
%Analog Signal reconstruction
dt=0.001;t=0:dt:0.6;
xa=x*sinc(Fs*(ones(length(n),1)*t-nTs'*ones(1,length(t))));
subplot(3,1,2);plot(t,xa);axis([0 0.6 -1 1]);xlabel('由采樣序列x2(n)恢復結果')
%Old Analog Signal
dt=0.001;t=0:dt:0.6;xa1=sin(20*pi*t); %信號頻率為fa=10HZ,周期為0.1秒
subplot(3,1,3);plot(t,xa1);xlabel('采樣前的連續時間模擬信號xa(t)');axis([0 0.6 -1 1]);
%
%
%Discrete-time Signal x1(n)
Ts=0.0625;n=0:1:10;x=sin(20*pi*(n*Ts)); Fs=1/Ts; nTs=n*Ts; %fs=16Hz,Ts=Ta*fa/fs=0.1/1.6
subplot(3,1,1);stem(n,x);xlabel('以16Hz采樣獲得的序列x1(n)');axis([0 9.6 -1 1]);
%Analog Signal reconstruction
dt=0.001;t=0:dt:0.6;
xa=x*sinc(Fs*(ones(length(n),1)*t-nTs'*ones(1,length(t))));
subplot(3,1,2);plot(t,xa);axis([0 0.6 -1 1]);xlabel('由采樣序列x1(n)恢復結果')
%Old Analog Signal
dt=0.001;t=0:dt:0.6;xa1=sin(20*pi*t); %信號頻率為fa=10HZ,周期為0.1秒
subplot(3,1,3);plot(t,xa1);xlabel('采樣前的連續時間模擬信號xa(t)');axis([0 0.6 -1 1]);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -