信息与通信Matlab程序文本说明.docx

上传人:b****6 文档编号:6045452 上传时间:2023-01-03 格式:DOCX 页数:126 大小:3.79MB
下载 相关 举报
信息与通信Matlab程序文本说明.docx_第1页
第1页 / 共126页
信息与通信Matlab程序文本说明.docx_第2页
第2页 / 共126页
信息与通信Matlab程序文本说明.docx_第3页
第3页 / 共126页
信息与通信Matlab程序文本说明.docx_第4页
第4页 / 共126页
信息与通信Matlab程序文本说明.docx_第5页
第5页 / 共126页
点击查看更多>>
下载资源
资源描述

信息与通信Matlab程序文本说明.docx

《信息与通信Matlab程序文本说明.docx》由会员分享,可在线阅读,更多相关《信息与通信Matlab程序文本说明.docx(126页珍藏版)》请在冰豆网上搜索。

信息与通信Matlab程序文本说明.docx

信息与通信Matlab程序文本说明

Matlab程序文本

第一章离散时间信号与系统

本程序产生均匀分布的白噪声信号

set(gcf,'color','w');

p=0.1;N=500000;

u=rand(1,N);%用函数rand产生500000个随机数组

u_mean1=mean(u(1:

length(u)))

power_u=var(u)

subplot(211);

plot(u(1:

100));grid;%显示前100个随机数

xlabel('n','fontSize',12);ylabel('u(n)','fontSize',12);

