📄 qpsk.m
字号:
echo off
close all
clc
w1=8; %通道载波频率设定为2
w2=300000000; %载波频率设定为30M
N=20; %产生40个点
x=randint(1,N,[0,1]); %产生随机信号
figure(1);
subplot(3,1,1);
stem(x(1:N),'fill','--'); %随机信号图形
title('随机二进制数');
xlabel('Bit Index');
%串并转换
y=reshape(x,2,N/2);
y1=y(1,:);
y2=y(2,:);
subplot(3,1,2);
stem(y1(1:N/2),'fill','--'); %I通道图形
title('I通道y1');
xlabel('Bit Index');
subplot(3,1,3);
stem(y2(1:N/2),'fill','--'); %Q通道图形
title('Q通道y2');
xlabel('Bit Index');
%变换成双极性电瓶
%对y1变换其中y1是I通道的随即点波形
for i=1:length(y1), %计算码元的值
if(y1(i)==1), %如果信息为1
for j=1:200, %该码元对应得点取值为1
y3((i-1)*200+j)=1;
end
else
for j=1:200, %反之,信息元为0,则变成负电瓶
y3((i-1)*200+j)=-1;
end;
end;
end
%画信号y1变换成双极性电瓶的信号y3
figure(2);
subplot(2,1,1);
n=length(y1);
t=linspace(0,n,length(y3));
plot(t,y3);
axis([0 n -1.5 1.5]);
title('I通道双极性');
xlabel('Bit Index');
%对y2变换变换成双极性电瓶的信号y4
for m=1:length(y2), %计算码元的值
if(y2(m)==1), %如果信息为1
for n=1:300, %该码元对应得点取值为1
y4((m-1)*300+n)=1;
end
else
for n=1:300, %反之,信息元为0,则变成负电瓶
y4((m-1)*300+n)=-1;
end;
end;
end
%画信号y1变换成双极性电瓶的信号y3
figure(3);
subplot(2,1,1);
n=length(y2);
t=linspace(0,n,length(y4));
plot(t,y4);
axis([0 n -1.5 1.5]);
title('Q通道双极性');
xlabel('Bit Index');
%实现扩频
connections=[1 0 1 0 1];
z11=kuopin1(y1,connections);
figure(4)
subplot(311);
t1=length(y1);
t2=length(connections);
m1=t1*(2^t2-1);
t=linspace(0,m1,length(z11));
plot(t,z11);
axis([0 m1 -1.5 1.5]);
title('I通道扩频后图形');
xlabel('点数');
z22=kuopin1(y2,connections);
figure(5)
subplot(311);
t=linspace(0,m1,length(z22));
plot(t,z22);
axis([0 m1 -1.5 1.5]);
title('Q通道扩频后图形');
xlabel('点数');
%===================================================================
%调制I通道
t=linspace(0,m1,length(z11));
z1=-1*sin(2*pi*w1*t).*z11;
figure(2)
subplot(2,1,2);
plot(t,z1);
axis([0 m1 -1.5 1.5]);
title('I通道调制');
xlabel('时间t');
%调制Q通道
t=linspace(0,m1,length(z22));
z2=cos(2*pi*w1*t).*z22;
figure(3)
subplot(2,1,2);
plot(t,z2);
axis([0 m1 -1.5 1.5]);
title('Q通道调制');
xlabel('时间t');
z=z1+z2;
figure(6);
subplot(211);
plot(t,z);
axis([0 m1 -2 2]);
title(' I+Q调制后图形');
xlabel('时间坐标t');
%加载破进行射频调制
t=linspace(0,m1,length(z));
out=z.*cos(2*pi*w2*t);
figure(7);
plot(t,out);
title('载波调制后图形');
xlabel('时间坐标t');
%=====================================================================
%qpsk解调
%以下是解调全过程
%=====================================================================
t=linspace(0,m1,length(out));
s1=out.*cos(2*pi*w2*t);
%设计滤波器
[n,Wn]= buttord(0.3,0.5,1,25) ;
[b,a]=butter(n,Wn,'low') ;
s2=filter(b,a,s1); %通过低通滤波器
figure(6);
subplot(212);
t=linspace(0,m1,length(s2));
plot(t,s2);
axis([0 m1 -1 1]);
title('去载波后的I+Q图形');
xlabel('时间坐标t');
%=================================================================
%通道解调
%=================================================================
%I通路解调
t=linspace(0,m1,length(s2));
r1=s2.*cos(2*pi*w1*t);
[n,Wn]= buttord(0.1,0.2,1,25) ;
[b,a]=butter(n,Wn,'low') ;
OUTI=filter(b,a,r1);
t=linspace(0,m1,length(OUTI));
figure(4);
subplot(3,1,2);
plot(t,OUTI);
title('解调出来的I通道双极性波形');
xlabel('时间轴');
%Q通路解调
t=linspace(0,m1,length(s2));
r2=s2.*sin(2*pi*w1*t);
[n,Wn]= buttord(0.1,0.2,1,25) ;
[b,a]=butter(n,Wn,'low') ;
OUTQ=filter(b,a,r2);
t=linspace(0,m1,length(OUTQ));
figure(5);
subplot(3,1,2);
plot(t,OUTQ);
title('解调出来的Q通道双极性波形');
xlabel('时间轴');
%============================================================
%信号恢复
%============================================================
%I通道信号整形
t=linspace(0,m1,length(OUTI));
OUTI1=sign(OUTI);
figure(4)
subplot(313);
plot(t,OUTI1);
axis([0 m1 -1.5 1.5]);
title('I 通道整形后函数图像');
xlabel('时间坐标t');
%Q 通道信号整形
t=linspace(0,m1,length(OUTQ));
OUTQ2=sign(OUTQ);
figure(5)
subplot(313);
plot(t,OUTQ2);
axis([0 m1 -1.5 1.5]);
title('Q 通道整形后函数图像');
xlabel('时间坐标t');
%=========================================================
%接扩
%=========================================================
dianshu=50:100:length(OUTI1);
j=50;
for i=1:length(dianshu);
p1(i)=OUTI1(j);
j=j+100;
end;
j=50;
for i=1:length(dianshu);
p2(i)=OUTQ2(j);
j=j+100;
end;
figure(8);
subplot(211);
stem(p1(1:length(dianshu)),'fill','--');
subplot(212);
stem(p2(1:length(dianshu)),'fill','--');
%产生N个M序列,以便解调
xulie=ones(N/2,1);
connections=[1 0 1 0 1];
sqe=m_sequence(connections);
for i=1:length(xulie),
if(xulie(i)==1),
for j=1:length(sqe),
jiekuo((i-1)*length(sqe)+j)=sqe(j);
end
end
end;
for t=1:length(jiekuo)
if(jiekuo(t)==1);
jiekuo(t)=1;
else jiekuo(t)=-1;
end;
end;
jiekuohouI=jiekuo.*p1;
jiekuohouQ=jiekuo.*p2;
t=length(jiekuohouI);
figure(9)
subplot(211);
plot(jiekuohouI);
axis([0 length(jiekuohouI) -1.5 1.5])
title('I接扩后图形')
xlabel('时间轴')
subplot(212)
plot(jiekuohouQ);
axis([0 length(jiekuohouI) -1.5 1.5])
title('Q接扩后图形')
xlabel('时间轴')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -