t0=0.15; ts=0.001; fc=250; snr=20; fs=1/ts; df=0.3; t=(0:ts:t0);
snr_lin=10^(snr/10); %信噪比
m=[ones(1,t0/(3*ts)),-2*ones(1,t0/(3*ts)),zeros(1,t0/(3*ts)+1)]; c=cos(2.*pi.*fc.*t); %载波 u=[2+0.85*m].*c;
[M,m,df1]=fftseq(m,ts,df); M=M/fs;
[U,u,df1]=fftseq(u,ts,df); U=U/fs;
[C,c,df1]=fftseq(c,ts,df);
f=[0:df1:df1*(length(m)-1)]-fs/2; dt=0.01;
signal_power=sum(u.*u)*dt/(length(t).*dt); noise_power=signal_power/snr_lin; noise_std=sqrt(noise_power); n=noise_std*randn(1,length(u)); r=u+n;
[N,n,df1]=fftseq(n,ts,df); %对噪声进行fft
N = N/fs; %频率采样 [R,r,df1]=fftseq(r,ts,df); %对最后的信号进行fft R = R/fs; signal_power noise_power figure(1)
plot(t,m(1:length(t))) xlabel('Time') title('基带信号') figure(2)
subplot(2,1,1)
plot(t,c(1:length(t))) xlabel('Time') title('载波信号') subplot(2,1,2)
plot(t,u(1:length(t)))
xlabel('Time') title('调制信号') figure(3)
subplot(2,1,1)
plot(f,abs(fftshift(M))) xlabel('frequency') title('基带信号频谱') subplot(2,1,2)
plot(f,abs(fftshift(U))) title('调制信号频谱') xlabel('frequency')
figure (4) subplot(2,1,1) plot(t,n(1:length(t))) title('噪声信号')
subplot(2,1,2) plot(f,abs(fftshift(N))) axis([-200 200 0 0.15]) title('噪声信号频谱') figure (5)
subplot(2,1,1) plot(t,r(1:length(t))) title('信号加噪声信号') axis([0 0.15 -3 3])
subplot(2,1,2) plot(f,abs(fftshift(R)))
title('信号加噪声信号频谱') axis([-500 500 0 0.15])
fftseq文件:
function [M,m,df]=fftseq(m,ts,df) fs=1/ts; n1=fs/df;
n2=length(m);
n=2^(max(nextpow2(n1),nextpow2(n2))); M=fft(m,n);
m=[m,zeros(1,n-n2)]; df=fs/n;
signal_power = 2.0484 noise_power = 0.0205
%噪声时域显示 %噪声频域显示 %加噪调制信号时域显示 %加噪调制信号频域显示 运行结果: signal_power =
2.0484
noise_power =
0.0205
signal_power =
2.0484
noise_power =
0.0205
signal_power =
2.0484
noise_power =
0.0205
signal_power =
2.0484
noise_power =
0.0205
signal_power =
2.0484
noise_power =
0.0205
signal_power =
2.0484
noise_power =
0.0205
示范课题:
第二题 clear clc clf
b=3000; sn0=-20; sn1=30; ns=0.01;
N=(sn0:ns:sn1); snrlin=10.^(N/10);
ct=b.*log2(1+snrlin.*(1/b)); plot(snrlin,ct) xlabel('s/n0')
title('高斯信道容量')
clear clc clf
n1=2.5; sn1=10.^n1; b0=300000; bs=10;
B=(3000:bs:b0); b=1./B;
ct=B.*(log2(1+sn1.*b)); plot(B,ct) xlabel('B')
title('信道容量') ct=(1/log(2)*sn1)
运行结果: ct =
456.2202
第三题 clear all; clf; Tb=1;
f1=1000/Tb; f2=f1+1/Tb; phi=pi/4; N=12000; n=N/4;
t=0:Tb/(n-1):Tb;%t=0:1/(n-1):1;
T=0:4*Tb/(N-1):4*Tb;%T=0:4*1/(N-1):4*1;
s1=[cos(2*pi*f1*t+phi) cos(2*pi*f1*t+phi) cos(2*pi*f1*t+phi) cos(2*pi*f1*t+phi)];
s2=[cos(2*pi*f2*t+phi) cos(2*pi*f2*t+phi) cos(2*pi*f2*t+phi) cos(2*pi*f2*t+phi)];% assume the transmit signal is \"1010\
a=[cos(2*pi*f2*t+phi) cos(2*pi*f1*t+phi) cos(2*pi*f2*t+phi) cos(2*pi*f1*t+phi)]; % a is the received signal b=a.*s1; c=a.*s2;
for j=1:4
for i=1:n;
d((j-1)*n+i)=sum(b((j-1)*n+1:(j-1)*n+i)); end; end;
%求积分 for j=1:4
for i=1:n;
e((j-1)*n+i)=sum(c((j-1)*n+1:(j-1)*n+i)); end; end;
%求积分
for j=1:4;
if d(j*n)>e(j*n);
f((j-1)*n+1:j*n)=zeros(1,n);%输出0 else
f((j-1)*n+1:j*n)=ones(1,n);%输出1 end; end;
%比较器 figure(1) plot(T,a);
xlabel('时间'); ylabel('幅度'); title('figure a'); hold on figure(2)
subplot(2,1,1); plot(T,b); ylabel('幅度'); title('figure b'); subplot(2,1,2) plot(T,c);
ylabel('幅度'); xlabel('时间'); ylabel('幅度'); title('figure c'); hold on
figure(3)
subplot(3,1,1); plot(T,d); ylabel('幅度'); title('figure d'); subplot(3,1,2); plot(T,e);
ylabel('幅度'); title('figure e'); subplot(3,1,3); plot(T,f);
xlabel('时间'); ylabel('幅度'); title('figure f');
第四题 (1)、 n=15; k=5;
g=[1 0 1 0 0 1 1 0 1 1 1]; m=mMatrix(k); for i=0:2^k-1
nkm=[m(i+1,:) zeros(1,n-k)]; [q r]=deconv(nkm,g); r=mod(r,2); len_r=length(r);
r=[zeros(1,n-len_r) r]; c(i+1,:)=mod(nkm+r,2) end;
for i=1:2^k
weight(i)=sum(c(i,:)); end;
minW=weight(2) for i=3:2^k;
if weight(i) 全部系统码字: c = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Column 15 0 1 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 0 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 0 1 0 1 0 1 1 1 1 0 0 1 0 1 1 1 1 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1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 1 1 0 1 1 1 0 1 1 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 0 1 0 1 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 mMatrix文件: function m=mMatrix(k) % m(1,:)=[0 0 0 0 0]; m(2,:)=[0 0 0 0 1]; for i=2:2^k-1; t=i; e=1; d=2^e; a=[0 0 0 0 0]; while 1; if t>d; e=e+1; d=2^e; else break; end; end; if t<2^e; e=e-1; end; while 1; if t-2^e==0; a(k-e)=1; break; end; if t-2^e>0; a(k-e)=1; t=t-2^e; e=e-1; else a(k-e)=0; e=e-1; end; end; m(i+1,:)=a; a=[0 0 0 0 0]; end; 因篇幅问题不能全部显示,请点此查看更多更全内容