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

📄 qpsk_sim1.m

📁 完成了QPSK的调制解调的仿真
💻 M
字号:
%QPSK_Sim1.m:this is a ideal system without channel impairments
%20080908

clear all
close all
clc
clf

%TRANSMITTER
%生成基带信号序列。
N=500;
dsource=[ ];
for k=1:2*N;
temp=rand;
if(temp<0.5)
dsource(k)=0;
else
dsource(k)=1;
end;
end;
x=dsource;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
S=[];
si=[];
sq=[];
temp=0;
%符号映射

for k=1:2:2*N
    X=x(k)*2+x(k+1);
    %temp=mod(temp+X,4);
    temp=X;
   
        switch temp
        %当输入码元为00时,可得:
        case 0
            I=1;
            Q=1;
                            
        %即可以得到码元为00时所得波形s。
        %然后再是输入码元为01时,可得:
        case 1
            I=-1;
            Q=1;
        %即可得到码元为01时的所得波形s。
        %当输入码元为10时,可得:
        case 2
            I=-1;
            Q=-1;
        %即可得到码元为10时的所得波形s。
        %当输入码元为11时,可得:
        case 3
           I=1;
           Q=-1;
         %即可得到码元为11时的所得波形s。
        end 
         %
         S=[S I+i*Q];     
           si=[si I];
           sq=[sq Q];           
end
% 对输入序列进行过采样
fc=10000; % carrier frequency
M=25000;% M must be greater than 2*fc

Fs=M;
Fd=2500;%码元速率
Rate=Fs/Fd;
%Rate=16;
%Fd=Fs/Rate;
Tc=Rate/M;
N_Filter=8;
R=0.02;
siup=zeros(1,N*Rate);
siup(1:Rate:end)=si;
squp=zeros(1,N*Rate);
squp(1:Rate:end)=sq;
NUM=rcosfir(R,N_Filter,Rate,Tc,'sqrt');
%[NUM, DEN] = RCOSINE(Fd, Fs, 'sqrt',R) ;
p=NUM;
siup=filter(p,1,siup);            % convolve pulse shape with data
squp=filter(p,1,squp);
t=1/M:1/M:length(siup)/M;              % T/M-spaced time vector
figure(1)         % baseband signal spectrum
subplot(2,1,1), plot(t,siup,'-')  ,grid on                % plot the waveform
xlabel('seconds'); ylabel('amplitude')     % label the axes
title('siup');
subplot(2,1,2), plot(t,squp)         % plot magnitude spectrum
xlabel('seconds'); ylabel('magnitude') 
title('squp');
grid on
% am modulation

t_offset=0;
phase_offset=pi/3;
c=cos(2*pi*fc*(t+t_offset)+phase_offset); % carrier
s=sin(2*pi*fc*(t+t_offset)+phase_offset); % carrier
r=c.*siup-s.*squp;                             % modulate message with carrier
%plot the signal
figure(2)
N2=length(r);
Ts=1/M;                                      
ssf=(-N2/2:N2/2-1)/(Ts*N2);                   % frequency vector
fx=fft(r(1:N2));                            % do DFT/FFT
fxs=fftshift(fx);                          % shift it for plotting
subplot(2,1,1), plot(t,r),grid on               % plot the waveform
xlabel('seconds'); ylabel('amplitude')     % label the axes
subplot(2,1,2), plot(ssf,abs(fxs))         % plot magnitude spectrum
xlabel('frequency'); ylabel('magnitude') 
grid on



%RECEIVER

c=cos(2*pi*fc*t); % Lo
s=sin(2*pi*fc*t); % Lo
zi=r.*c*2;                            % demod received signal
zq=-r.*s*2;                            % demod received signal
fl=50;                               % LPF length
zi=filter(p,1,zi);            % convolve pulse shape with data
zq=filter(p,1,zq);


figure(3)  % soft decisions
subplot(2,1,1), plot(t,zi),grid on;
subplot(2,1,2), plot(t,zq),grid on;
figure(4)
plot(si,sq,'*')
axis([-1.5 1.5 -1.5 1.5])
grid on
figure(5)
plot(zi,zq)
grid on

⌨️ 快捷键说明

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