function [f,P]=qpskPSD(SubCarrier)
IFFT_n=2*SubCarrier;%IFFT点数
Symbol_n=10;%每个子载波含有的OFDM符号数
Symbol_bit=2;%每个符号占比特数(QPSK调制)
SymbolCount=SubCarrier*Symbol_n*Symbol_bit;%输入的总符号数
%产生随机输入====================
InputData=rand(1,SymbolCount)>0.5;
%串并变换====================
ParaData=zeros(SubCarrier,Symbol_n*Symbol_bit);%存放并行数据
for i=1:SymbolCount
ParaData(mod(i-1,SubCarrier)+1,fix((i-1)/SubCarrier)+1)=InputData(i);
end
%星座映射====================
%QPSK
%分成I,Q两路码元
I_Data=zeros(SubCarrier,Symbol_n);%存放I路数据
Q_Data=zeros(SubCarrier,Symbol_n);%存放Q路数据
for i=1:SubCarrier
for j=1:Symbol_n
I_Data(i,j)=ParaData(i,j*2-1);
Q_Data(i,j)=ParaData(i,j*2);
end
end
%QPSK相乘电路
%双极性不归零波形:1对应1,0对应-1
for i=1:SubCarrier
for j=1:Symbol_n
if I_Data(i,j)==0
I_Data(i,j)=-1;
end
if Q_Data(i,j)==0
Q_Data(i,j)=-1;
end
end
end
%幅度变为1/sqrt(2)
I_Data=I_Data./sqrt(2);
Q_Data=Q_Data./sqrt(2);
%Q路信号转成复数
Q_Data=Q_Data.*sqrt(-1);
%QPSK相加电路
QPSK_Signal=zeros(SubCarrier,Symbol_n);%存放QPSK调制后各路信号
for i=1:SubCarrier
for j=1:Symbol_n
QPSK_Signal(i,j)=I_Data(i,j)+Q_Data(i,j);
end
end
%IFFT====================
QPSK_Signal1=[QPSK_Signal(1:SubCarrier/2,:);zeros(IFFT_n-SubCarrier,Symbol_n);QPSK_Signal(SubCarrier/2+1:SubCarrier,:)];
x=ifft(QPSK_Signal1*sqrt(IFFT_n),IFFT_n);
%并串变换====================
x1=reshape(x,1,IFFT_n*Symbol_n);
%频谱
nfft=1024; %2^n
X=fftshift(fft(x,nfft));
Pxx=abs(X).^2/max(abs(X).^2); %求解PSD
t=0:nfft-1;
f=t/nfft;
P=10*log10(Pxx(t+1)); %纵坐标的单位为dB
plot(f,P);
axis([0 1 -40 0])
grid on
|