clear all;
close all;
code_length=1000; %信息码元个数
x1=sign(rand(1,code_length)-0.5); %信息码
for i=1:1000
s2((1+(i-1)*10):i*10)=x1(i); %每个信息码元内含fs/f=310个采样点
end
T = length(s2);
figure(1);
subplot(211);
stem(x1);
title('a 脉冲信号');
subplot(212);
plot( s2 );
axis([ 0 1000 -1.2 1.2 ]);
title('b 矩形信号');
%*************************************************************************
% 2PSK 调制
t=linspace(0,50,10000);
si=sin(40*pi*t);
figure(2);
subplot(211);
plot(si);
axis([0,200,-1.2,1.2]);
title('a 载波信号si');
epsk=s2 .* si;
subplot(212);
plot(epsk);
axis([0,200,-1.2,1.2]);
title('b 2psk调制信号');
%************************************************************************
% 加入高斯白噪声
xinhao=awgn(epsk,10); % 通过高斯信道之后的信号
zaosheng=xinhao-epsk; % 高斯噪声曲线
figure(3);
subplot(211);
plot(xinhao);
title('a 加入高斯噪声后的信号');
axis([0,200,-2,2]);
subplot(212);
plot(zaosheng);
title('b 高斯噪声');
axis([0,200,-2,2]);
%********************************************************
% 2psk解调
jietiaoo = xinhao .* si;
figure(4);
subplot(211);
plot(jietiaoo);
axis([0,200,-1.2,1.2]);
title('a 与载波相乘之后的波形');
[f,af] = T2F(t,jietiaoo); %转变到频域
[t,jietiao2] = lpf(f,af,20); %通过低通滤波器,带宽为40
subplot(212);
plot(jietiao2);
axis([0,10000,-1.2,1.2]);
title('b 低通滤波之后的波形');
%**********************************************************
% 抽样判决
for mq=0:999;
if jietiao2( 1,10*mq+5 )<0; %取中间值进行判断
for j= mq*10+1:(mq+1)*10 ;
ji(1,j)=-1;
ab(mq+1)=-1;
end
else
for j=mq*10+1:(mq+1)*10;
ji(1,j)=1;
ab(mq+1)=1;
end
end
end
figure(5);
plot(ji);
axis([0,10000,-1.2,1.2]);
title('a 抽样判决后波形');
%******************************************************************
su = ab - x1;
figure(6);
stem(su);
title('b 检错电平');
%figure(7);
%stem(a);
%title('抽样后的脉冲波形');
A = length(find(su));
B = A/1000;
close all;
code_length=1000; %信息码元个数
x1=sign(rand(1,code_length)-0.5); %信息码
for i=1:1000
s2((1+(i-1)*10):i*10)=x1(i); %每个信息码元内含fs/f=310个采样点
end
T = length(s2);
figure(1);
subplot(211);
stem(x1);
title('a 脉冲信号');
subplot(212);
plot( s2 );
axis([ 0 1000 -1.2 1.2 ]);
title('b 矩形信号');
%*************************************************************************
% 2PSK 调制
t=linspace(0,50,10000);
si=sin(40*pi*t);
figure(2);
subplot(211);
plot(si);
axis([0,200,-1.2,1.2]);
title('a 载波信号si');
epsk=s2 .* si;
subplot(212);
plot(epsk);
axis([0,200,-1.2,1.2]);
title('b 2psk调制信号');
%************************************************************************
% 加入高斯白噪声
xinhao=awgn(epsk,10); % 通过高斯信道之后的信号
zaosheng=xinhao-epsk; % 高斯噪声曲线
figure(3);
subplot(211);
plot(xinhao);
title('a 加入高斯噪声后的信号');
axis([0,200,-2,2]);
subplot(212);
plot(zaosheng);
title('b 高斯噪声');
axis([0,200,-2,2]);
%********************************************************
% 2psk解调
jietiaoo = xinhao .* si;
figure(4);
subplot(211);
plot(jietiaoo);
axis([0,200,-1.2,1.2]);
title('a 与载波相乘之后的波形');
[f,af] = T2F(t,jietiaoo); %转变到频域
[t,jietiao2] = lpf(f,af,20); %通过低通滤波器,带宽为40
subplot(212);
plot(jietiao2);
axis([0,10000,-1.2,1.2]);
title('b 低通滤波之后的波形');
%**********************************************************
% 抽样判决
for mq=0:999;
if jietiao2( 1,10*mq+5 )<0; %取中间值进行判断
for j= mq*10+1:(mq+1)*10 ;
ji(1,j)=-1;
ab(mq+1)=-1;
end
else
for j=mq*10+1:(mq+1)*10;
ji(1,j)=1;
ab(mq+1)=1;
end
end
end
figure(5);
plot(ji);
axis([0,10000,-1.2,1.2]);
title('a 抽样判决后波形');
%******************************************************************
su = ab - x1;
figure(6);
stem(su);
title('b 检错电平');
%figure(7);
%stem(a);
%title('抽样后的脉冲波形');
A = length(find(su));
B = A/1000;

