如何用MATLAB生成OFDM时域信号波形
全部清除;
全部关闭;
载波计数= 200;子载波数量%
符号每载波= 12;每个子载波的符号数百分比
每符号位数= 4;每符号%位,16QAM调制
IFFT _宾_长度= 512;FFT点数百分比
prefix ratio = 1/4;保护间隔与OFDM数据的百分比是1/6~1/4。
GI = prefix ratio * IFFT _ bin _长度;%添加到每个OFDM符号的循环前缀的长度是1/4*IFFT_bin_length,即保护间隔的长度是128。
beta = 1/32;%窗口函数的滚降系数
GIP = beta *(IFFT _ bin _长度+GI);%循环后缀20的长度
SNR = 15;%信噪比dB
%==================================================
% = = = = = = = = = = = = =信号生成= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
基带输出长度=载波计数*符号每载波*比特每符号;输入的位数百分比
carriers =(1:carrier _ count)+(floor(IFFT _ bin _长度/4)-floor(carrier _ count/2));对应于% * *轭对称副载波映射的复数数据的IFFT点坐标。
共轭_载波= IFFT _ bin _长度-载波+2;% * * *轭对称副载波映射* * *轭复数对应的IFFT点坐标。
rand( 'state ',0);
基带_out=round(rand(1,基带_ out _ length));%输出要调制的二进制比特流
% = = = = = = = = = = = 16 QAM调制= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
复数_载波_矩阵=qam16(基带_输出);%列向量
complex _ carrier _ matrix = reshape(complex _ carrier _ matrix ',carrier_count,symbols _ per _ carrier)';每个载波的符号百分比*载波计数矩阵
图(1);
plot(complex_carrier_matrix,' * r ');%16QAM调制后的星座图
轴([-4,4,-4,4]);
网格打开
% = = = = = = = = = = = = = = = = = IFFT = = = = = = = = = = = = = = = = = = = = = =
IFFT _调制=零(每载波符号,IFFT _ bin _长度);%加0构成IFFT_bin_length IFFT运算。
IFFT _调制(:,载波)=复数_载波_矩阵;%导频信号不加,副载波映射在此。
IFFT _调制(:,共轭_载波)= conj(复数_载波_矩阵);% * * *磁轭复杂映射
%========================================================
图(2);
Stem (0: IFFT _ bin _ length-1,ABS (IFFT _调制(2,1: IFFT _ bin _ length)),' b *-')%第一个OFDM符号的频谱。
网格打开
轴([0 IFFT _ bin _ length-0.5 4.5]);
ylabel('震级');
xlabel(“IFFT·宾”);
标题(“OFDM载波频率幅度”);
图(3);
plot(0:IFFT_bin_length-1,(180/pi)*角度(IFFT _调制(2,1:IFFT_bin_length)),' go ')
继续
stem(0:载波-1,(180/pi)*角度(IFFT _调制(2,1:载波)),' b *-');第一个OFDM符号的%相位
stem(0:共轭_载波-1,(180/pi)*角度(IFFT _调制(2,1:共轭_载波)),' b *-');
坐标轴([0 IFFT _ bin _长度-200 +200])
网格打开
ylabel('相位(度)')
xlabel(“IFFT·宾”)
标题(“OFDM载波相位”)
%=================================================================
信号_ after _ IFFT = IFFT(IFFT _调制,IFFT_bin_length,2);%OFDM调制是IFFT变换。
时间_波_矩阵=信号_后_ after%时域波形矩阵,表示每个载波的符号数,列出了ITTF点,N个子载波映射在其中,每行是一个OFDM符号。
图(4);
支线剧情(3,1,1);
plot(0:IFFT_bin_length-1,时间_波_矩阵(2,));第一个符号的%波形
轴([0,700,-0.2,0.2]);
网格打开;
ylabel('振幅');
xlabel(' Time ');
标题(“OFDM时间信号,一个符号周期”);
%===========================================================
% = = = = = = = = = = = = =添加一个循环前缀和后缀= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
XX =零(符号_每载波,IFFT _ bin _长度+GI+GIP);
对于k=1:每载波符号数;
对于I = 1:IFFT _ bin _ length;
XX(k,i+GI)=signal_after_IFFT(k,I);
结束
对于I = 1:GI;
XX(k,i)=signal_after_IFFT(k,I+IFFT _ bin _ length-GI);%添加循环前缀
结束
对于j = 1:GIP;
XX(k,IFFT _ bin _ length+GI+j)= signal _ after _ IFFT(k,j);%添加循环后缀
结束
结束
time _ wave _ matrix _ cp = XX%具有循环前缀和后缀的时域信号矩阵,并且OFDM符号的长度是IFFT_bin_length+GI+GIP=660。
支线剧情(3,1,2);
plot(0:length(time _ wave _ matrix _ CP)-1,time_wave_matrix_cp(2,);%第一个符号添加了循环前缀的波形
轴([0,700,-0.2,0.2]);
网格打开;
ylabel('振幅');
xlabel(' Time ');
标题(“带CP的OFDM时间信号,一个符号周期”);
% = = = = = = = = = = = = OFDM符号开窗= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
windowed _ time _ wave _ matrix _ CP = zeros(1,IFFT _ bin _ length+GI+GIP);
对于i = 1:每载波符号数
windowed_time_wave_matrix_cp(i,)= real(time_wave_matrix_cp(i,))。*rcoswindow(beta,IFFT _ bin _ length+GI)';%窗口升余弦窗口
结束
支线剧情(3,1,3);
plot(0:IFFT _ bin _ length-1+GI+GIP,加窗_时间_波形_矩阵_cp(2,);第一个符号的%波形
轴([0,700,-0.2,0.2]);
网格打开;
ylabel('振幅');
xlabel(' Time ');
标题(“OFDM时间信号应用一个窗口,一个符号周期”);
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
windowed_Tx_data=zeros(1,symbols _ per _ carrier *(IFFT _ bin _ length+GI)+GIP);
windowed _ Tx _ data(1:IFFT _ bin _ length+GI+GIP)= windowed _ time _ wave _ matrix _ CP(1,);
对于i = 1:符号_每_载波-1;
windowed _ Tx _ data((IFFT _ bin _ length+GI)* I+1:(IFFT _ bin _ length+GI)*(I+1)+GIP)= windowed _ time _ wave _ matrix _ CP(I+1,);%并串转换,循环后缀和循环前缀叠加。
结束
%=======================================================
tx _ data _ without window = shape(time _ wave _ matrix _ CP ',(symbols _ per _ carrier)*(IFFT _ bin _ length+GI+GIP),1)';%串行信号无窗口,仅添加循环前缀和后缀
tx _ data = shape(windowed _ time _ wave _ matrix _ CP ',(symbols _ per _ carrier)*(IFFT _ bin _ length+GI+GIP),1)';%窗口化后不叠加带循环前缀和后缀的串行信号
%=================================================================
temp _ time 1 =(symbols _ per _ carrier)*(IFFT _ bin _ length+GI+GIP);%开窗口后,循环前缀和后缀不重叠发送总位数
图(五)
支线剧情(2,1,1);
plot(0:temp _ time 1-1,Tx _ data);%循环前缀和后缀不与发送的信号波形重叠。
网格打开
ylabel('振幅(伏特)')
xlabel('时间(样本)')
标题(“OFDM时间信号”)
temp _ time 2 = symbols _ per _ carrier *(IFFT _ bin _ length+GI)+GIP;
支线剧情(2,1,2);
plot(0:temp_time2-1,windowed _ Tx _ data);%循环后缀与循环前缀叠加以发送信号波形。
网格打开
ylabel('振幅(伏特)')
xlabel('时间(样本)')
标题(“OFDM时间信号”)
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
symbols _ per _ average = ceil(symbols _ per _ carrier/5);1/5,10行%符号数
avg _ temp _ time =(IFFT _ bin _ length+GI+GIP)* symbols _ per _ average;%点,10行数据,10个符号
平均值= floor(temp _ time 1/avg _ temp _ time);
average _ FFT(1:avg _ temp _ time)= 0;%被分成5个部分
对于a = 0:(平均值-1)
subset _ OFDM = Tx _ data _ without window((a * avg _ temp _ time)+1):((a+1)* avg _ temp _ time);%
subset _ OFDM _ f = ABS(FFT(subset _ OFDM));%将发送信号段频谱。
average _ FFT = average _ FFT+(subset _ OFDM _ f/averages);将总* * *数据的%分成五段,对各段进行FFT,并进行平均相加。
结束
average _ FFT _ log = 20 * log 10(average _ FFT);
图(6)
支线剧情(2,1,1);
plot((0:(avg _ temp _ time-1))/avg _ temp _ time,average _ FFT _ log)%归一化0/avg _ temp _ time:(avg _ temp _ time-1)/avg _ temp _ log。
继续
plot(0:1/IFFT _ bin _ length:1,-35,' rd ')
网格打开
轴([0 0.5 -40最大值(average_fft_log)])
ylabel('幅度(dB)')
xlabel('归一化频率(0.5 = fs/2)')
标题(“无窗口的OFDM信号频谱”)
% = = = = = = = = = = = =加窗发射信号的频谱= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
symbols _ per _ average = ceil(symbols _ per _ carrier/5);1/5,10行%符号数
avg _ temp _ time =(IFFT _ bin _ length+GI+GIP)* symbols _ per _ average;%点,10行数据,10个符号
平均值= floor(temp _ time 1/avg _ temp _ time);
average _ FFT(1:avg _ temp _ time)= 0;%被分成5个部分
对于a = 0:(平均值-1)
subset _ OFDM = Tx _ data((a * avg _ temp _ time)+1):((a+1)* avg _ temp _ time);%使用循环前缀后缀未叠加的串行加窗信号计算频谱。
subset _ OFDM _ f = ABS(FFT(subset _ OFDM));%分段频谱
average _ FFT = average _ FFT+(subset _ OFDM _ f/averages);将总* * *数据的%分成五段,对各段进行FFT,并进行平均相加。
结束
average _ FFT _ log = 20 * log 10(average _ FFT);
支线剧情(2,1,2)
plot((0:(avg _ temp _ time-1))/avg _ temp _ time,average _ FFT _ log)%归一化0/avg _ temp _ time:(avg _ temp _ time-1)/avg _ temp _ log。
继续
plot(0:1/IFFT _ bin _ length:1,-35,' rd ')
网格打开
轴([0 0.5 -40最大值(average_fft_log)])
ylabel('幅度(dB)')
xlabel('归一化频率(0.5 = fs/2)')
标题(“加窗OFDM信号频谱”)
% = = = = = = = = = = = = = = =添加噪点= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Tx _ signal _ power = var(windowed _ Tx _ data);%发射信号功率
linear_snr=10^(snr/10);%线性信噪比
noise _σ= Tx _ signal _ power/linear _ SNR;
噪声_比例_因子= sqrt(噪声_西格玛);标准差百分比西格玛
noise=randn(1,((符号_每载波)*(IFFT _ bin _长度+GI))+GIP)* noise _ scale _ factor;%产生正态分布的噪声序列。
%noise=wgn(1,length(windowed_Tx_data),noise_sigma,'复数');%产生复杂的高斯白噪声信号。
rx _ data = windowed _ Tx _ data+noise;%接收信号加噪声
% = = = = = = = = = = = = = =接收信号字符串/并行变换去除前缀和后缀= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Rx_data_matrix=zeros(符号_每载波,IFFT _ bin _长度+GI+GIP);
对于i=1:每载波符号数;
Rx_data_matrix(i,)=Rx_data(1,(I-1)*(IFFT _ bin _ length+GI)+1:I *(IFFT _ bin _ length+GI)+GIP);%串行-并行转换
结束
Rx _ data _ complex _ matrix = Rx _ data _ matrix(:,GI+1:IFFT _ bin _ length+GI);%去除循环前缀和循环后缀,得到有用的信号矩阵。
%============================================================%================================================================
%==============================================================
% OFDM解码16QAM解码
% = = = = = = = = = = = = = FFT变换= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
y 1 = FFT(Rx _ data _ complex _ matrix,IFFT_bin_length,2);%OFDM解码是FFT变换。
Rx_carriers=Y1(:,carriers);%除由IFFT/FFT变换添加的零,并选择映射的子载波。
Rx _ phase =角度(Rx _ carriers);接收信号的相位百分比
Rx _ mag = ABS(Rx _ carriers);接收信号的%振幅
图(7);
极坐标(Rx_phase,Rx_mag,' BD ');用%极坐标画出接收信号的星座图。
%======================================================================
[M,N]=pol2cart(Rx_phase,Rx _ mag);
Rx_complex_carrier_matrix =复数(M,N);
图(8);
plot(Rx_complex_carrier_matrix,' * r ');%XY坐标下接收信号的星座图
轴([-4,4,-4,4]);
网格打开
% = = = = = = = = = = = = = = = = = 16 QAM解调= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Rx _ serial _ complex _ symbols = reshape(Rx _ complex _ carrier _ matrix ',size(Rx_complex_carrier_matrix,1)* size(Rx _ complex _ carrier _ matrix,2),1)';
Rx _ decoded _ binary _ symbols = demoduqam 16(Rx _ serial _ complex _ symbols);
%============================================================
基带_输入=接收_解码_二进制_符号;
图(9);
支线剧情(2,1,1);
stem(基带_ out(1:100));
支线剧情(2,1,2);
stem(基带_ in(1:100));
% = = = = = = = = = = = = = =错误率计算= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
bit_errors=find(基带_ in ~ =基带_ out);
位错误计数=大小(位错误,2)
ber =比特错误计数/基带输出长度