title('

(1)前100个随机数');

subplot(212)

hist(u,50);grid;%画出随机数分布的直方图

xlabel('n','fontSize',12);ylabel('u(n)','fontSize',12);

title('

(2)随机数分布的直方图');

%u_mean=0.4997;power_u=0.0832%程序运行结果

本程序产生零均值、方差为0.1且服从高斯分布的噪声信号

set(gcf,'color','w')

p=0.1;N=500000;

u=randn(1,N);a=sqrt(p);%计算a值

u=u*a;power_u=var(u);%把randn得到的噪声序列乘以a值。

subplot(221);

plot(u(1:

100));grid

xlabel('n','fontSize',12);ylabel('u(n)','fontSize',12);

title('

(1)白噪声序列');

subplot(222)

hist(u,50);grid%画出直方图

xlabel('n','fontSize',12);ylabel('u(n)','fontSize',12);

title('

(2)白噪声序列的高斯分布');

%power_u=0.0997mean_u=-8.9297e-004

演示序列平移

set(gcf,'color','w')

x=[1,2,3,4,5,4,3,2,1];

m=0:

8

subplot(221)

H=stem(m,x);set(H,'markersize',2);grid

xlabel('n','FontSize',12);ylabel('x(n)','FontSize',12);title('

(1)原序列');

axis([0,15,0,6]);

n0=4

n=m+n0;y=x

subplot(222)

H=stem(n,y);set(H,'markersize',2);grid

xlabel('n','FontSize',12);ylabel('x(n+no)','FontSize',12);title('

(2)平移序列');

axis([0,15,0,6])

演示函数conv在线性卷积中的用法

set(gcf,'color','w');

h=[4*ones(1,4),zeros(1,4)];nh=0:

7;

x=[1,4,3,1,zeros(1,5)];nx=-1:

7;

y=conv(x,h);

n=-1:

14;

subplot(311);H=stem(nh,h);set(H,'markersize',6);grid;

xlabel('n','FontSize',12);ylabel('h(n)','FontSize',12);title('

(1)序列1');

subplot(312);H=stem(nx,x);set(H,'markersize',6);grid;

xlabel('n','FontSize',12);ylabel('x(n)','FontSize',12);title('

(2)序列2');

subplot(313);H=stem(n,y);set(H,'markersize',6);grid;

xlabel('n','FontSize',12);ylabel('y(n)','FontSize',12);title('(3)卷积所得的序列');

y

%y=420323632164000000000

用Toeplitz矩阵计算线性卷积

set(gcf,'color','w');

x=[1,2,3]

h=[3,4,5,6,7]%给定x和h向量

Nx=length(x);Nh=length(h);L=Nx+Nh-1;%求向量长度

%生成toeplitz矩阵H

%TOEPLITZ(C,R)isanon-symmetricToeplitzmatrixhavingCasitsfirstcolumnandRasitsfirstrow.

H=toeplitz([h

(1),zeros(1,Nx-1)],[h,zeros(1,Nx-1)])

y=x*H%用向量x左乘toeplitz矩阵,求出卷积

subplot(2,2,1)

Hd=stem(0:

L-1,y);set(Hd,'markersize',5);grid

xlabel('n','FontSize',12);ylabel('y(n)','FontSize',12);title('卷积所得的序列');

演示用函数filter和impz求解差分方程

set(gcf,'color','w');

b=1.5;a=[1,-0.5];

x=[1,zeros(1,20)];

y1=filter(b,a,x)

subplot(221)

H=stem(0:

length(y1)-1,y1);axis([-1,20,0,2]);grid;

xlabel('n','FontSize',12);ylabel('y(n)','FontSize',12);

title('

(1)用函数filter求得的输出序列');;

set(H,'markersize',3);

length(y1)

subplot(222)

y2=impz(b,a,20);

length(y2)

H=stem(0:

length(y2)-1,y2);axis([-1,20,0,2]);grid;

xlabel('n','FontSize',12);ylabel('y(n)','FontSize',12);

title('

(2)用函数impz求得的输出序列');

set(H,'markersize',3);

用FIR和IIR系统分别实现五点滤波算法

set(gcf,'color','w')

%产生高斯分布的噪声序列

p=0.01;N=1000;%使噪声的方差为p=0.01

u=randn(1,N);a=sqrt(p);

m=mean(u)

u=u*a;sigma=var(u)

%显示噪化序列(信号平均值为零)

subplot(221)

plot(u(1:

N),'k');grid;xlabel('n','FontSize',12);ylabel('sn(k)','FontSize',12);

title('

(1)噪化序列','FontSize',8)

%五点平均算法---使用FIR非因果系统

subplot(222)

fork=4:

N-3

v(k)=0.2*(u(k-2)+u(k-1)+u(k)+u(k+1)+u(k+2));

end

sigma_FIR1=var(v)

plot(1:

N-3,v,'k');grid,xlabel('n','FontSize',12);ylabel('snFIR(n)','FontSize',12);

title('

(2)五点平均算法(FIR非因果系统)','FontSize',8)

%五点平均算法---使用FIR因果系统

subplot(223)

fork=5:

N-3

v(k)=0.2*(u(k-4)+u(k-3)+u(k-2)+u(k-1)+u(k));

end

sigma_FIR2=var(v)

plot(1:

N-3,v,'k');grid,xlabel('n','FontSize',12);ylabel('snFIR(n)','FontSize',12);

title('(3)五点平均算法(FIR因果系统)','FontSize',8)

%五点平均算法---使用IIR系统

subplot(224);

v(3)=0;

fork=4:

N-3

v(k)=0.8*v(k-1)+0.2*u(k);

end

sigma_IIR=var(v)

plot(1:

N-3,v,'k');grid;xlabel('n','FontSize',12);ylabel('snIIR(n)','FontSize',12);

title('(4)五点平均算法(IIR系统)','FontSize',8);

%程序运行后在Matlab命令窗看到的实测数据

%m=

%-0.0431%信号的实测平均值

%sigma=

%0.0089%信号的实测方差值

%sigma_FIR1=

%0.0018%方差

(五点平均算法---使用FIR因果系统)

%sigma_FIR2=

%0.0018%方差

(五点平均算法---使用FIR非因果系统)

%sigma_IIR=

%0.0010%方差

(五点平均算法---使用IIR系统)

下面计算不同算法的系统输出噪声的方差。

(1)五点平均算法---使用FIR菲因果系统

系统的输出、输入噪声序列分别是

可写为

(1)

式中的

都是随机变量。

由式

(1)得

(3)

其中,代表平均运算。

将式(3)展开后,由于假定不同随机变量不相关,故有

(4)

式中右边的5项是相应随机变量的方差。

但假设随机过程是平稳的,故这5项是相等的,即

(5)

是输出噪声

的方差,而

是输入噪声

的方差。

由此可见,采用这种系统时,输出噪声方差

(6)

(2)五点平均算法---使用FIR因果系统

(7)

同样可以证明,采用这种系统时,输出噪声方差

(8)

可见,采用五点平均算法时,不管系统是FIR因果系统或FIR非因果系统,输出噪声方差是相同的。

(3)五点平均算法---使用IIR系统

(9)

(10)

因此,采用这种系统时,输出噪声方差

(11)

以上分析结果与实测结果是吻合的。

观察离散时间信号的相关性

set(gcf,'color','w')

p=0.1;N=5000;%产生点数为5000的白噪声序列。

其均值为零,功率为0.1且服从高斯分布。

u=randn(1,N);a=sqrt(p);

u=u*a;power_u=var(u);

subplot(221);%观察序号区间[1:

100]的噪声序列。

u1=u(1:

500);

plot(u1);grid

xlabel('n','FontSize',12);ylabel('u(n)','FontSize',12);title('

(1)白噪声序列');

N=500

u1=u(1:

N);

fori=1:

N%求自相关函数(令位移为0~49)

u2=u(1+i-1:

500+i-1);

a(i)=u1*u2';

end

subplot(222);%画出自相关函数

k=1:

N;

plot(k,a);holdon;grid

axis([-50,N,-10,60])

xlabel('n','FontSize',12);ylabel('a(n)','FontSize',12);title('

(2)自相关序列');

求序列的自相关函数可以检测出序列是否含有周期成分

set(gcf,'color','w')

p=0.1;N=5000;%产生点数为5000的白噪声序列。

其均值为零,功率为0.1且服从高斯分布。

u=randn(1,N);a=sqrt(p);

u=u*a;power_u=var(u);

n=1:

800

s=0.2*sin(2*pi*10/600*n+pi/2)

sn=s(1:

400)+u(1:

400)

subplot(221);

plot(s(1:

400)),grid

xlabel('n','FontSize',12);ylabel('s(n)','FontSize',12);

title('

(1)正弦序列','FontSize',8);

subplot(222);

plot(sn);grid

xlabel('n','FontSize',12);ylabel('sn(n)','FontSize',12);

title('

(2)噪化的正弦序列','FontSize',8);

subplot(223);

u2=sn(1:

200);

fori=1:

200

u3=sn(1+i-1:

200+i-1)

a(i)=u2*u3'

end

k=0:

199;

plot(k,a);grid

xlabel('n','FontSize',12);ylabel('a(n)','FontSize',12);

title('(3)从自相关函数检出序列含有周期成分','FontSize',8);

axis([0,200,-10,10]),

计算矩形冲激响应序列的DTFT

set(gcf,'color','w')%置图形背景色为白

N=6;nmax=32;n=0:

nmax;

x=[ones(1,N),zeros(1,nmax+1-N)];%给出输入序列

w=[-9.9:

0.1:

9.9]+1e-10;

X=(sin(N*w/2)./sin(w/2)).*exp(-j*(N-1)*w/2);%进行DTFT,给出频谱序列(关键语句)

subplot(2,2,1),stem(n,x,'.')%画出输入序列

axis([0,20,-0.1,1.1]),gridon

xlabel('n','FontSize',12);ylabel('x(n)','FontSize',12);

title('

(1)输入序列')

subplot(2,2,2),plot(w,abs(X)),gridon%画出模频特性

xlabel('\omega(rad./sample)','FontSize',12),ylabel('|X|','FontSize',12);

title('

(2)模频特性')

subplot(2,2,3),plot(w,angle(X)),gridon%画出相频特性

xlabel('\omega(rad./sample)','FontSize',12);ylabel('angleofX','FontSize',12);

title('(3)相频特性')

用Matlab计算FT和DTFT的方法。

验证采样间隔越小,DTFT就越逼近FT。

figure

(1)

set(gcf,'color','w')

%产生连续时间信号

Dt=0.00005;t=-0.005:

Dt:

0.005;xa=exp(-1000*abs(t));

%显示连续时间信号

subplot(221);plot(t*1000,xa);grid;

xlabel('t(sec)','FontSize',12);ylabel('xa(t)','FontSize',12);

title('

(1)连续时间信号');

%计算傅里叶积分并显示

fmax=2000;Wmax=2*pi*fmax;K=1000;k=-K:

1:

K;W=k*Wmax/K;

%Xa=xa*exp(-j*t'*W)*Dt;%Xa是行向量(第12行)

Xa=exp(-j*W'*t)*xa'*Dt;%Xa是列向量(第13行)

subplot(222);plot(W/(2*pi),abs(Xa));grid;%以f(Hz)作为频率轴

xlabel('f(Hz)','FontSize',12);ylabel('|Xa(jf)|','FontSize',12);

title('

(2)傅里叶积分(模值)');

%对连续时间信号采样

Ts=0.0002;n=-25:

1:

25;x=exp(-1000*abs(n*Ts));

subplot(223);H=stem(n*Ts*1000,x);set(H,'markersize',2);grid;axis([-5,5,0,1.1]);

xlabel('n','FontSize',12);ylabel('xa(n)','FontSize',12);

title('(3)对连续时间信号采样');

%计算DTFT(模值)并显示它的1个周期

fs=1/Ts;f=2000;K=1000;k=-K:

1:

K;N=200;w=(2*pi*(f/fs)*k/K);

X=x*exp(-j*n'*w);%X是行向量

subplot(224);plot(w*fs/(2*pi),abs(X));grid;%以f(Hz)作为频率轴

xlabel('f(Hz)','FontSize',12);ylabel('|X(jf)|','FontSize',12);

title('(4)离散时间傅里叶变换(模值,1个周期)');

%显示计算误差

%a=abs(Xa)-abs(X*Ts);%Xa和a都是行向量(第23行)

a=abs(Xa')-abs(X*Ts);%a是列向量(第24行)

error_max=max(a)

%error_max=-5.2822e-006

%显示DTFT(模值)的4个周期

figure

(2)

set(gcf,'color','w')

fs=1/Ts;f=2000;K=1000;a=5;k=-a*K:

1:

a*K;w=(2*pi*(f/fs)*k/K);

X=x*exp(-j*n'*w);

subplot(211);plot(w/(2*pi),abs(X));grid;%以归一化频率f/fs作为频率轴

xlabel('归一化频率','FontSize',12);ylabel('|X(jf)|','FontSize',12);

title('(5)离散时间傅里叶变换(模值,4个周期)');

演示相时延对信号波形的影响

set(gcf,'color','w')

n=0:

30;

fs=1000

S11=2*sin(2*pi*50*(1/fs)*n);S12=2*sin(2*pi*100*(1/fs)*n);S13=2*sin(2*pi*150*(1/fs)*n)

S21=2*sin(2*pi*50*(1/fs)*n-0.3*pi);S22=2*sin(2*pi*100*(1/fs)*n-0.6*pi);

S23=2*sin(2*pi*150*(1/fs)*n-0.9*pi)

S31=2*sin(2*pi*50*(1/fs)*n-0.3*pi);S32=2*sin(2*pi*100*(1/fs)*n-0.7*pi);

S33=2*sin(2*pi*150*(1/fs)*n-0.8*pi)

s1=S11+S12+S13;s2=S21+S22+S23;s3=S31+S32+S33

subplot(2,2,1)

plot(n,s1);grid;

xlabel('n','FontSize',12);ylabel('s1(n)','FontSize',12);

title('

(1)原来的合成信号1','fontsize',8)

subplot(2,2,2)

plot(n,s2);grid;1

xlabel('n','FontSize',12);ylabel('s2(n)','FontSize',12);

title('

(2)合成信号2--相位移与频率成正比','fontsize',8)

subplot(2,2,3)

plot(n,s3);grid;axis([130-55]);

xlabel('n','FontSize',12);ylabel('s3(n)','FontSize',12);

title('(3)合成信号3--相位移与频率不成正比','fontsize',8)

演示群时延对调幅波包络线的影响

set(gcf,'color','w');

f1=0.3;f2=0.8;f3=1.2;%三个低频调制分量的相位值

fc=10;%载波频率fc>>f1,f2,f3

fs=200;%采样频率

n=1:

2000;

c=cos(2*pi*(fc/fs)*n)%载波

%---------------------------

subplot(321);

d10=0.3;d20=0.6;d30=1.2;%三个低频调制分量的相位值

s10=1+0.6*cos(2*pi*(f1/fs)*n+d10);%调幅波包络线分量1

s20=1+0.2*cos(2*pi*(f2/fs)*n+d20);%调幅波包络线分量2

s30=1+0.5*cos(2*pi*(f3/fs)*n+d30);%调幅波包络线分量3

sm0=(s10+s20+s30).*c;%原来的调幅波

plot(n,sm0);grid

xlabel('n','Fon

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 交通运输

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1