通信原理实验4 BPSK系统仿真matlab程序,波形
实验名称:BPSK系统实验
一.程序代码
close all;clc;clear;
ts=1;fc=2;
n_sample=200;n_num=1000;
dt=ts/n_sample;t=0:dt:n_num*ts-dt;
d=2*randint(1,n_num)-1;
st_bb=rectpulse(d,n_sample);
st_2psk=st_bb.*cos(2*pi*fc*t);
figure;
subplot(2,1,1);
plot(t,st_2psk);
axis([0 13 -1 1]);title('时域波形');
nloop=20;nfft=2^16;sp_p=0;
window=boxcar(length(st_2psk));
for k=1:nloop
[px,f]=periodogram(st_2psk,window,nfft,1/dt);
sp_p=sp_p+px;
d=2*randint(1,n_num)-1;
st_bb=rectpulse(d,n_sample);
st_2psk=st_bb.*cos(2*pi*fc*t);
end
subplot(2,1,2);
plot(f,sp_p);
axis([0 7 0 20]);title('功率谱');
snr_db=20;snr=10^(snr_db/10);
s=mean(d.^2);sigma=sqrt(s/snr);
n=sigma*randn(size(d))+j*sigma*randn(size(d));
rt=d+n;
figure;
subplot(1,2,1);
plot(rt,'.');
axis([-2 2 -0.5 0.5]);title('dB=20时的星座图');
snr_db=5;snr=10^(snr_db/10);
s=mean(d.^2);sigma=sqrt(s/snr);
n=sigma*randn(size(d))+j*sigma*randn(size(d));
rt=d+n;
hold on;
subplot(1,2,2);
plot(rt,'.');
axis([-2.5 2.5 -2 2]);title('dB=5时的星座图');
二.波形图