⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 数字信号处理实验matlab程序(一).txt

📁 数字信号处理课程,1.信号采样及编程环境;2.信号、系统及频响,用于学生上机练习。
💻 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 + -