📄 psk_8.m
字号:
%============= 2008.4.21 ======%
%========== “根” 升余弦 脉冲
clear;
clc;
fs=12000; % sample rate
ts=1/fs;
tb=ts*5;
fc=1800; % carrier frequency
df=1;
alpha=0.25;
t=(-4*tb):ts:(4*tb); % time sample
N=100;
s=randint(1,N,8); % stream of bits
%=============脉冲波形
xrc=sin(pi*t/tb)./(pi*t/tb).*(2*cos(pi*t/tb)+tb^2./(4*t.^2*alpha^2-1).*cos(pi*t*alpha/tb));
for k=1:4*2*5
if mod(k,5)==1
xrc(k)=0;
end;
end;
xrc(21)=2-tb^2;
%=============脉冲叠加形成待调制波形
total=41+5*(N-1);
wi=zeros(1,total);
wq=zeros(1,total);
map=[1;0.707+i*0.707;i;-70707+i*0.707;
-1;-0.707-i*0.707;-i;0.707-i*0.707];
for k=1:N
switch s(k)
case 0
si=1,sq=0;
case 1
si=0.707,sq=0.707;
case 2
si=0,sq=1;
case 3
si=-0.707,sq=0.707;
case 4
si=-1,sq=0;
case 5
si=-0.707,sq=-0.707;
case 6
si=0,sq=-1;
otherwise
si=0.707,sq=-0.707;
end;
tempi=[zeros(1,(k-1)*5),xrc*si,zeros(1,total-length(xrc)-(k-1)*5)];
tempq=[zeros(1,(k-1)*5),xrc*sq,zeros(1,total-length(xrc)-(k-1)*5)];
wi=wi+tempi;
wq=wq+tempq;
end;
subplot(5,2,1),plot(wi);
subplot(5,2,2),plot(wq);
%=============调制到1800Hz载频
t=0:ts:((N-1)*5+40)*ts;
ci=cos(2*pi*fc*t);
cq=-sin(2*pi*fc*t);
xi=wi.*ci;
xq=wq.*cq;
subplot(5,2,3),plot(xi);
subplot(5,2,4),plot(xq);
x=xi+xq;
subplot(5,2,5),plot(x);
%=============接收后再乘以载波
yi=x.*ci;
yq=x.*cq;
subplot(5,2,7),plot(yi);
subplot(5,2,8),plot(yq);
%=============匹配滤波
f_out_i=conv(yi,xrc);
f_out_q=conv(yq,xrc);
subplot(5,2,9),plot(f_out_i);
subplot(5,2,10),plot(f_out_q);
%=============采样判决
for k=1:N
d_i(k)=f_out_i((k-1)*5+41);
d_q(k)=f_out_q((k-1)*5+41);
for l=1:8
tt=d_i(k)+i*d_q(k);
distance(l)=abs(map(l)-tt);
md=min(distance);
switch md
case distance(1)
out(k)=0;
case distance(2)
out(k)=1;
case distance(3)
out(k)=2;
case distance(4)
out(k)=3;
case distance(5)
out(k)=4;
case distance(6)
out(k)=5;
case distance(7)
out(k)=6;
case distance(8)
out(k)=7;
end;
end;
end;
err=0;
for k=1:N
if out(k)~=s(k)
err=err+1;
else;
end;
end;
% %==============观察解调后的波形
% for i=1:N % 形成方波
% u((i-1)*5+1:(i-1)*5+5)=g*d(i);
% end;
% subplot(6,1,6),plot(u);axis([1,600,-2,2]);
% %==============观察解调后的波形
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -