⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 陈城的作业.m

📁 这是一个完整的描述软件无线电的MATLAB编程
💻 M
字号:

clc
clear
% Carrier frequency for modulation and demodulation
Fd=1e3
Fc=128e3;
% Generate an randm sequence of 0 and 1
% Input binary data of 1KHz
n=0:6000
data=100;     %发送100个0、1随机序列
rand_data=randn(1,data);
for i=1:data
    if rand_data(i)>=0
        input(i)=1;
    else 
        input(i)=0;
    end
end
%画图
tb=[0:data-1]/(2*Fd);
figure(1);
stem(tb,input,'x');
axis([0 0.01 -1.6 1.6]);
legend('发送信号');
xlabel('Time (seconds)');ylabel('Signal Value');

% Series to Parallel
Ix=input(1:2:length(input));    
Qx=input(2:2:length(input));

% QPSK Encoder.
for i=1:length(Ix)
    if  Ix(i)==1
        I(i)=-1;
    else I(i)=1;
    end
end    
for i=1:length(Qx)
    if Qx(i)==1
         Q(i)=-1;
    else Q(i)=1;
    end
end

delay=2;
Fd=1000;
Fs=8000;
r=0.5;
N0=32;
[Ipulse,tx]=rcosflt(I,1e3,8e3,'sqrt',0.5,2);   %Ipulse长度为8*data/2+N0
[Qpulse,ty]=rcosflt(Q,1e3,8e3,'sqrt',0.5,2);   %Ipulse长度为8*data/2+N0
%取中间4*data个点
for i=1:4*data                                 
    Ipulse(i)=Ipulse(i+N0/2);
    Qpulse(i)=Qpulse(i+N0/2);
end


%====================================================
%                半带滤波器内插  2倍                 
%====================================================
L1=2;
N1=L1*4*data;
%7阶半带滤波器系数
h1=[-0.031303 0 0.281280 0.499954 0.281280 0 -0.030303];  
%脉冲成形滤波后的I,Q两路基带信号每两个点内插一个0
Izero1=zeros(1,N1);
Qzero1=zeros(1,N1);
Izero1(1:L1:end)=Ipulse(1:4*data);
Qzero1(1:L1:end)=Qpulse(1:4*data);
%内插0值的数据经半带滤波器滤波
Ipulse1=conv(Izero1,2*h1);
Qpulse1=conv(Qzero1,2*h1);
for i=1:8*data
    Ipulse1(i)=Ipulse1(i+3);
    Qpulse1(i)=Qpulse1(i+3);
end
%以下为画图命令
figure(3);
stem(n(1:80)/Fs,Ipulse(1:80),'filled');hold on;
stem(n(1:160)/(2*Fs),Ipulse1(1:160),'r');
h= legend('2倍内插之前','2倍内插之后',2);

xlabel('Time (seconds)');ylabel('Signal Value');


%====================================================
%               CIC滤波器内插    25倍                 
%====================================================
L2=25;
N2=L2*L1*4*data;
%内插2倍后的I,Q基带信号每两个点之间插24个0
Izero2=zeros(1,N2);
Qzero2=zeros(1,N2);
Izero2(1:L2:end)=Ipulse1(1:8*data);
Qzero2(1:L2:end)=Qpulse1(1:8*data);
%使用4级CIC内插滤波器
cic25_1=ones(1,25);
cic25_2=conv(cic25_1,cic25_1);
cic25_4=conv(cic25_2,cic25_2);
[h2,w]=freqz(cic25_4);
cic25_4=25*cic25_4/h2(1);
Ipulse2=conv(Izero2,cic25_4);
Qpulse2=conv(Qzero2,cic25_4);
Ipulse3=Ipulse2(49:200*data+48)
Qpulse3=Qpulse2(49:200*data+48)
%以下为画图命令
figure(4);
stem(n(1:2)/(2*Fs),Ipulse1(1:2),'fill');
hold on;
stem(n(1:50)/(50*Fs),Ipulse2(49:98),'r');
h= legend('CIC内插之前','CIC内插之后',2);

