?? qpsk_mod.m
字號(hào):
function [msumiq,sumiq,cs_t,sn_t,tiq]=qpsk_mod(sig1,sig2,Isymbols,Qsymbols,N,fcarr)
%fcarr=20e3; % Carrier frequency(Hz)
%N=2e3; % Number of data bits(bit rate)
fs=8*10e3; % Sampling frequency
Fn=fs/2; % Nyquist frequency
Ts=1/fs; % Sampling time = 1/fs
T=1/N; % Bit time
randn('state',0); % Keeps PRBS from changing on reruns
td=[0:Ts:(N*T)-Ts]';% Time vector(data)(transpose)
tiq = [0:Ts*2:(N*T)-Ts]';% Time vector for I and Q symbols(transpose)
%generate carrier waves
%cosine and sine wave
%2 pi fc t is written as below
twopi_fc_t=(1:fs/2)*2*pi*fcarr/fs;
a=1;
%phi=45*pi/180
phi=0;%phase error
cs_t = a * cos(twopi_fc_t + phi);
sn_t = a * sin(twopi_fc_t + phi);
%Generating spread signal
%cs_t=cs_t'%transpose
%sn_t=sn_t'%transpose
si=cs_t.*sig1;
sq=sn_t.*sig2;
sumiq=si+sq;
sumiq=1*sumiq;%reduce gain to keep output at +/- one
%Generating unspread signal (for comparison purposes)
mi=cs_t.*Isymbols;
mq=sn_t.*Qsymbols;
msumiq=mi+mq;
msumiq=1*msumiq; %reduce gain to keep output at +/- one
%========================================================================
%Take FFT of unmodulated carrier
%========================================================================
y=cs_t;
NFFY=2.^(ceil(log(length(y))/log(2)));
FFTY=fft(y,NFFY);%pad with zeros
NumUniquePts=ceil((NFFY+1)/2);
FFTY=FFTY(1:NumUniquePts);
UY=abs(FFTY);
UY=UY*2;
UY(1)=UY(1)/2;
UY(length(UY))=UY(length(UY))/2;
UY=UY/length(y);
f1=(0:NumUniquePts-1)*2*Fn/NFFY;
%========================================================================
%Take FFT of modulated spread carrier
%========================================================================
y=sumiq;
NFFY=2.^(ceil(log(length(y))/log(2)));
FFTY=fft(y,NFFY);%pad with zeros
NumUniquePts=ceil((NFFY+1)/2);
FFTY=FFTY(1:NumUniquePts);
MY=abs(FFTY);
MY=MY*2;
MY(1)=MY(1)/2;
MY(length(MY))=MY(length(MY))/2;
MY=MY/length(y);
%f1=(0:NumUniquePts-1)*2*Fn/NFFY;
%========================================================================
%Take FFT of modulated unspread carrier
%========================================================================
y=msumiq;
NFFY=2.^(ceil(log(length(y))/log(2)));
FFTY=fft(y,NFFY);%pad with zeros
NumUniquePts=ceil((NFFY+1)/2);
FFTY=FFTY(1:NumUniquePts);
CY=abs(FFTY);
CY=CY*2;
CY(1)=CY(1)/2;
CY(length(CY))=CY(length(CY))/2;
CY=CY/length(y);
%f1=(0:NumUniquePts-1)*2*Fn/NFFY;
%========================================================================
%Plots
%========================================================================
%figure(2)
%plot(tiq,sumiq)
%axis([0 5/N -2 2]);
%grid on
%xlabel(' 時(shí)間')
%ylabel('幅度')
%title('QPSK 輸出波形')
%figure(4)
%subplot(3,1,1)
%plot(f1,CY)
%axis([0 40000 0 .1]);
%grid on
%xlabel(' Time')
%ylabel('Amplitude')
%title('Unspread')
%subplot(3,1,2); plot(f1,MY);xlabel('');ylabel('AMPLITUDE');
%axis([0 40000 0 .1]);%zoom in/out
%title('Frequency domain spread');
%grid on
%subplot(3,1,3)
%plot(f1,UY)
%axis([0 40000 0 .1]);
%grid on
%xlabel(' Time')
%ylabel('Amplitude')
%title('carrier')
%figure(5)
%subplot(3,1,1); plot(f1,20*log10(abs(CY).^2));xlabel('FREQUENCY(Hz)');ylabel('DB');
%axis([0 40000 -80 -20]);%zoom in/out
%grid on
%title('Modulated QPSK unspread signal')
%subplot(3,1,2); plot(f1,20*log10(abs(MY).^2));xlabel('FREQUENCY(Hz)');ylabel('DB');
%axis([0 40000 -80 -20]);%zoom in/out
%grid on
%title('Modulated QPSK spread signal')
%subplot(3,1,3); plot(f1,20*log10(abs(UY).^2));xlabel('FREQUENCY(Hz)');ylabel('DB');
%axis([0 40000 -80 0]);%zoom in/out
%grid on
%title('Carrier')
%figure(6)
%subplot(4,1,1)
%plot(tiq,si)
%axis([0 5/N -2 2]);
%grid on
%xlabel(' Time')
%ylabel('Amplitude')
%title('I channel spread Output Waveform')
%subplot(4,1,2)
%plot(tiq,sq)
%axis([0 5/N -2 2]);
%grid on
%xlabel(' Time')
%ylabel('Amplitude')
%title('Q channel spread Output Waveform')
%subplot(4,1,3)
%plot(tiq,mi)
%axis([0 5/N -2 2]);
%grid on
%xlabel(' Time')
%ylabel('Amplitude')
%title('I channel Output Waveform')
%subplot(4,1,4)
%plot(tiq,mq)
%axis([0 5/N -2 2]);
%grid on
%xlabel(' Time')
%ylabel('Amplitude')
%title('Q channel Output Waveform')
end
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -