资源简介

QPSK方式的MATLAB仿真程序 包括信号的调制解调等

资源截图

代码片段和文件信息

% MATLAB script for System Simulation Homework #2

clear;
clc;

% Carrier frequency for modulation and
% demodulation
Fc =5e6;
%  
% QPSK transmitter 

data_len=5000;%  Input binary data of 5MHz
input=randint(1data_len);

%Series to Parallel
for i=1:data_len
    if rem(i2)==1       %the remainder of i/2
       if input(i)==1
          I(i)=1;
          I(i+1)=1;
       else
          I(i)=-1;
          I(i+1)=-1;
       end
    else
       if input(i)==1
          Q(i-1)=1;
          Q(i)=1;
       else
          Q(i-1)=-1;
          Q(i)=-1;
       end
    end
end
% Zero insertion
zero=5;    % Sampling rate is 25MHz
for i=1:zero*data_len
    if rem(izero)==1
       Izero(i)=I(fix((i-1)/zero)+1);
       Qzero(i)=Q(fix((i-1)/zero)+1);
    else
       Izero(i)=0;
       Qzero(i)=0;
    end
end

%Pulse shaping filter
NT =50;
N=2*zero*NT;
Fs=25e6;
rf=0.1;
psf=rcosfir(rfNTzeroFs‘sqrt‘);

Ipulse= conv(Izeropsf);
Qpulse= conv(Qzeropsf);

%Modulation
for i=1:zero*data_len+N
    t(i)=(i-1)/(Fc*zero);
    Imod(i)=Ipulse(i).*sqrt(2)*cos(2*pi*Fc*t(i));
    Qmod(i)=Qpulse(i).*(-sqrt(2)*sin(2*pi*Fc*t(i)));
end
sum=Imod+Qmod;
%
% QPSK Receiver
%
% Demodulation
for i=1:zero*data_len+N
    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

% Matched filter
mtf= rcosfir(rfNT zeroFs‘sqrt‘);
Imat = conv(Idemmtf);
Qmat = conv(Qdemmtf);

% Data selection
for i=1:zero*data_len
    Isel(i)=Imat(i+N);
    Qsel(i)=Qmat(i+N);
end
% Sampler
for i = 1:data_len
    Isam(i)= Isel((i-1)*zero+1);
    Qsam(i)= Qsel((i-1)*zero+1);
end

%  Decision threshold
threshold = 0.5;         %how to determine
for i = 1:data_len
    if Isam(i)>= threshold
       Ifinal(i)= 1;
    else
       Ifinal(i)= -1;
    end
    if Qsam(i) >= threshold
       Qfinal(i) = 1;
    else
       Qfinal(i)= -1;
    end
end

%  Parallel to Series
for i = 1:data_len
    if rem(i 2)== 1
       if Ifinal(i)== 1
          final(i)=1;
       else
          final(i)= 0;
       end
    else
       if Qfinal(i) == 1
          final(i)= 1;
       else
          final(i)= 0;
       end
    end
end

figure(1)
plot(20*log(abs(fft(input))))
axis([0 data_len -40 100])
grid
title(‘Spectrum of Input binary data‘)

figure(2)
subplot(221)
plot(20*log(abs(fft(I))))
axis([0 data_len -40 140])
grid
title(‘Spectrum of I-channel data‘)

subplot(222)
plot(20*log(abs(fft(Q))))
axis([0 data_len -40 140])
grid
title(‘Spectrum of Q-channel da

评论

共有 条评论