xlabel('Time (seconds)');ylabel('Signal Value');


%====================================================
%  发送端把信号提升,接收端混频提取基带信号                  
%====================================================
for i=1:200*data
    t(i)=(i-1)/(50*Fs);
    Imod(i)=Ipulse3(i).*sqrt(2)*cos(2*pi*Fc*t(i));
    Qmod(i)=Qpulse3(i).*(-sqrt(2))*sin(2*pi*Fc*t(i));
end
sum=Imod+Qmod;
for i=1:200*data
    Idem(i)=sum(i).*sqrt(2)*cos(2*pi*Fc*t(i));
    Qdem(i)=sum(i).*(-sqrt(2))*sin(2*pi*Fc*t(i));
end
%画图
figure(5);
subplot(211);
plot(t,sum,'r');
axis([0 0.01 -1.6 1.6]);
legend('发送端正交调制');
xlabel('Time (seconds)');ylabel('Signal Value');
subplot(212);
plot(t,Idem);
axis([0 0.01 -1.6 1.6]);
legend('接收端I混频信号');
xlabel('Time (seconds)');ylabel('Signal Value');

%====================================================
%  对接收端提取的基带信号进行抽取   50倍                
%====================================================
Ir1=conv(Idem,cic25_4/25);
Qr1=conv(Qdem,cic25_4/25);
Ir2=Ir1(49:25:200*data+48);
Qr2=Qr1(49:25:200*data+48);
%2倍抽取
Ir3=conv(Ir2,h1);
Qr3=conv(Qr2,h1);
Ir4=Ir3(4:2:8*data+3);
Qr4=Qr3(4:2:8*data+3);
%画图
figure(6);
subplot(211);
stem(n(1:160)/(2*Fs),Ir2(1:160),'r');
legend('CIC抽取后波形');
xlabel('Time (seconds)');ylabel('Signal Value');
subplot(212);
stem(n(1:160)/(2*Fs),Ir2(1:160),'fill');hold on;
stem(n(1:80)/Fs,Ir4(1:80),'r');
legend('2倍抽取后波形');
xlabel('Time (seconds)');ylabel('Signal Value');


%====================================================
%  接收端接匹配滤波器               
%====================================================
mtf=rcosfir(0.5,2,8,1e3,'sqrt');
Imat=conv(Ir4,mtf);
Qmat=conv(Qr4,mtf);
%Data selection
Isam=Imat(17:8:4*data+16);
Qsam=Qmat(17:8:4*data+16);
%Decision threshold,判决门限为0.2;

for i=1:data/2
      if Isam(i)>=0.2
         Ifinal(i)=1;
      else
         Ifinal(i)=-1;
      end
      if Qsam(i)>=0.2
         Qfinal(i)=1;
      else 
         Qfinal(i)=-1;
      end
end
%画图
figure(7)
subplot(211);
stem(ta,Ifinal,'kx');
axis([0 0.01 -1.6 1.6]);
legend('接收到的I路信号');
subplot(212);
stem(ta,Qfinal,'kx');
axis([0 0.01 -1.6 1.6]);
legend('接收到的Q路信号');
xlabel('Time (seconds)');ylabel('Signal Value');


%====================================================
%  QPSK解调              
%====================================================
for i=1:length(Ifinal)
    if  Ifinal(i)==1
        Ip(i)=0;
    else Ip(i)=1;
    end
    if Qfinal(i)==1
         Qp(i)=0;
    else Qp(i)=1;
    end
end


%====================================================
%    最后接受端得到输出序列          
%====================================================
output=zeros(1,data);
output(1:2:data)=Ip;
output(2:2:data)=Qp;
figure(8);
stem(tb,output,'x');
axis([0 0.01 -1.6 1.6]);
legend('接收到的信号');
xlabel('Time (seconds)');ylabel('Signal Value');



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -