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

📄 idealchannel.m

📁 本程序模拟了无线通信中常用的AWGN
💻 M
字号:

fc=50;                    % carrier frequency
Fs=40;   %系统采样频率
Fd=1;    %码速率
num=20;                   % number of symbols
data=rand(1,num)>0.5;    %产生20个(0,1)随机数
source_qpsk=2*data-1;    %把(0,1)变换成(-1,1)
figure(1);               %画出原始信号的阶梯图
stairs(source_qpsk,'g');
    title('the source single of QPSK');

%%%%串并转换
% %%function [Ichannel,Qchannel] = SerialToParallel(source_qpsk)
Ichannel=source_qpsk(1:2:length(source_qpsk));
Qchannel =source_qpsk(2:2:length(source_qpsk));
%%%%通过成形滤波器  
%%%%figure(2)figure(3)画的是是进过滤波器后的信号Ichannel_shape,Qchannel_shape
figure(2);
Ichannel_shape =rcosflt(Ichannel, Fd, Fs, 'fir', 0.5, 3);
plot(Ichannel_shape);
title('the  Ichannel single of QPSK being filtered by shape filter');
 figure(3);
Qchannel_shape=rcosflt(Qchannel, Fd, Fs,' fir', 0.5, 3);
plot(Qchannel_shape);
title('the  Qchannel single of QPSK  being  filtered by shape filter');
%%%%调制信号
t=0:(1/639):1;  %%%t是根据Ichannel_shape的点数确定的,因为乘载波时要点乘,行列要对称
%%% figure(4), figure(5)画的是经过调制的信号Ichannel_signal,Qchannel_signal
 figure(4);
Ichannel_signal=Ichannel_shape'.*cos(2*pi*fc*t);
plot(Ichannel_signal);
title('the  Ichannel single of QPSK being modulated');
 figure(5);
Qchannel_signal=Qchannel_shape'.*sin(2*pi*fc*t);
plot(Qchannel_signal);
title('the  Qchannel single of QPSK being  modulated');
%%% figure(6)是在要传输的QPSK信号
 figure(6);
qpsk_single=Ichannel_signal+Qchannel_signal;
plot(t,qpsk_single);
title('the   single of QPSK to be translated' );

%%%%解调部分
%%%%%%% figure(7), figure(8)画的是经过解调后的信号demoIchannel_signal,demoQchannel_signal
 figure(7)
demoIchannel_signal=Ichannel_signal.*cos(2*pi*fc*t);
plot(demoIchannel_signal);
title('the  Ichannel single of QPSK being demodulated');
 figure(8)
demoQchannel_signal=Qchannel_signal.*sin(2*pi*fc*t);
plot(demoQchannel_signal);
title('the  Qchannel single of QPSK being demodulated');
%%%%经过低通滤波器 

%%% figure(9),figure(10)画的是经过低通滤波器的信号demoIchannel_shape,demoQchannel_shape
figure(9);
demoIchannel_shape =rcosflt(demoIchannel_signal, Fd, Fs, 'fir', 0.5, 3);
plot(demoIchannel_shape );
title('the  Ichannel single of QPSK being filtered by LPF');
 figure(10);
demoQchannel_shape=rcosflt(demoQchannel_signal, Fd, Fs,' fir', 0.5, 3);
plot(demoQchannel_shape);
title('the  Qchannel single of QPSK being filtered by LPF');
%%%%判决
s=length(demoIchannel_shape);
%%%%因为经过低通滤波器,必然造成输出信号出现拖尾的残留信号,这些对判决是不利的,应该除去;
%%%%这个步骤是判决能否取得正确结果的关键;
for w=s:-1:1;%%%这个循环主要把信号的末尾部分的残留信号去掉。
  if ((demoIchannel_shape(w)>0.25)||(demoIchannel_shape(w)<-0.25))
 s=w;
break;
  end;
end;
h=0;
for x=1:s;%%%%这个循环主要把信号的开始部分的残留信号去掉。
  if ((demoIchannel_shape(x)>0.25)||(demoIchannel_shape(x)<-0.25))
 h=x;
break;
  end;
  end;
  s=s-h;
  %%开始判决
  %%算法是:因为每个信道有10个码元,所以把有效信号的所以点数分成十段,
  %%对每一段分布判决。这里设门限值为0,设两个计数器m,n,对所有点进行判断,当
  %%某点大于0判为1,否则为-1;
  %%对I信道;
 for i=1:10;
    m=0;
    n=0;
    for j=floor(((i-1)*s/10+x)):floor(((i*s))/10+x);%%%注意这个循环中始末位置的选择
        if  demoIchannel_shape(j)>0;
            m=m+1;
        else if  demoIchannel_shape(j)<0;
                n=n+1;
            end;    
        end;
        if m>n   a(i)=1;
        else a(i)=-1;
        end;
     end;
end;
%%%对Q信道
for i=1:10;
    p=0;
    q=0;
    for j=floor(((i-1)*s/10+x)):floor(((i*s))/10+x);
        if  demoQchannel_shape(j)>0;
           p=p+1;
        else if  demoQchannel_shape(j)<0;
                q=q+1;
            end;    
        end;
        if p>q   b(i)=1;
        else b(i)=-1;
        end;
     end;
end;
%%%% 并串转换
for i=1:10;
    enddata(2*i-1)=a(i);
    enddata(2*i)=b(i);
end
%%%画出最后的解调的最后结果并且与输入值即 figure(1)作比较,即可判断这个程序的成功与否;
 figure(11);
 
stairs(enddata,'r');
title('the resumed   single of QPSK ');
    
            
        






⌨️ 快捷键说明

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