注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Mr.Right

不顾一切的去想,于是我们有了梦想。脚踏实地的去做,于是梦想成了现实。

 
 
 

日志

 
 
关于我

人生一年又一年,只要每年都有所积累,有所成长,都有那么一次自己认为满意的花开时刻就好。即使一时不顺,也要敞开胸怀。生命的荣枯并不是简单的重复,一时的得失不是成败的尺度。花开不是荣耀,而是一个美丽的结束,花谢也不是耻辱,而是一个低调的开始。

网易考拉推荐

Demonstration of QPSK Modulation and Demodulation  

2012-05-11 21:46:12|  分类: 编程 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

% QPSK的目的是将数字信号调制为模拟信号发送出去,在接收机端将模拟信号解调为数字信号

% Demonstration of QPSK Modulation and Demodulation
%  

Demonstration of QPSK Modulation and Demodulation - 阿英 - Mr.Right
 

clear; %clear all stored variables
N=100; %number of data bits
noiseVariance = 0.1; %Noise variance of AWGN channel
data=randn(1,N)>=0; %Generate uniformly distributed random data
Rb=1e3; %bit rate
amplitude=1; % Amplitude of NRZ data

oddBits = data(1:2:end);
evenBits= data(2:2:end);

[evenTime,evenNrzData,Fs]=NRZ_Encoder(evenBits,Rb,amplitude,'Polar');
[oddTime,oddNrzData]=NRZ_Encoder(oddBits,Rb,amplitude,'Polar');

Fc=2*Rb;  % 载频取比特率的2倍就行
inPhaseOsc = 1/sqrt(2)*cos(2*pi*Fc*evenTime);
quadPhaseOsc = 1/sqrt(2)*sin(2*pi*Fc*oddTime);

qpskModulated = oddNrzData.*quadPhaseOsc + evenNrzData.*inPhaseOsc;

Tb=1/Rb;
subplot(3,2,1);
stem(data);
xlabel('Samples');
ylabel('Amplitude');
title('Input Binary Data');
axis([0,N,-0.5,1.5]);

subplot(3,2,3);
plotHandle=plot(qpskModulated);
xlabel('Samples');
ylabel('Amplitude');
title('QPSK modulated Data');
xlimits = xlim;  
ylimits = ylim;
axis([xlimits,ylimits(1)-0.5,ylimits(2)+0.5]) ;
grid on;

%-------------------------------------------
%Adding Channel Noise
%-------------------------------------------
noise = sqrt(noiseVariance)*randn(1,length(qpskModulated));
received = qpskModulated + noise;
subplot(3,2,5);
plot(received);
xlabel('Time');
ylabel('Amplitude');
title('QPSK Modulated Data with AWGN noise');

%-------------------------------------------
%QPSK Receiver
%-------------------------------------------
%Multiplying the received signal with reference Oscillator
iSignal = received.*inPhaseOsc;  %注意这里的匹配滤波器是如何实现的。inPhaseOsc本身含有多个滑窗,其模拟了滑窗滑动的过程
qSignal = received.*quadPhaseOsc;

%Integrator
integrationBase = 0:1/Fs:Tb-1/Fs;
for i = 0:(length(iSignal)/(Tb*Fs))-1,
    inPhaseComponent(i+1)=trapz(integrationBase,iSignal(int32(i*Tb*Fs+1):int32((i+1)*Tb*Fs))); %我以前不知道可以用积分匹配滤波
end
for i = 0:(length(qSignal)/(Tb*Fs))-1,
    quadraturePhaseComponent(i+1)=trapz(integrationBase,qSignal(int32(i*Tb*Fs+1):int32((i+1)*Tb*Fs)));
end

%Threshold Comparator
estimatedInphaseBits=(inPhaseComponent>=0); % inPhaseComponent本身是个浮点数2.968e-04,-2.0247e-04是其典型值
estimatedQuadphaseBits=(quadraturePhaseComponent>=0);

finalOutput=reshape([estimatedQuadphaseBits;estimatedInphaseBits],1,[]); % 如是将2路信号交替合成1一个行向量
BER = sum(xor(finalOutput,data))/length(data);

subplot(3,2,2);
stem(finalOutput);
xlabel('Samples');
ylabel('Amplitude');
title('Detected Binary Data after QPSK demodulation');
axis([0,N,-0.5,1.5]);

%Constellation Mapping at transmitter and receiver
%constellation Mapper at Transmitter side
subplot(3,2,4);
plot(evenNrzData,oddNrzData,'ro');  % 我以前没有想到这样画星座图
xlabel('Inphase Component');
ylabel('Quadrature Phase component');
title('QPSK Constellation at Transmitter');
axis([-1.5,1.5,-1.5,1.5]);
h=line([0 0],[-1.5 1.5]);
set(h,'Color',[0,0,0])
h=line([-1.5 1.5],[0 0]);
set(h,'Color',[0,0,0])

%constellation Mapper at receiver side
subplot(3,2,6);

%下一行是没有进行门限比较的星座图,可以看出其凌乱
%plot(inPhaseComponent/max(inPhaseComponent),quadraturePhaseComponent/max(quadraturePhaseComponent),'ro');

plot(2*estimatedInphaseBits-1,2*estimatedQuadphaseBits-1,'ro'); %门限比较后的星座图
xlabel('Inphase Component');
ylabel('Quadrature Phase component');
title(['QPSK Constellation at Receiver when AWGN Noise Variance =',num2str(noiseVariance)]);
axis([-1.5,1.5,-1.5,1.5]);
h=line([0 0],[-1.5 1.5]);
set(h,'Color',[0,0,0]);
h=line([-1.5 1.5],[0 0]);
set(h,'Color',[0,0,0]);

 

 

%%%% 用到的函数 %%%%%%%%%%%%%%%%%%%%%%%%

% NRZ_Encoder   Line codes encoder
%   [time,output,Fs]=NRZ_Encoder(input,Rb,amplitude,style)
%   NRZ_Encoder NRZ encoder
%   Input a stream of bits and specify bit-Rate, amplitude of the output signal and the style of encoding
%   Currently 3 encoding styles are supported namely 'Manchester','Unipolar'and 'Polar'
%   Outputs the NRZ stream
function [time,output,Fs]=NRZ_Encoder(input,Rb,amplitude,style)


Fs=10*Rb; %Sampling frequency , oversampling factor= 5,举例也就是原来的一bit,0 变成 10 个 -1
Ts=1/Fs; % Sampling Period
Tb=1/Rb; % Bit period

output=[];
switch lower(style)
    case {'manchester'}
        %disp('Method is ,manchester')
        for count=1:length(input),
            for tempTime=0:Ts:Tb/2-Ts,
                output=[output (-1)^(input(count))*amplitude];
            end       
            for tempTime=Tb/2:Ts:Tb-Ts,
                output=[output (-1)^(input(count)+1)*amplitude];
            end
        end   
    case {'unipolar'}
        %disp('Method is unipolar')
        for count=1:length(input),
            for tempTime=0:Ts:Tb-Ts,
                output=[output input(count)*amplitude];
            end
        end
    case {'polar'}
        %disp('Method is polar')
        for count=1:length(input),
            for tempTime=0:Ts:Tb-Ts,
                output=[output amplitude*(-1)^(1+input(count))];
            end
        end
    otherwise,
        disp('NRZ_Encoder(input,Rb,amplitude,style)-Unknown method given as ''style'' argument');
        disp('Accepted Styles are ''Manchester'', ''Unipolar'' and ''Polar''');
end
time=0:Ts:Tb*length(input)-Ts;

  评论这张
 
阅读(1067)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016