matlab这是OFDM的时域和频域的子载波图形
% ofdm spectrum plot
clear all;
close all;
clc;
modulateNum_Sc = 12; % 13 subcarriers
Ts = 1; % 1s
F_space = 1/Ts;
F = -F_space*Num_Sc/2-4:0.001:F_space*Num_Sc/2+4;
F_spectrum = zeros(Num_Sc,length(F));
for i = -Num_Sc/2:1:Num_Sc/2
F_spectrum(i+Num_Sc/2+1,1:end) = sin(2*pi*(F-i*F_space).*Ts/2)./(2*pi*(F-i*F_space).*Ts/2);
end
plot(F,F_spectrum)
grid on
% ofdm subcarrier plot
clear all;
close all;
clc;
N = 256;
M = 6;
N_symbol = 1;
% s_data = [-3-sqrt(-1)*3 -3-sqrt(-1) -3-sqrt(1) -3-sqrt(-1)*3]/sqrt(10);
s_data = (1+sqrt(-1))/sqrt(2);
tx_data = repmat(s_data,1,N); % some initial phase
% Original_bin = randint(2,N*N_symbol,2,222);
% Modobj = modem.qammod('M',4,'SymbolOrder','Gray','InputType','Bit');
% tx_data = modulate(Modobj,Original_bin)/sqrt(10);
for j = 0:1:N_symbol-1
for k =0:1:N-1
for n = 0:1:N-1
x_tmp(k+1,n+1+j*N) = tx_data(k+1+j*N)*exp(sqrt(-1)*2*pi*k*n/N);
end
end
end
% plot four-subcarrier
figure(1)
plot(real(x_tmp(1:4,1:end).'))
clear;
clc;
clc;
SNR=10; % 信噪比
fl=128; % 设置FFT长度
Ns=6; %设置一个祯结构中OFDM信号的个数
para=128;%设置并行传输的子载波个数
sr=250000; %符号速率
br=sr.*2;% 每个子载波的比特率
gl=32 %保护时隙的长度
Signal=rand(1,para*Ns*2)>0.5;%产生0,1 随即序列,符号数为para*Ns*2
for i=1:para
for j=1:Ns*2
SigPara(i,j)=Signal(i*j);%串并变换
end
end
%QPSK调制,将数据分为两个通道
fl=128; % 设置FFT长度
Ns=6; %设置一个祯结构中OFDM信号的个数
para=128;%设置并行传输的子载波个数
sr=250000; %符号速率
br=sr.*2;% 每个子载波的比特率
gl=32 %保护时隙的长度
Signal=rand(1,para*Ns*2)>0.5;%产生0,1 随即序列,符号数为para*Ns*2
for i=1:para
for j=1:Ns*2
SigPara(i,j)=Signal(i*j);%串并变换
end
end
%QPSK调制,将数据分为两个通道
for j=1:Ns
ich(:,j)=SigPara(:,2*j-1);
qch(:,j)=SigPara(:,2*j);
end
kmod=1./sqrt(2);
ich1=ich.*kmod;
qch1=qch.*kmod;
x=ich1+qch1.*sqrt(-1); %频域数据变时域
y=ifft(x);
ich2=real(y);
qch2=imag(y);
%插入保护间隔
ich3=[ich2(fl-gl+1:fl,:);ich2];
qch3=[qch2(fl-gl+1:fl,:);qch2];
%并串变换
ich(:,j)=SigPara(:,2*j-1);
qch(:,j)=SigPara(:,2*j);
end
kmod=1./sqrt(2);
ich1=ich.*kmod;
qch1=qch.*kmod;
x=ich1+qch1.*sqrt(-1); %频域数据变时域
y=ifft(x);
ich2=real(y);
qch2=imag(y);
%插入保护间隔
ich3=[ich2(fl-gl+1:fl,:);ich2];
qch3=[qch2(fl-gl+1:fl,:);qch2];
%并串变换
ich4=reshape(ich3,1,(fl+gl)*Ns);
qch4=reshape(qch3,1,(fl+gl)*Ns);
%形成复数发射数据
TrData=ich4+qch4.*sqrt(-1);
%接收机
%加入高斯白噪声
ReData=awgn(TrData,SNR,'measured');
%接收端
%移去保护间隔
idata=real(ReData);
qdata=imag(ReData);
idata1=reshape(idata,fl+gl,Ns);
qdata1=reshape(qdata,fl+gl,Ns);
idata2=idata1(gl+1:gl+fl,:);
qdata2=qdata1(gl+1:gl+fl,:);
qch4=reshape(qch3,1,(fl+gl)*Ns);
%形成复数发射数据
TrData=ich4+qch4.*sqrt(-1);
%接收机
%加入高斯白噪声
ReData=awgn(TrData,SNR,'measured');
%接收端
%移去保护间隔
idata=real(ReData);
qdata=imag(ReData);
idata1=reshape(idata,fl+gl,Ns);
qdata1=reshape(qdata,fl+gl,Ns);
idata2=idata1(gl+1:gl+fl,:);
qdata2=qdata1(gl+1:gl+fl,:);
%FFT
Rex=idata2+qdata2*sqrt(-1);
ry=fft(Rex);
ReIChan=real(ry);
ReQChan=imag(ry);
ReIchan=ReIChan/kmod;
ReQchan=ReQChan/kmod;
%QPSK逆映射
for j=1:Ns
RePara(:,2*j-1)=ReIChan(:,j);
RePara(:,2*j)=ReQChan(:,j);
end
ReSig=reshape(RePara,1,para*Ns*2);
%符号抽样判决
ReSig=ReSig>0.5;
Rex=idata2+qdata2*sqrt(-1);
ry=fft(Rex);
ReIChan=real(ry);
ReQChan=imag(ry);
ReIchan=ReIChan/kmod;
ReQchan=ReQChan/kmod;
%QPSK逆映射
for j=1:Ns
RePara(:,2*j-1)=ReIChan(:,j);
RePara(:,2*j)=ReQChan(:,j);
end
ReSig=reshape(RePara,1,para*Ns*2);
%符号抽样判决
ReSig=ReSig>0.5;
figure(1);
subplot(2,1,1),stem(ReSig(1:20)),grid minor;
title('resignal');
xlabel('x'),ylabel('y');
subplot(2,1,2),stem(Signal(1:20)),grid;
title('signal');
这是一个最基本的OFDM系统仿真,可以与OFDM系统框图对照理解,希望能帮到你。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论