📄 ofdm.m
字号:
para=256; % Number of parallel channel to transmit (points)
fftlen=256; % FFT length
noc=256; % Number of carrier
nd=1; % Number of information OFDM symbol for one loop
ml=2; % Modulation level : QPSK
sr=250000; % Symbol rate
br=sr.*ml; % Bit rate per carrier
% gilen=15; % Length of guard interval (points)
fullen=gilen+para; %ofdm符号总长
% ebn0=7; %Eb/N0
snr=10^(ebn0/10);
deltad=0; %时延
deltaf=0; %频偏
%************************** main loop part **************************
%************************** transmitter *********************************
%************************** Data generation ****************************
seldata=rand(1,para*nd*ml)>0.5; % rand : built in function
%****************** Serial to parallel conversion ***********************
paradata=reshape(seldata,para,nd*ml); % reshape : built in function
%************************** QPSK modulation *****************************
[ich,qch]=qpskmod(paradata,para,nd,ml);
kmod=1/sqrt(2); % sqrt : built in function
ich1=ich.*kmod;
qch1=qch.*kmod;
%******************* IFFT ************************
x=ich1+qch1.*i;
y=ifft(x); % ifft : built in function
ich2=real(y); % real : built in function
qch2=imag(y); % imag : built in function
%********* Gurad interval insertion **********
[ich3,qch3]= giins(ich2,qch2,fftlen,gilen,nd);
fftlen2=fftlen+gilen;
%********* Attenuation Calculation *********
spow=sum(ich3.^2+qch3.^2)/nd./para; % sum : built in function
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn);
%*************************** Receiver *****************************
%*************************加频率偏移和时延***************************
[ich3,qch3]=delay(ich3,qch3,length(ich3),deltad);
y=ich3+qch3.*i;
for k=1:length(ich3);
y(k)=y(k)*exp(i*2*pi*deltaf*k/para);
end
ich3=real(y);
qch3=imag(y);
%for k=1:length(ich3);
%y(k)=y(k)*exp(i*2*pi*deltaf*k/para);
%end
%***************** AWGN addition *********
% [ich4,qch4]=comb(ich3,qch3,attn);
ich4 = ich3;
qch4 = qch3;
y=ich4+qch4.*i;
%****************** Guard interval removal *********
[ich5,qch5]= girem(ich4,qch4,fftlen2,gilen,nd);
%****************** FFT ******************
rx=ich5+qch5.*i;
ry=fft(rx); % fft : built in function
ich6=real(ry); % real : built in function
qch6=imag(ry); % imag : built in function
%***************** demoduration *******************
ich7=ich6./kmod;
qch7=qch6./kmod;
figure(1);
plot(ich7(:,1),qch7(:,1),'*');grid on;
[demodata]=qpskdemod(ich7,qch7,para,nd,ml);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -