📄 qpsk.txt
字号:
numbits
bits=rand(1,numbits)>0.5;
nb=length(bits);%number of bits
ns=ceil(nb/2);%number of symbols
b0=zeros(1,ns*2);%zero padding
b0(1:nb)=bits;
j=sqrt(-1);
for s=1:ns
ba=b0(((s-1)*2)+1);%分别取数据流第1个
bb=b0(((s-1)*2)+2);%分别取数据流第2个
k=bb+ba*2;
p=((pi/4)*(2*k-1))-pi ;%相位
Sc(s)=cos(p);%同相成分
Ss(s)=sin(p);%正交相成分
S(s)=Sc(s)+j*Ss(s);%合成
end
fp=1e9;%central frequency
fc=50e9;%sampling frequency
T0=242.4e-9;%information lenght
TP=60.6e-9;%cyclic prefix
TG=70.1e-9;%total guard time
A=1;%amplitude of the rectangular impulse
%response
N=128; %number of carriers of the OFDM system
%------------
% Step One OFDM modulator
%------------
tc=T0/N;%chip time
ntcp=floor(TP/tc);%number of tones of the cyclis prefix
n=(-ntcp+1:1:N);%tone counter
NT=length(n);%total number of tones per symbor
nb=ceil(length(S)/N);%number of OFDM blocks to be transmitted
S0=zeros(1,nb*N);%zero padding
S0(1:length(S))=S;
dt=1/fc;%sampling period
if ntcp>0 % coming into the data area
tc=(T0+TP)/NT;%tone duration
%NT=length(n);%total number of tones per symbor
%n=(-ntcp+1:1:N);%tone counter
end
tonesamples=floor(tc/dt);%samples per tone
toneres=floor((TG-TP)/dt);%samples for the residual part
symsamp=(tonesamples*NT)+toneres;
%number of samples representing one OFDM symbol
totsamp=symsamp*nb;
%number of samples representing the transmitted signal
X=[zeros(1,totsamp)'];
for b=1:nb
c=S0((1+(b-1)*N):(N+(b-1)*N));%blick extraction
%Serial to paralllel conversion and zero padding
A=length(c);
a1=floor(A/2);
a2=A-a1;
FS=2*A;
Czp=zeros(FS,1);
Czp(1:a1)=[c(1:a1).'];
Czp(FS-a2+1:FS)=[c(A-a2+1:A).'];
C=ifft(Czp);%ifft of the zero-padded input
if ntcp>0%insertion of the cyclic prefix
C1=zeros(length(C)+2*ntcp,1);
C1(1:(2*ntcp))=C(2*N+1-(2*ntcp):2*N);
C1(2*ntcp+1:length(C1))=C;
else
C1=C;
end
%
zp=floor(tonesamples/2);
C2=[C1.';zeros((zp-1),length(C1))];
C3=C2(:);
g=ones(1,zp);
C4=conv(g,C3);
C4=C4(1:(zp*NT*2));
ics=1+(b-1)*symsamp+toneres;
X(ics:ics+length(C4)-1)=C4;
end%for b=1:nb
XM=X';%Parallel to Serial conversion
XM=XM(1:totsamp);
I=real(XM);
Q=imag(XM);
%carrier modulation
time=linspace(0,totsamp*dt,length(I));
SI=I.*(cos((2*pi*fp).*time));
SQ=Q.*(sin((2*pi*fp).*time));
stx=SI-SQ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -