基于matlab实现OFDM的编码

合集下载

(完整版)OFDMmatlab实现

(完整版)OFDMmatlab实现

close all;carrier_count=200;%子载波数symbols_per_carrier=12;%每子载波含符号数bits_per_symbol=4;%每符号含比特数,16QAM调制IFFT_bin_length=512;%FFT点数PrefixRatio=1/4;%保护间隔与OFDM数据的比例1/6~1/4GI=PrefixRatio*IFFT_bin_length ;%每一个OFDM符号添加的循环前缀长度为1/4*IFFT_bin_length 即保护间隔长度为128beta=1/32;%窗函数滚降系数GIP=beta*(IFFT_bin_length+GI);%循环后缀的长度20SNR=15; %信噪比dB%==================================================%================信号产生=================================== baseband_out_length = carrier_count * symbols_per_carrier * bits_per_symbol;%所输入的比特数目carriers = (1:carrier_count) + (floor(IFFT_bin_length/4) - floor(carrier_count/2));%共轭对称子载波映射复数数据对应的IFFT点坐标conjugate_carriers = IFFT_bin_length - carriers + 2;%共轭对称子载波映射共轭复数对应的IFFT点坐标rand( 'state',0);baseband_out=round(rand(1,baseband_out_length));%输出待调制的二进制比特流%==============16QAM调制====================================complex_carrier_matrix=qam16(baseband_out);%列向量complex_carrier_matrix=reshape(complex_carrier_matrix',carrier_count,symbols_per_car rier)';%symbols_per_carrier*carrier_count 矩阵figure(1);plot(complex_carrier_matrix,'*r');%16QAM调制后星座图axis([-4, 4, -4, 4]);grid on%=================IFFT===========================IFFT_modulation=zeros(symbols_per_carrier,IFFT_bin_length);%添0组成IFFT_bin_length IFFT 运算IFFT_modulation(:,carriers ) = complex_carrier_matrix ;%未添加导频信号,子载波映射在此处IFFT_modulation(:,conjugate_carriers ) = conj(complex_carrier_matrix);%共轭复数映射%========================================================stem(0:IFFT_bin_length-1, abs(IFFT_modulation(2,1:IFFT_bin_length)),'b*-')%第一个OFDM符号的频谱grid onaxis ([0 IFFT_bin_length -0.5 4.5]);ylabel('Magnitude');xlabel('IFFT Bin');title('OFDM Carrier Frequency Magnitude');figure(3);plot(0:IFFT_bin_length-1, (180/pi)*angle(IFFT_modulation(2,1:IFFT_bin_length)), 'go') hold onstem(0:carriers-1, (180/pi)*angle(IFFT_modulation(2,1:carriers)),'b*-');%第一个OFDM符号的相位stem(0:conjugate_carriers-1,(180/pi)*angle(IFFT_modulation(2,1:conjugate_carriers)),'b*-');axis ([0 IFFT_bin_length -200 +200])grid onylabel('Phase (degrees)')xlabel('IFFT Bin')title('OFDM Carrier Phase')%================================================================= signal_after_IFFT=ifft(IFFT_modulation,IFFT_bin_length,2);%OFDM调制即IFFT变换time_wave_matrix =signal_after_IFFT;%时域波形矩阵,行为每载波所含符号数,列ITTF 点数,N个子载波映射在其内,每一行即为一个OFDM符号figure(4);subplot(3,1,1);plot(0:IFFT_bin_length-1,time_wave_matrix(2,:));%第一个符号的波形axis([0, 700, -0.2, 0.2]);grid on;ylabel('Amplitude');xlabel('Time');title('OFDM Time Signal, One Symbol Period');%===========================================================%=====================添加循环前缀与后缀====================================XX=zeros(symbols_per_carrier,IFFT_bin_length+GI+GIP);for k=1:symbols_per_carrier;for i=1:IFFT_bin_length;XX(k,i+GI)=signal_after_IFFT(k,i);endfor i=1:GI;XX(k,i)=signal_after_IFFT(k,i+IFFT_bin_length-GI);%添加循环前缀endfor j=1:GIP;XX(k,IFFT_bin_length+GI+j)=signal_after_IFFT(k,j);%添加循环后缀endendtime_wave_matrix_cp=XX;%添加了循环前缀与后缀的时域信号矩阵,此时一个OFDM符号长度为IFFT_bin_length+GI+GIP=660subplot(3,1,2);plot(0:length(time_wave_matrix_cp)-1,time_wave_matrix_cp(2,:));%第一个符号添加循环前缀后的波形axis([0, 700, -0.2, 0.2]);grid on;ylabel('Amplitude');xlabel('Time');title('OFDM Time Signal with CP, One Symbol Period');%==============OFDM符号加窗==========================================windowed_time_wave_matrix_cp=zeros(1,IFFT_bin_length+GI+GIP);for i = 1:symbols_per_carrierwindowed_time_wave_matrix_cp(i,:) =real(time_wave_matrix_cp(i,:)).*rcoswindow(beta,IFFT_bin_length+GI)';%加窗升余弦窗endsubplot(3,1,3);plot(0:IFFT_bin_length-1+GI+GIP,windowed_time_wave_matrix_cp(2,:));%第一个符号的波形axis([0, 700, -0.2, 0.2]);grid on;ylabel('Amplitude');xlabel('Time');title('OFDM Time Signal Apply a Window , One Symbol Period');%========================生成发送信号,并串变换==================================================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,:); for i = 1:symbols_per_carrier-1 ;windowed_Tx_data((IFFT_bin_length+GI)*i+1:(IFFT_bin_length+GI)*(i+1)+GIP)=window ed_time_wave_matrix_cp(i+1,:);%并串转换,循环后缀与循环前缀相叠加end%=======================================================Tx_data_withoutwindow=reshape(time_wave_matrix_cp',(symbols_per_carrier)*(IFFT_bin_length+GI+GIP),1)';%没有加窗,只添加循环前缀与后缀的串行信号Tx_data=reshape(windowed_time_wave_matrix_cp',(symbols_per_carrier)*(IFFT_bin_length+GI +GIP),1)';%加窗后循环前缀与后缀不叠加的串行信号%================================================================= temp_time1 = (symbols_per_carrier)*(IFFT_bin_length+GI+GIP);%加窗后循环前缀与后缀不叠加发送总位数figure (5)subplot(2,1,1);plot(0:temp_time1-1,Tx_data );%循环前缀与后缀不叠加发送的信号波形grid onylabel('Amplitude (volts)')xlabel('Time (samples)')title('OFDM Time Signal')temp_time2 =symbols_per_carrier*(IFFT_bin_length+GI)+GIP;subplot(2,1,2);plot(0:temp_time2-1,windowed_Tx_data);%循环后缀与循环前缀相叠加发送信号波形grid onylabel('Amplitude (volts)')xlabel('Time (samples)')title('OFDM Time Signal')%=================未加窗发送信号频谱==================================symbols_per_average = ceil(symbols_per_carrier/5);%符号数的1/5,10行avg_temp_time = (IFFT_bin_length+GI+GIP)*symbols_per_average;%点数,10行数据,10个符号averages = floor(temp_time1/avg_temp_time);average_fft(1:avg_temp_time) = 0;%分成5段for a = 0:(averages-1)subset_ofdm = Tx_data_withoutwindow(((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);%总共的数据分为5段,分段进行FFT,平均相加endaverage_fft_log = 20*log10(average_fft);figure (6)subplot(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_timehold onplot(0:1/IFFT_bin_length:1, -35, 'rd')grid onaxis([0 0.5 -40 max(average_fft_log)])ylabel('Magnitude (dB)')xlabel('Normalized Frequency (0.5 = fs/2)')title('OFDM Signal Spectrum without windowing')%===============加窗的发送信号频谱================================= symbols_per_average = ceil(symbols_per_carrier/5);%符号数的1/5,10行avg_temp_time = (IFFT_bin_length+GI+GIP)*symbols_per_average;%点数,10行数据,10个符号averages = floor(temp_time1/avg_temp_time);average_fft(1:avg_temp_time) = 0;%分成5段for a = 0:(averages-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);%总共的数据分为5段,分段进行FFT,平均相加endaverage_fft_log = 20*log10(average_fft);subplot(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_timehold onplot(0:1/IFFT_bin_length:1, -35, 'rd')grid onaxis([0 0.5 -40 max(average_fft_log)])ylabel('Magnitude (dB)')xlabel('Normalized Frequency (0.5 = fs/2)')title('Windowed OFDM Signal Spectrum')%====================添加噪声============================================Tx_signal_power = var(windowed_Tx_data);%发送信号功率linear_SNR=10^(SNR/10);%线性信噪比noise_sigma=Tx_signal_power/linear_SNR;noise_scale_factor = sqrt(noise_sigma);%标准差sigmanoise=randn(1,((symbols_per_carrier)*(IFFT_bin_length+GI))+GIP)*noise_scale_factor; %产生正态分布噪声序列%noise=wgn(1,length(windowed_Tx_data),noise_sigma,'complex');%产生复GAUSS白噪声信号Rx_data=windowed_Tx_data +noise;%接收到的信号加噪声%=====================接收信号串/并变换去除前缀与后缀==========================================Rx_data_matrix=zeros(symbols_per_carrier,IFFT_bin_length+GI+GIP);for i=1:symbols_per_carrier;Rx_data_matrix(i,:)=Rx_data(1,(i-1)*(IFFT_bin_length+GI)+1:i*(IFFT_bin_length+GI)+GI P);%串并变换endRx_data_complex_matrix=Rx_data_matrix(:,GI+1:IFFT_bin_length+GI);%去除循环前缀与循环后缀,得到有用信号矩阵%============================================================%==== ============================================================%==============================================================% OFDM解码16QAM解码%=================FFT变换=================================Y1=fft(Rx_data_complex_matrix,IFFT_bin_length,2);%OFDM解码即FFT变换Rx_carriers=Y1(:,carriers);%除去IFFT/FFT变换添加的0,选出映射的子载波Rx_phase =angle(Rx_carriers);%接收信号的相位Rx_mag = abs(Rx_carriers);%接收信号的幅度figure(7);polar(Rx_phase, Rx_mag,'bd');%极坐标坐标下画出接收信号的星座图%================================================================== ====[M, N]=pol2cart(Rx_phase, Rx_mag);Rx_complex_carrier_matrix = complex(M, N);figure(8);plot(Rx_complex_carrier_matrix,'*r');%XY坐标接收信号的星座图axis([-4, 4, -4, 4]);grid on%====================16qam解调==================================================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=demoduqam16(Rx_serial_complex_symbols);%============================================================ baseband_in = Rx_decoded_binary_symbols;figure(9);subplot(2,1,1);stem(baseband_out(1:100));subplot(2,1,2);stem(baseband_in(1:100));%================误码率计算=============================================bit_errors=find(baseband_in ~=baseband_out);bit_error_count = size(bit_errors, 2)ber=bit_error_count/baseband_out_length。

MATLAB OFDM卷积编码程序及代码

MATLAB OFDM卷积编码程序及代码

%bin22deci.mfunction y=bin22deci(x)%将二进制数转化为十进制数t=size(x,2);y=(t-1:-1:0);y=2.^y;y=x*y';%************************end of file***********************************%comb.m%AWGN加噪声程序function[iout,qout]=comb(idata,qdata,attn)%******************variables*************************%idata:输入I信道数据%qdata:输入Q信道数据%iout输出I信道数据%qout输出Q信道数据%attn:由信噪比导致的衰减系数%******************************************************iout=randn(1,length(idata)).*attn;qout=randn(1,length(qdata)).*attn;iout=iout+idata(1:length(idata));qout=qout+qdata(1:length(qdata));%************************end of file***********************************%crdemapping.m%数据逆映射载波程序function[iout,qout]=crdemapping(idata,qdata,fftlen,nd);%******************variables*************************%idata:输入I信道的数据%qdata:输入Q信道的数据%iout:输出I信道的数据%qout:输出Q信道的数据%fftlen:FFT的长度%nd:OFDM符号数%*****************************************************iout(1:26,:)=idata(2:27,:);qout(1:26,:)=qdata(2:27,:);iout(27:52,:)=idata(39:64,:);qout(27:52,:)=qdata(39:64,:);%********************end of file***************************%crmapping.m%数据映射载波程序function[iout,qout]=crmapping(idata,qdata,fftlen,nd);%******************variables*************************%idata:输入I信道的数据%qdata:输入Q信道的数据%iout:输出I信道的数据%qout:输出Q信道的数据%fftlen:FFT的长度%nd:OFDM符号数%*****************************************************iout=zeros(fftlen,nd);qout=zeros(fftlen,nd);iout(2:27,:)=idata(1:26,:);qout(2:27,:)=qdata(1:26,:);iout(39:64,:)=idata(27:52,:);qout(39:64,:)=qdata(27:52,:);%********************end of file***************************%deci22bin.mfunction y=deci22bin(x,t)%十进制数x转化为二进制数,二进制数至少表示为t位y=zeros(size(x,1),t);for j=1:size(x,1)i=1;while x(j)>=0&i<=ty(j,i)=rem(x(j),2);%x(j)为偶数时,y(j,i)为0;反之为1x(j)=(x(j)-y(j,i))/2;i=i+1;endy(j,:)=y(j,t:-1:1);%倒序排列end%************************end of file***********************************%giins1.m%插入保护间隔程序function[iout,qout]=giins1(idata,qdata,fftlen,gilen,nd);%******************变量*************************%idata:输入I信道数据%qdata:输入Q信道数据%iout:输出I信道数据%qout:输出Q信道数据%fftlen:FFT长度(points)%gilen:保护间隔长度(points)%*****************************************************idata1=reshape(idata,fftlen,nd);qdata1=reshape(qdata,fftlen,nd);idata2=[idata1(fftlen-gilen+1:fftlen,:);idata1];qdata2=[qdata1(fftlen-gilen+1:fftlen,:);qdata1];iout=reshape(idata2,1,(fftlen+gilen)*nd);qout=reshape(qdata2,1,(fftlen+gilen)*nd);%********************end of file***************************%qpskdemod1.m%QPSK解调程序function[demodata]=qpskdemod1(idata,qdata,para,nd,ml)%******************variables*************************%idata:输入I信道数据%qdata:数据Q信道数据%demodata:解调后数据(para-by-nd matrix)%para:并行信道数%nd:符号数%ml:调制数%(QPSK->2 16QAM->4)%*****************************************************demodata=zeros(para,ml*nd);demodata((1:para),(1:ml:ml*nd-1))=idata((1:para),(1:nd))>=0; demodata((1:para),(2:ml:ml*nd))=qdata((1:para),(1:nd))>=0;%************************end of file***********************************%qpskmod1.m%QPSK调制程序function[iout,qout]=qpskmod1(paradata,para,nd,ml)%******************variables*************************%paradata:输入数据%iout:输出数据I%qout:输出数据Q%para:并行信道数%nd:数据数%ml:调制数%(QPSK->2 16QAM->4)%*****************************************************m2=ml./2;paradata2=paradata.*2-1;count2=0;for jj=1:ndisi=zeros(para,1);isq=zeros(para,1);isi=isi+paradata2((1:para),1+count2);isq=isq+paradata2((1:para),2+count2);iout((1:para),jj)=isi;qout((1:para),jj)=isq;count2=count2+ml;end%********************end of file***************************%viterbi.m%viterbi解码程序function[decoder_output,survivor_state,cumulated_metric]=viterbi(G,k,channel_output) %[decoder_output,survivor_state,cumulated_metric]=viterbi(G,k,channel_output)%其中G是一个n行L*k列矩阵,它的每一行决定了从移位寄存器到输入码字的连接方式.%survivor_state是一个矩阵,它显示了通过网格的最优路径,这个矩阵通过一个单独%的函数metric(x,y)给出。

基于MATLAB的OFMD仿真实验-OFDM系统设计1

基于MATLAB的OFMD仿真实验-OFDM系统设计1

GI, TG (frac of TU)
24.6%
SubC 1K/2K
spacing/Hz
(子载波间隔)
4K/8K
1⁄4, 1⁄32
​1⁄8,
​1⁄16,

1⁄4, 1⁄32
​1⁄8,
​1⁄16,

1⁄4,
​1⁄6,
​1⁄9
4, 464 1, 116
4,464, 2,232, 1,116
2,000
1/128, 1/32, 1/16, 19/256, 1/8, 19/128, 1/4.
(CFO):
f
f
tx c
f
rx c
Doppler Shift (多普勒偏移)
CFO Estimation & Compensation
(先估计出偏移然后补偿,然后就可以消除频偏CFO实现同步)
Time/Frequency Synchronization
Find the start point of OFDM symbols (ISI free) CFO Estimation & Compensation (ICI free)
Noise Figure
SNR -- Signal to Noise Ratio -- 信噪比
Tx/Rx process of OFDM system
Time Synchronization
(时间同步)
Inter-symbol Interference (ISI)
N
N
N
Find the start point of OFDM symbols
Physical Layer System Design

mimoofdm无线通信技术与matlab代码

mimoofdm无线通信技术与matlab代码

mimoofdm无线通信技术与matlab代码1. 引言1.1 概述无线通信技术的发展迅猛,随着移动互联网时代的到来,人们对高速、稳定的无线通信需求日益增加。

MIMO-OFDM无线通信技术作为一种重要的解决方案,在提升系统容量和抗干扰性能方面具有显著优势。

本文旨在介绍MIMO-OFDM 无线通信技术原理,并借助MATLAB代码实现,通过仿真和性能评估分析展示其有效性和优越性。

1.2 文章结构本文分为五个部分:引言、MIMO-OFDM无线通信技术、MATLAB代码实现、实验结果与讨论以及结论与展望。

在引言部分,我们将简要介绍文章的背景和目标。

接下来,会详细讲解MIMO-OFDM无线通信技术的基本原理,并说明其在提高系统容量和抗干扰性能方面的作用。

然后,我们会详细描述如何使用MATLAB编写MIMO-OFDM系统模拟代码,并进行性能评估与分析。

随后,我们会展示仿真参数设置和结果展示,并对结果进行深入分析和性能讨论。

最后,在结论与展望部分,我们将总结本文的研究工作和贡献,并讨论目前的不足之处以及可能的改进方案。

1.3 目的本文的主要目的是深入介绍MIMO-OFDM无线通信技术及其原理,并通过MATLAB代码实现来验证其性能。

通过对实验结果进行分析和讨论,我们旨在揭示MIMO-OFDM技术在提高系统容量和抗干扰性能方面的优势。

同时,本文也希望为读者提供一个了解和学习MIMO-OFDM无线通信技术以及使用MATLAB进行系统模拟的参考。

以上就是“1. 引言”部分内容,概述了本文的背景、目标和结构。

在接下来的章节中,我们将逐一展开讲解MIMO-OFDM无线通信技术、MATLAB代码实现、实验结果与讨论以及结论与展望部分。

2. MIMO-OFDM无线通信技术:2.1 MIMO技术介绍:多输入多输出(MIMO)技术是一种通过在发射和接收端使用多个天线来增加系统容量和提高通信质量的无线通信技术。

MIMO技术利用空间上的多样性,通过在不同天线之间形成独立的传输通道,从而带来更好的抗干扰能力和信号接收品质。

ofdm解调matlab代码

ofdm解调matlab代码
在Matlab中实现OFDM解调的基本代码如下所示:
%假设接收到的信号为receivedSignal,其长度为N
N = length(receivedSignal);
%假设使用的子载波数量为M
Hale Waihona Puke M = 64;%生成一个长度为M的IFFT矩阵
IFFTMatrix = ifft(ones(1, M), M);
%对接收到的信号进行解调
demodulatedSignal = IFFTMatrix * receivedSignal;
%输出解调后的信号
disp(demodulatedSignal);
这个代码实现了基本的OFDM解调过程,即将接收到的信号通过一个逆快速傅里叶变换(IFFT)矩阵解调为原始数据信号。需要注意的是,这只是一个基本的示例,实际的OFDM解调过程可能需要进行同步、信道估计和均衡等操作。此外,对于不同的系统参数(如子载波数量、调制方式等),IFFT矩阵的大小和生成方式也可能不同。

基于MATLAB实现OFDM的解码

基于MATLAB实现OFDM的解码

毕业论文题目基于MATLAB的OFDM研究2019年 4 月基于MATLAB的OFDM研究摘要自80年代,数字移动通信技术逐渐开始成熟,并开始应用在各式各样的,种类不同的无线通信系统,例如,数字集群电话,数字蜂窝电话,无线寻呼等,以上使用的是特高频/甚高频波段的数字移动通信。

但是这两者的移动信道存在很多问题,噪声干扰,在多径传播时易造成码间串扰,选择性衰弱等。

为解决这些问题,OFDM出现了,即正交频分复用。

它是第四代移动通信的关键技术。

因为它的信道被利用率非常高,抗衰弱能力非常好。

OFDM的信号产生与解调的过程就是 IDFT/DFT 的变换过程。

正交频分复用(OFDM)是一种调制技术,在许多新兴的宽带无线和有线通信系统中得到了广泛应用。

由于OFDM技术具有利用多个频谱重叠的低速副载波传输高速数据流的能力,因此它具有频谱效率高、抗载波间和符号间抗干扰性、对服务器信道条件的适应性等优点,近年来,OFDM技术的研究越来越深入。

基于OFDM传输技术,被认为是未来超高速光传输的一种有前途的技术。

它可以构建一种在频谱分配和数据速率调节方面具有极大灵活性和可扩展性的新型弹性光网络结构,以支持未来多种业务和互联网流量的快速增长。

正交频分复用(OFDM)主要是针对多径接收的效果,通过将宽带频率选择性衰落信道许多狭窄的扁平子通道。

正交频分复用适应时变信道的灵活性采用各参数的条件副载波准确。

为了避免ISI多径,连续的OFDM符号被分开通过防护带。

这使得OFDM系统抗多径效应的思想利用FDM进行并行数据传输。

对OFDM的关注在无线和有线通信系统领域。

关键字:正道频分复用、OFDM、调制方式Decoding of OFDM System Based on MATLABAbstractSince the 1980s, digital mobile communication technology has gradually matured, and began to be applied in a variety of different types of wireless communication systems, such as digital trunking telephone, digital cellular phone, wireless paging, etc. The above uses digital mobile communication in UHF/VHF band. However, there are many problems in both mobile channels, such as noise interference, intersymbol interference and selective fading in multipath propagation. In order to solve these problems, the key technologies of the fourth generation mobile communication technology have emerged. It is better and more efficient, namely (orthogonal frequency division multiplexing) OFDM. It not only has high channel utilization, but also has good anti-fading ability. The process of signal generation and demodulation in OFDM is the transformation process of IDFT/DFT. Orthogonal Frequency Division Multiplexing (OFDM) is a modulation technology, which has been widely used in many emerging broadband wireless and wired communication systems. Because OFDM technology has the ability to transmit high-speed data streams using low-speed subcarriers with overlapping spectrum, it has the advantages of high spectral efficiency, anti-interference between carriers and symbols, and adaptability to server channel conditions. In recent years, the research of OFDM technology has become more and more in-depth. Based on OFDM transmission technology, it is considered as a promising technology for ultra-high-speed optical transmission in the future. It can construct a new elastic optical network structure with great flexibility and scalability in spectrum allocation and data rate regulation to support the rapid growth of various services and Internet traffic in the future.Orthogonal Frequency Division Multiplexing (OFDM) is mainly aimed at the effect of multipath reception. It uses many narrowflat subchannels in broadband frequency selective fading channels. Orthogonal Frequency Division Multiplexing (OFDM) is flexible to adapt to time-varying channels, and the subcarriers with different parameters are accurate. To avoid ISI multipath, consecutive OFDM symbols are separated through the guard belt. This makes the idea of anti-multipath effect in OFDM system use FDM to carry out parallel data transmission. Concern about OFDM is in the field of wireless and wired communication systems.Key words: channel frequency division multiplexing, OFDM目录摘要 (Ⅰ)Abstract (Ⅱ)第一章绪论 (1)1.1 OFDM的研究背景、意义 (1)1.2 OFDM的发展 (1)1.3 OFDM的主要优点和缺点 (1)1.4 OFDM的应用 (2)第二章OFDM基本原理 (4)2.1 原理、数学描述 (4)2.2 OFDM的参数、特性 (5)2.3 子载波调制 (6)第三章OFDM的系统仿真 (9)3.1 MATLAB的特点和功能 (9)3.2 OFDM系统仿真 (9)3.2.1 OFDM时域波形 (9)3.2.2 OFDM子载波频谱 (10)3.2.3 QPSK调制 (11)3.2.4 QPSK调制星座图 (13)3.2.5 并串转换 (13)3.2.6 QPSK解调 (14)3.2.7 接收信号 (15)3.2.8 OFDM解码实现 (15)结束语 (20)参考文献 (21)致谢 (23)第一章绪论1.1 OFDM的研究背景、意义正交频分复用(OFDM)已成为世界上许多电信标准的基础(包括无线局域网(LAN)、数字地面电视(DTT)、数字无线电广播)。

ofdm子载波频谱matlab代码

ofdm子载波频谱matlab代码

ofdm子载波频谱matlab代码以下是一个简单的OFDM子载波频谱的Matlab代码示例。

该代码主要生成一个OFDM信号,并计算其频谱。

```Matlab% 参数设定N = 64; % 子载波数CP = N/4; % 循环前缀长度t = 1/20e3; % 时间长度Ts = t/N; % 符号周期f0 = 2.5e9; % 载波频率fc = 10*f0; % 信号带宽Tb = N*Ts; % 比特周期c = 3e8; % 光速d = c*Ts/2; % 发送天线与接收天线间距SNRdB = 10; % 比特能量噪声比(dB)snr = SNRdB/10; % 比特能量噪声比EbN0 = 10^(snr/10); % 比特能量噪声密度比EbN0_dB = 10*log10(EbN0); % 比特能量噪声密度比(dB)Pn = 1/sqrt(2)*(sqrt(2)*sqrt(pi)*sqrt(EbN0)*1i)/2; % 加性高斯白噪声功率谱密度Pn_dB = 10*log10(Pn); % 加性高斯白噪声功率谱密度(dB)% 生成OFDM信号data = randi([0,1],N,1); % 生成随机的二进制数据data_fft = fft(data); % FFT变换data_fft_cp = [data_fft, zeros(CP,1)]; % 添加循环前缀x = exp(1i*2*pi*f0*(0:N-1)*Ts); % 生成载波信号x_cp = [x, zeros(CP,1)]; % 添加循环前缀x_cp_data = x_cp.*data_fft_cp; % 调制信号x_cp_data_mod = real(x_cp_data); % 取实部,得到复数调制信号x_cp_data_mod_tx = repmat(x_cp_data_mod,1,d); % 发送天线复制信号x_cp_data_mod_rx = repmat(x_cp_data_mod,1,d); % 接收天线复制信号x_cp_data_mod_rx(:,:) = conj(x_cp_data_mod(:,:)); % 天线相位翻转,实现模拟MIMO传输y = filter([1-d -d],1,x_cp_data_mod_tx) + filter([-d -d 1],1,x_cp_data_mod_rx); % MIMO接收信号滤波器处理y = y/2; % 均衡处理,实现模拟解调y_fft = fft(y); % FFT变换,解调信号y_fft = y_fft(CP+1:end); % 去掉循环前缀,得到解调数据频域信号y = real(y_fft); % 取实部,得到解调数据时域信号y = ifft(y); % IFFT变换,得到解调数据时域信号data_demod = real(y); % 取实部,得到解调数据时域信号% 计算频谱frequencies = -fc:fc/(N*Ts); % 频率轴取值范围power = abs(fft(data))**2; % 计算功率谱密度函数power_noise = abs(fft(randn(N,length(t)))**2); % 计算加性高斯白噪声功率谱密度函数power = power + power_noise; % 计算总功率谱密度函数power = power/max(power); % 归一化处理,使最大功率为1figure; plot(frequencies,power); xlabel('Frequency (Hz)'); ylabel('Power Spectral Density (W/Hz)'); title('Power Spectrum'); grid on;以上就是关于ofdm子载波频谱matlab代码的介绍,欢迎补充。

基于Matlab的OFDM同步算法

基于Matlab的OFDM同步算法

02
OFDM技术通过将高速数据流分散到多个子载波上,增加信号传输的可靠性, 同时通过添加循环前缀,有效抵抗多径干扰。
03
同步技术则关注如何快速、准确地找到接收信号的起始位置,以恢复原始数据 。
算法流程
编码阶段,发送端将输入数据进行OFDM编码,添加循 环前缀和其他必要的标识。
解调阶段,接收端对接收到的OFDM信号进行解码,提 取出原始数据。
时频跟踪
展示算法在时变信道下的跟踪性能,验证其 适应能力。
误码率分析
通过分析误码率等指标,验证算法在实际应 用中的可靠性。
复杂度评估
对优化前后的算法复杂度进行评估,展示优 化在降低运算复杂度方面的效果。
05
总结与展望
研究成果总结
高效的算法
基于matlab的ofdm同步算法在仿真实验中表现出高效性 ,能够快速准确地实现信号同步。
01
预处理接收信号
通过去除噪声、频偏等手段,提 高接收信号的质量。
构建解调器
根据估计的参数,构建适合的解 调器对OFDM信号进行解调。
03
02
估计时频参数
利用训练序列或已知信息,估计 出信号的时域和频域参数。
优化解调结果
对解调后的信号进行进一步优化 ,如去除干扰、均衡等。
04
优化结果展示
性能对比
将优化后的算法与传统的OFDM同步算法进 行性能对比,展示优化的有效性。
2. 生成训练序列:在每 个OFDM符号前添加一 个特定的训练序列,用
于接收端进行同步。
实现步骤
3. 调制
对输入数据进行QPSK或QAM等调制。
4. IFFT
进行逆快速傅里叶变换(IFFT),将频域数据转换为时域数据。

【matlab编程代做】OFDM

【matlab编程代做】OFDM

clc;clear;%参数初始化i=sqrt(-1);awgn=0; % 定义高斯信道se=0; % 估计技术nse=64; % OFDM载波个数ng=16; % 循环前缀长度SNR=[0 5 10 15 20 25 30 35 40]; % 信噪比mt=2; % 发送天线mr=2; % 接收天线pilot=[1:nse/ng:nse]; % 子带载波ds=5; % 信道延迟number=200;%====================================================================== N=50;fm=100;B=20e3;fd=(rand(1,N)-0.5)*2*fm;theta=randn(1,N)*2*pi;c=randn(1,N);c=c/sum(c.^2);t=0:fm/B:10000*fm/B;T_c=zeros(size(t));T_s=zeros(size(t));for k=1:NT_c=c(k)*cos(2*pi*fd(k)*t+theta(k))+T_c;T_s=c(k)*sin(2*pi*fd(k)*t+theta(k))+T_s;endr=ones(mt*mr,1)*(T_c.^2+T_s.^2).^0.5;index=floor(rand(mt*mr,ds)*5000+1);MEE1=zeros(1,length(SNR));MEE2=zeros(1,length(SNR));for snrl=1:length(SNR)snrlestimation_error1=zeros(mt*mr,nse);estimation_error2=zeros(mt*mr,nse);R1=besselj(0,2*pi*fm*(nse+ng)/B);sigma2=10^(-SNR(snrl)/10);aa=(1-R1^2)/(1-R1^2+sigma2);bb=sigma2*R1/(1-R1^2+sigma2);for iteration=1:numberif awgn==1h=ones(mt*mr,1);elsephi=rand*2*pi;h=r(index+iteration)*exp(j*phi);h=h.*(ones(mt*mr,1)*(exp(-0.5).^[1:ds]));h=h./(sqrt(sum(abs(h).^2,2))*ones(1,ds));end% 信道长度CL=size(h,2);data_time=zeros(mt,nse+ng);data_qam=zeros(mt,nse);data_out=zeros(mr,nse);output=zeros(mr,nse);for tx=1:mtdata_b=0*round(rand(4,nse));data_qam(tx,:)=j*(2*(mod(data_b(1,:)+data_b(2,:),2)+2*data_b(1,:))-3)+2*(mod(data_b(3,:)+data_b(4,:),2)+2*da ta_b(3,:))-3;for loop=1:mtdata_qam(tx,pilot+loop-1)=(1+j)*(loop==tx);enddata_time_temp=ifft(data_qam(tx,:));data_time(tx,:)=[data_time_temp(end-ng+1:end) data_time_temp];endfor rx=1:mrfor tx=1:mtoutput_temp=conv(data_time(tx,:),h((rx-1)*mt+tx,:));output(rx,:)=output_temp(ng+1:ng+nse)+output(rx,:);endnp=(sum(abs(output(rx,:)).^2)/length(output(rx,:)))*sigma2;noise=(randn(size(output(rx,:)))+i*randn(size(output(rx,:))))*sqrt(np);output(rx,:)=output(rx,:)+noise;data_out(rx,:)=fft(output(rx,:));end%信道估计H_act=zeros(mt*mr,nse);H_est1=zeros(mt*mr,nse);H_est2=zeros(mt*mr,nse);i=1;for tx=1:mtfor rx=1:mrH_est_temp=data_out(rx,pilot+tx-1)./data_qam(tx,pilot+tx-1);h_time=ifft(H_est_temp);h_time=[h_time zeros(1,nse-length(h_time))];H_est1((rx-1)*mt+tx,:)=fft(h_time);H_est2((rx-1)*mt+tx,:)=((aa*abs(H_est1((rx-1)*mt+tx,:))+bb*abs(H_est2((rx-1)*mt+tx,:)))....*H_est1((rx-1)*mt+tx,:))./abs(H_est1((rx-1)*mt+tx,:));if (tx>1)H_est1((rx-1)*mt+tx,:)=[H_est1((rx-1)*mt+tx,nse-tx+2:nse)H_est1((rx-1)*mt+tx,1:nse-tx+1)];H_est2((rx-1)*mt+tx,:)=[H_est2((rx-1)*mt+tx,nse-tx+2:nse)H_est2((rx-1)*mt+tx,1:nse-tx+1)];endH_act((rx-1)*mt+tx,:)=fft([h((rx-1)*mt+tx,:) zeros(1,nse-CL)]);error1=(abs(H_act((rx-1)*mt+tx,:)-H_est1((rx-1)*mt+tx,:)).^2);error2=(abs(H_act((rx-1)*mt+tx,:)-H_est2((rx-1)*mt+tx,:)).^2);estimation_error1((rx-1)*mt+tx,:)=estimation_error1((rx-1)*mt+tx,:)+error1;estimation_error2((rx-1)*mt+tx,:)=estimation_error2((rx-1)*mt+tx,:)+error2;endendendestimation_error1=estimation_error1/number;estimation_error2=estimation_error2/number;MEE1(snrl)=sum(sum(estimation_error1))/(mt*mr*nse);MEE2(snrl)=sum(sum(estimation_error2))/(mt*mr*nse);endplot(SNR,10*log10(MEE1));hold on;plot(SNR,10*log10(MEE2),'r');error1=(abs(H_act-H_est1).^2)./(abs(H_act).^2);error2=(abs(H_act-H_est2).^2)./(abs(H_act).^2);fig=4;i=1;figure(1);subplot(fig,1,i),plot([0:length(H_act)-1],abs(H_act)); i=i+1;subplot(fig,1,i),plot([0:length(H_est1)-1],abs(H_est1)); i=i+1;subplot(fig,1,i),plot([0:length(H_est2)-1],abs(H_est2)); i=i+1;subplot(fig,1,i),plot([0:length(error1)-1],error1); i=i+1;IFFT_bin_length=128;carrier_count=100;biT_s_per_symbol=2;symbols_per_carrier=12;LI=7 ;Np=ceil(carrier_count/LI)+1;N_number=carrier_count*symbols_per_carrier*biT_s_per_symbol; carriers=1:carrier_count+Np;GI=8;N_snr=40; % 每比特信噪比snr=8; %信噪比间隔X=zeros(1,N_number) ;XX=zeros(1,N_number) ;dif_bit=zeros(1,N_number) ;dif_bit1=zeros(1,N_number);dif_bit2=zeros(1,N_number);dif_bit3=zeros(1,N_number);X=randint(1,N_number) ;s=(X.*2-1)/sqrt(2) ;sreal=s(1:2:N_number) ;simage=s(2:2:N_number) ;%=========================================X1=sreal+j.*simage;train_sym=randint(1,2*symbols_per_carrier);t=(train_sym.*2-1)/sqrt(2);treal=t(1:2:2*symbols_per_carrier);timage=t(2:2:2*symbols_per_carrier);training_symbols1=treal+j.*timage;training_symbols2=training_symbols1.';training_symbols=repmat(training_symbols2,1,Np);pilot=1:LI+1:carrier_count+Np;if length(pilot)~=Nppilot=[pilot,carrier_count+Np];end%串并转换X2=reshape(X1,carrier_count,symbols_per_carrier).';%插入导频signal=1:carrier_count+Np;signal(pilot)=[];X3(:,pilot)=training_symbols;X3(:,signal)=X2;IFFT_modulation=zeros(symbols_per_carrier,IFFT_bin_length); IFFT_modulation(:,carriers)=X3;X4=ifft(IFFT_modulation,IFFT_bin_length,2);%加保护间隔(循环前缀)for k=1:symbols_per_carrier;for i=1:IFFT_bin_length;X6(k,i+GI)=X4(k,i);endfor i=1:GI;X6(k,i)=X4(k,i+IFFT_bin_length-GI);endend%并串转换X7=reshape(X6.',1,symbols_per_carrier*(IFFT_bin_length+GI)); %信道模型:带多普勒频移的瑞利衰落信道fd=100; %多普勒频移r=6; %多径数a=[0.123 0.3 0.4 0.5 0.7 0.8]; %多径的幅度d=[2 3 4 5 9 13]; %各径的延迟T=1; %系统采样周期th=[90 0 72 144 216 288]*pi./180;%相移h=zeros(1,carrier_count);hh=[];for k=1:rh1=a(k)*exp(j*((2*pi*T*fd*d(k)/carrier_count)));hh=[hh,h1];endh(d+1)=hh;channel1=zeros(size(X7));channel1(1+d(1):length(X7))=hh(1)*X7(1:length(X7)-d(1)); channel2=zeros(size(X7));channel2(1+d(2):length(X7))=hh(2)*X7(1:length(X7)-d(2)); channel3=zeros(size(X7));channel3(1+d(3):length(X7))=hh(3)*X7(1:length(X7)-d(3)); channel4=zeros(size(X7));channel4(1+d(4):length(X7))=hh(4)*X7(1:length(X7)-d(4)); channel5=zeros(size(X7));channel5(1+d(5):length(X7))=hh(5)*X7(1:length(X7)-d(5)); channel6=zeros(size(X7));channel6(1+d(6):length(X7))=hh(6)*X7(1:length(X7)-d(6));Tx_data=X7+channel1+channel2+channel3+channel4;%加高斯白噪声Error_ber=[];%误比特率Error_ber1=[];Error_ber2=[];%误比特率Error_ber3=[];for snr_db=0:snr:N_snrcode_power=0;code_power=[norm(Tx_data)]^2/(length(Tx_data)); %信号的符号功率bit_power=code_power/biT_s_per_symbol; %比特功率noise_power=10*log10((bit_power/(10^(snr_db/10))));%噪声功率noise=wgn(1,length(Tx_data),noise_power,'complex');%产生GAUSS白噪声信号Y7=Tx_data+noise;%串并变换Y6=reshape(Y7,IFFT_bin_length+GI,symbols_per_carrier).';%去保护间隔for k=1:symbols_per_carrier;for i=1:IFFT_bin_length;Y5(k,i)=Y6(k,i+GI);endendY4=fft(Y5,IFFT_bin_length,2);Y3=Y4(:,carriers);%LS信道估计H=[];Y2=Y3(:,signal);Rx_training_symbols=Y3(:,pilot);Rx_training_symbols0=reshape(Rx_training_symbols,symbols_per_carrier*Np,1);training_symbol0=reshape(training_symbols,1,symbols_per_carrier*Np);training_symbol1=diag(training_symbol0);training_symbol2=inv(training_symbol1);Hls=training_symbol2*Rx_training_symbols0;Hls1=reshape(Hls,symbols_per_carrier,Np);HLs=[];HLs1=[];if ceil(carrier_count/LI)==carrier_count/LIfor k=1:Np-1HLs2=[];for t=1:LIHLs1(:,1)=(Hls1(:,k+1)-Hls1(:,k))*(t-1)./LI+Hls1(:,k);HLs2=[HLs2,HLs1];endHLs=[HLs,HLs2];endelsefor k=1:Np-2HLs2=[];for t=1:LIHLs1(:,1)=(Hls1(:,k+1)-Hls1(:,k))*(t-1)./LI+Hls1(:,k);HLs2=[HLs2,HLs1];endHLs=[HLs,HLs2];endHLs3=[];for t=1:mod(carrier_count,LI)HLs1(:,1)=(Hls1(:,Np)-Hls1(:,Np-1))*(t-1)./LI+Hls1(:,Np-1);HLs3=[HLs3,HLs1];end;HLs=[HLs,HLs3];endY1=Y2./HLs;%并串变换YY=reshape(Y2.',1,N_number/biT_s_per_symbol);YY1=reshape(Y1.',1,N_number/biT_s_per_symbol);%QPSK解调y_real=sign(real(YY));y_image=sign(imag(YY));y_re=y_real./sqrt(2);y_im=y_image./sqrt(2);y_real1=sign(real(YY1));y_image1=sign(imag(YY1));y_re1=y_real1./sqrt(2);y_im1=y_image1./sqrt(2);r00=[];r01=[];r10=[];r11=[];for k=1:length(y_real);r00=[r00,[y_real(k),y_image(k)]];end;for k=1:length(y_real1);r10=[r10,[y_real1(k),y_image1(k)]];end;for k=1:length(y_re);r01=[r01,[y_re(k),y_im(k)]];end;for k=1:length(y_re1);r11=[r11,[y_re1(k),y_im1(k)]];end;XX(find(r01>0))=1;%计算在不同信噪比下的误比特率并作图dif_bit=s-r01;dif_bit1=s-r11;ber_snr=0; %纪录误比特数for k=1:N_number;if dif_bit(k)~=0;ber_snr=ber_snr+1;endend;ber_snr1=0; %纪录误比特数for k=1:N_number;if dif_bit1(k)~=0;ber_snr1=ber_snr1+1;endendError_ber=[Error_ber,ber_snr]; Error_ber1=[Error_ber1,ber_snr1]; endBER=zeros(1,length(0:snr:N_snr)); BER1=zeros(1,length(0:snr:N_snr));BER=Error_ber./N_number;BER1=Error_ber1./N_number; figure(2);i=0:snr:N_snr;semilogy(i,BER,'-*r');hold on;semilogy(i,BER1,'-og');hold on;legend('无信道估计','线性信道估计');。

基于MATLAB的OFMD仿真实验-OFDM系统设计2

基于MATLAB的OFMD仿真实验-OFDM系统设计2
(块大小与单个OFDM符号中的比特数相对应)
The interleaver is defined by a two-step permutation (置换). The first permutation ensures that adjacent coded bits are
mapped onto nonadjacent subcarriers. The second ensures that adjacent coded bits are mapped
Convolutional code
[1 0 1 1 0 1 1]=(133)8
1/2编码,约束长度为7
[1 1 1 1 0 0 1]=(171)8
test_coding.m
Puncturing (打孔)
# 1/2编码,多一倍 然后打孔punctuate
# 进去9个,出来12个 就有 r = 3/4
Main Parameters of 802.11a
Tg 4
Ttotal 5Tg
f 20MHz 64 312.5KHz
B f 54 16.875MHz
Tx/Rx process of OFDM system
Modulation: BPSK/QPSK/16QAM/64QAM Coding: 1/2 Convolutional code Coding Rate (Punctuate (打孔)): 1/2、2/3、3/4
alternately onto less and more significant bits of the constellation and, thereby, long runs of low reliability (LSB) bits are avoided. ( Least Significant Bit 还需要好好理解!)

基于matlab ofdm通信系统仿真代码

基于matlab ofdm通信系统仿真代码

基于matlab ofdm通信系统仿真代码
基于MATLAB OFDM通信系统仿真代码是一种应用在无线通信领域的高
效的通信技术。

OFDM(正交分频多载波)技术是一种高效的技术,它
能够在有限的信道容量内传输大量的数据,同时也能抵御多径衰减和
多路径效应。

此外,OFDM还可以抵抗非线性干扰和伪噪声,从而提高
系统的可靠性和稳定性。

MATLAB OFDM通信系统仿真代码可以帮助我们快速验证一个OFDM系统的性能,从而帮助我们更好地理解OFDM技术
背后的原理和技术。

MATLAB OFDM通信系统仿真代码由信道模拟、OFDM调制和解调制的子
模块组成,其中每个子模块都可以通过MATLAB编程实现。

首先,我们
需要定义一个简单的信道函数,以模拟实际信道的衰减和多路径效应,然后将信号传输给OFDM调制模块,它将信号转换成OFDM调制的多载
波信号。

接着,多载波信号被发射到信道中,经过信道后,经过OFDM
解调制模块处理,得到恢复后的信号,再经过信道衰减模拟得到最终
信号,完成仿真。

通过使用MATLAB OFDM通信系统仿真代码,我们可以更有效地对OFDM
技术进行仿真评估,同时也可以获得更为准确、直观的仿真结果。

此外,MATLAB OFDM通信系统仿真代码还可以帮助我们了解OFDM技术的
具体实施方法,为实际开发工作提供有效的技术支持。

OFDM发射端matlab仿真代码

OFDM发射端matlab仿真代码
% Fstop2 = 7; 2,Fstop2);
% output = conv(output,b);
% filter_coeff = [-0.0003,-0.0007,-0.0008,-0.0002,0.0014,0.0033,0.004,0.0022,-0.0018,-0.0061,-0.0075,-0.0046,0.0012,0.0064,0.0076,0.0047,0.0007,-0.0008,0.0013,0.0042,0.0041,-0.0001,-0.0057,-0.0081,-0.0057,-0.0013,0.0001,-0.0036,-0.0092,-0.011,-0.0063,0.0014,0.0054,0.0023,-0.004,-0.0057,0.0012,0.0122,0.018,0.0137,0.0039,-0.0005,0.0066,0.0195,0.0253,0.0161,-0.0019,-0.0129,-0.0071,0.0085,0.0147,-0.0016,-0.0324,-0.0531,-0.0449,-0.0163,0.0002,-0.0238,-0.0816,-0.1265,-0.1041,0.0019,0.1474,0.2515,0.2515,0.1474,0.0019,-0.1041,-0.1265,-0.0816,-0.0238,0.0002,-0.0163,-0.0449,-0.0531,-0.0324,-0.0016,0.0147,0.0085,-0.0071,-0.0129,-0.0019,0.0161,0.0253,0.0195,0.0066,-0.0005,0.0039,0.0137,0.018,0.0122,0.0012,-0.0057,-0.004,0.0023,0.0054,0.0014,-0.0063,-0.011,-0.0092,-0.0036,0.0001,-0.0013,-0.0057,-0.0081,-0.0057,-0.0001,0.0041,0.0042,0.0013,-0.0008,0.0007,0.0047,0.0076,0.0064,0.0012,-0.0046,-0.0075,-0.0061,-0.0018,0.0022,0.004,0.0033,0.0014,-0.0002,-0.0008,-0.0007,-0.0003;];

OFDM信道估计MATLAB代码

OFDM信道估计MATLAB代码

echo off; % 关闭回显clear all; % 从内存中清除变量和函数close all; % 关闭所有图形fprintf( '\n OFDM仿真\n \n') ; % 设置显示格式% --------------------------------------------- %% 参数定义%% --------------------------------------------- %IFFT_bin_length = 1024; % 发送端的IFFT变换长度, 接收端的FFT变换长度,R代表接受,T代表发送carrier_count = 200; % 子载波数bits_per_symbol = 2; % 位数/符号symbols_per_carrier = 50; % 符号数/载波cp_length = input('cp length = '); % 输入循环前缀长度d4 = input('d4 = '); % 输入最大多径时延扩展a4 = input('a4 = '); % 输入最大多径时延扩展的系数SNR = input('SNR = '); % 输入信道信噪比(dB) % --------------------------------------------- %% 初始参数设置完毕%% --------------------------------------------- %baseband_out_length = carrier_count * symbols_per_carrier * bits_per_symbol; % 计算发送的二进制序列长度:基带传送长度=载波数×符号数/载波×位数/符号carriers = (1:carrier_count) + (floor(IFFT_bin_length/4) - floor(carrier_count/2)); % 载波(坐标):(1:200) + 256 - 100 = 157:356conjugate_carriers = IFFT_bin_length - carriers + 2; % 载波变换(坐标):1024 - (157:356) + 2 = 1026 - (157:356) = (869:670)%---------------------------------------% 构造共轭时间-载波矩阵,以便应用所谓的RCC,Reduced Computational Complexity算法,即ifft之后结果为实数% 也可以用flipdim函数构造对称共轭矩阵%---------------------------------------% --------------------------------------------- %% 发送信号%% --------------------------------------------- %%---------------------------------------% Generate a random binary output signal:% - a row of uniform random numbers (between 0 and 1), rounded to 0 or 1% - this will be the baseband signal which is to be transmitted.%---------------------------------------baseband_out = round(rand(1,baseband_out_length));%---------------------------------------% round:朝最近的整数取整,rand:产生均匀分布的随机数矩阵(1×baseband_out_length 阶)% Convert to 'modulo N' integers where N = 2^bits_per_symbol% - this defines how many states each symbol can represent% - first, make a matrix with each column representing consecutive bits% from the input stream and the number of bits in a column equal to the% number of bits per symbol% - then, for each column, multiply each row value by the power of 2 that% it represents and add all the rows% - for example: input 0 1 1 0 0 0 1 1 1 0% bits_per_symbol = 2% convert_matrix = 0 1 0 1 1% 1 0 0 1 0% modulo_baseband = 1 2 0 3 2%---------------------------------------convert_matrix = reshape(baseband_out,bits_per_symbol,length(baseband_out)/bits_per_symbol) ;%---------------------------------------% RESHAPE Change size. 把baseband_out变为M×N阶的矩阵% RESHAPE(X,M,N) returns the M-by-N matrix whose elements% are taken columnwise from X. An error results if X does% not have M*N elements.%---------------------------------------for k = 1:(length(baseband_out)/bits_per_symbol)modulo_baseband(k) = 0 ;for i = 1:bits_per_symbolmodulo_baseband(k) = modulo_baseband(k) + convert_matrix(i,k)*2^(bits_per_symbol - i) ; endend%---------------------------------------% Serial to Parallel Conversion 串并转换% - convert the serial modulo N stream into a matrix where each column% represents a carrier and each row represents a symbol% - for example:% serial input stream = a b c d e f g h i j k l m n o p% parallel carrier distribution =% C1/s1=a C2/s1=b C3/s1=c C4/s1=d% C1/s2=e C2/s2=f C3/s2=g C4/s2=h% C1/s3=i C2/s3=j C3/s3=k C4/s3=l% . . . .% . . . .%---------------------------------------carrier_matrix = reshape(modulo_baseband, carrier_count, symbols_per_carrier)'; %生成时间-载波矩阵(carrier_count×symbols_per_carrier)%---------------------------------------% Apply differential coding to each carrier string% - append an arbitrary start symbol (let it be 0, that works for all% values of bits_per_symbol) (note that this is done using a vertical% concatenation [x;y] of a row of zeros with the carrier matrix, sweet!)% - perform modulo N addition between symbol(n) and symbol(n-1) to get the% coded value of symbol(n)% - for example:% bits_per_symbol = 2 (modulo 4)% symbol stream = 3 2 1 0 2 3% start symbol = 0%% coded symbols = 0 + 3 = 3% 3 + 2 = 11 = 1% 1 + 1 = 2% 2 + 0 = 2% 2 + 2 = 10 = 0% 0 + 3 = 3%% coded stream = 0 3 1 2 2 0 3%---------------------------------------% --------------------------------------------- %% QDPSK调制%% --------------------------------------------- %carrier_matrix = [zeros(1,carrier_count);carrier_matrix]; % 添加一个差分调制的初始相位,为0for i = 2:(symbols_per_carrier + 1)carrier_matrix(i,:) = rem(carrier_matrix(i,:)+carrier_matrix(i-1,:),2^bits_per_symbol); % 差分调制(rem除后取余)end%---------------------------------------% Convert the differential coding into a phase% - each phase represents a different state of the symbol% - for example:% bits_per_symbol = 2 (modulo 4)% symbols = 0 3 2 1% phases =% 0 * 2pi/4 = 0 (0 degrees)% 3 * 2pi/4 = 3pi/2 (270 degrees)% 2 * 2pi/4 = pi (180 degrees)% 1 * 2pi/4 = pi/2 (90 degrees)%---------------------------------------carrier_matrix = carrier_matrix * ((2*pi)/(2^bits_per_symbol)); % 产生差分相位%---------------------------------------% Convert the phase to a complex number% - each symbol is given a magnitude of 1 to go along with its phase% (via the ones(r,c) function)% - it is then converted from polar to cartesian (complex) form% - the result is 2 matrices, X with the real values and Y with the imaginary% - each X column has all the real values for a carrier, and each Y column% has the imaginary values for a carrier% - a single complex matrix is then generated taking X for real and% Y for imaginary%---------------------------------------[X,Y] = pol2cart(carrier_matrix, ones(size(carrier_matrix,1),size(carrier_matrix,2))); % 由极坐标向复数坐标转化第一参数为相位第二参数为幅度%---------------------------------------% Carrier_matrix contains all the phase information and all the amplitudes are the same,‘1’% 函数说明:极或柱坐标变为直角坐标% POL2CART Transform polar to Cartesian coordinates.% [X,Y] = POL2CART(TH,R) transforms corresponding elements of data% stored in polar coordinates (angle TH, radius R) to Cartesian% coordinates X,Y. The arrays TH and R must the same size (or% either can be scalar). TH must be in radians.% [X,Y,Z] = POL2CART(TH,R,Z) transforms corresponding elements of% data stored in cylindrical coordinates (angle TH, radius R, height Z)% to Cartesian coordinates X,Y,Z. The arrays TH, R, and Z must be% the same size (or any of them can be scalar). TH must be in radians.%---------------------------------------complex_carrier_matrix = complex(X,Y);%---------------------------------------% 函数说明:% COMPLEX Construct complex result from real and imaginary parts.% C = COMPLEX(A,B) returns the complex result A + Bi, where A and B are% identically sized real N-D arrays, matrices, or scalars of the same data type.%% Assign each carrier to its IFFT bin% - each row of complex_carrier_matrix represents one symbol period, with% a symbol for each carrier% - a matrix is generated to represent all IFFT bins (columns) and all% symbols (rows)% - the phase modulation for each carrier is then assigned to the% appropriate bin% - the conjugate of the phase modulation is then assigned to the% appropriate bin% - the phase modulation bins and their conjugates are symmetric about% the Nyquist frequency in the IFFT bins% - since the first bin is DC, the Nyquist Frequency is located% at (number of bins/2) + 1% - symmetric conjugates are generated so that when the signal is% transformed to the time domain, the time signal will be real-valued% - example% - 1024 IFFT bins% - bin 513 is the center (symmetry point)% - bin 1 is DC% - bin 514 is the complex conjugate of bin 512% - bin 515 is the complex conjugate of bin 511% - ....% - bin 1024 is the complex conjugate of bin 2 (if all bins% were used as carriers)% - So, bins 2-512 map to bins 1024-514%---------------------------------------%--------------------------------------% % 添加训练序列% %--------------------------------------% training_symbols = [ 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 ...-j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 ...1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 ...-1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j ...-1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 1 j j 1 -1 -j -j -1 ];%---------------------------------------% 25 times "1 j j 1"% 25 times "-1 -j -j -1"% totally 200 symbols as a row%---------------------------------------training_symbols = cat(1, training_symbols, training_symbols) ;training_symbols = cat(1, training_symbols, training_symbols) ;%---------------------------------------% Production of 4 rows of training_symbols% 函数说明:串接成高维数组% CAT Concatenate arrays.% CAT(DIM,A,B) concatenates the arrays A and B along the dimension DIM.% CAT(2,A,B) is the same as [A,B].% CAT(1,A,B) is the same as [A;B].% B = CAT(DIM,A1,A2,A3,A4,...) concatenates the input% arrays A1, A2, etc. along the dimension DIM.%---------------------------------------complex_carrier_matrix = cat(1, training_symbols, complex_carrier_matrix);%---------------------------------------% 训练序列与数据合并,串接成高维数组% block-type pilot symbols%---------------------------------------IFFT_modulation = zeros(4 + symbols_per_carrier + 1, IFFT_bin_length);%---------------------------------------% Here a row vector of zeros is between training symbols and data symbols% 4 training symbols and 1 zero symbol% every OFDM symbol takes a row of "IFFT_modulation"%---------------------------------------IFFT_modulation(:,carriers) = complex_carrier_matrix;IFFT_modulation(:,conjugate_carriers) = conj(complex_carrier_matrix);%---------------------------------------% Find the indices of zeros% Description% ZC = conj(Z) returns the complex conjugate of the elements of Z.% AlgorithmIf Z is a complex array: conj(Z) = real(Z) - i*imag(Z)%---------------------------------------time_wave_matrix = ifft(IFFT_modulation'); % 进行IFFT操作time_wave_matrix = time_wave_matrix'; % 进行矩阵转置cp_add = zeros(4 + symbols_per_carrier + 1,cp_length);for i = 1:4 + symbols_per_carrier + 1cp_add(i,:) = time_wave_matrix(i,(IFFT_bin_length - cp_length + 1) : IFFT_bin_length);endtime_wave_matrix_cp = [cp_add,time_wave_matrix];for i = 1: 4 + symbols_per_carrier + 1 % windowed_time_wave_matrix(i,:) = real(time_wave_matrix(i,:)) .* hamming(IFFT_bin_length)';windowed_time_wave_matrix_cp(i,:) = real(time_wave_matrix_cp(i,:));end%---------------------------------------% Serialize the modulating waveform% - sequentially take each row of windowed_time_wave_matrix and construct a row vector % - the row vector will be the modulating signal% - note that windowed_time_wave_matrix is transposed, this is to account for the way the % Matlab 'reshape' function works (reshape takes the columns of the target matrix and% appends them sequentially)% get the real part of the result of IFFT% 这一步可以省略,因为IFFT结果都是实数% 由此可以看出,只是取了IFFT之后载波上的点,并未进行CP的复制和添加end%---------------------------------------ofdm_modulation = reshape(windowed_time_wave_matrix_cp', 1, (IFFT_bin_length + cp_length)*(4 + symbols_per_carrier+1)); % P2S operation%---------------------------------------Tx_data = ofdm_modulation;%---------------------------------------% 信道模拟%---------------------------------------% The channel model is Gaussian (AWGN) only% - Rayleigh fading would be a useful addition%---------------------------------------d1 = 40; a1 = 0.2; d2 = 50; a2 = 0.3; d3 = 60; a3 = 0.4;%d4 = 160; a4 = 0.9;copy1 = zeros(size(Tx_data)) ;for i = 1 + d1: length(Tx_data)copy1(i) = a1*Tx_data( i - d1) ;endcopy2 = zeros(size(Tx_data) ) ;for i = 1 + d2: length( Tx_data)copy2(i) = a2*Tx_data( i - d2) ;endcopy3 = zeros(size(Tx_data) ) ;for i = 1 + d3: length(Tx_data)copy3(i) = a3*Tx_data ( i - d3) ;endcopy4 = zeros(size(Tx_data) ) ;for i = 1 + d4: length( Tx_data)copy4(i) = a4*Tx_data(i - d4) ;endTx_data = Tx_data + copy1 + copy2 + copy3 + copy4; % 4 multi-pathsTx_signal_power = var(Tx_data);%-------------------------------------------------------------------------% 函数说明:% VAR Variance.% For vectors, Y = VAR(X) returns the variance of the values in X. For% matrices, Y is a row vector containing the variance of each column of% X.%-------------------------------------------------------------------------linear_SNR = 10^(SNR/10);noise_sigma = Tx_signal_power/linear_SNR;noise_scale_factor = sqrt(noise_sigma);%noise = randn(1, length(Tx_data))*noise_scale_factor;Rx_Data = Tx_data + noise;%Rx_Data = Tx_data;%-------------------------------------------------------------------------% 函数说明:产生正态分布的随机函数% Y = randn(m,n) or Y = randn([m n]) returns an m-by-n matrix of random% entries.% The randn function generates arrays of random numbers whose elements are% normally distributed with mean 0 and variance 1.%-------------------------------------------------------------------------% --------------------------------------------- %% 信号接收%% --------------------------------------------- %%-------------------------------------------------------------------------Rx_Data_matrix_cp = reshape(Rx_Data, IFFT_bin_length + cp_length, 4 + symbols_per_carrier + 1);Rx_Data_matrix_cp = Rx_Data_matrix_cp';Rx_Data_matrix = zeros(4 + symbols_per_carrier + 1,IFFT_bin_length);for i = 1:4 + symbols_per_carrier + 1Rx_Data_matrix(i,:) = Rx_Data_matrix_cp(i,(cp_length + 1):(IFFT_bin_length + cp_length)); endRx_Data_matrix = Rx_Data_matrix';%-------------------------------------------------------------------------% Transform each symbol from time to frequency domain% - take the fft of each column%-------------------------------------------------------------------------Rx_spectrum = fft(Rx_Data_matrix);%-------------------------------------------------------------------------% Suppose precise synchronazition between Tx and RxRx_carriers = Rx_spectrum(carriers,:)';Rx_training_symbols = Rx_carriers( (1: 4) , : ) ;Rx_carriers = Rx_carriers((5: 55), : ) ;% --------------------------------------------- %% 信道估计%% --------------------------------------------- %Rx_training_symbols = Rx_training_symbols./ training_symbols;Rx_training_symbols_deno = Rx_training_symbols.^2;Rx_training_symbols_deno = Rx_training_symbols_deno(1,:)+Rx_training_symbols_deno(2,:)+Rx_training_symbols_deno(3,:)+ Rx_training_symbols_deno(4,:) ;Rx_training_symbols_nume = Rx_training_symbols(1, : ) +Rx_training_symbols(2, : ) + Rx_training_symbols(3, : ) +Rx_training_symbols(4, : ) ;Rx_training_symbols_nume = conj(Rx_training_symbols_nume) ;%-------------------------------------------------------------------------% 取4个向量的导频符号是为了进行平均优化% 都是针对“行向量”即单个的OFDM符号进行操作% 原理:寻求1/H,对FFT之后的数据进行频域补偿% 1/H = conj(H)/H^2 because H^2 = H * conj(H)%-------------------------------------------------------------------------Rx_training_symbols = Rx_training_symbols_nume./Rx_training_symbols_deno;Rx_training_symbols_2 = cat(1, Rx_training_symbols,Rx_training_symbols) ;Rx_training_symbols_4 = cat(1, Rx_training_symbols_2,Rx_training_symbols_2) ;Rx_training_symbols_8 = cat(1, Rx_training_symbols_4,Rx_training_symbols_4) ;Rx_training_symbols_16 = cat(1, Rx_training_symbols_8, Rx_training_symbols_8) ;Rx_training_symbols_32 = cat(1, Rx_training_symbols_16, Rx_training_symbols_16) ;Rx_training_symbols_48 = cat(1, Rx_training_symbols_32, Rx_training_symbols_16) ;Rx_training_symbols_50 = cat(1, Rx_training_symbols_48, Rx_training_symbols_2) ;Rx_training_symbols = cat(1, Rx_training_symbols_50,Rx_training_symbols) ;Rx_carriers = Rx_training_symbols.*Rx_carriers;%-------------------------------------------------------------------------% 进行频域单抽头均衡%-------------------------------------------------------------------------Rx_phase = angle(Rx_carriers)*(180/pi);phase_negative = find(Rx_phase < 0);%-------------------------------------------------------------------------% 函数说明:找出非零元素的索引号% FIND Find indices of nonzero elements.% I = FIND(X) returns the linear indices of the array X that are nonzero.% X may be a logical expression. Use IND2SUB(I,SIZE(X)) to calculate% multiple subscripts from the linear indices I.%---------------------------------------------------------------------------Rx_phase( phase_negative );Rx_phase(phase_negative) = rem(Rx_phase(phase_negative) + 360, 360) ;% 把负的相位转化为正的相位Rx_decoded_phase = diff(Rx_phase) ;% 这也是为什么要在前面加上初始相位的原因% “Here a row vector of zeros is between training symbols and data symbols”%-------------------------------------------------------------------------% 函数说明:% DIFF Difference and approximate derivative.% DIFF(X), for a vector X, is [X(2)-X(1) X(3)-X(2) ... X(n)-X(n-1)].% DIFF(X), for a matrix X, is the matrix of row differences,% [X(2:n,:) - X(1:n-1,:)].%------------------------Test Codes --------------------------------------% a = [1 2 3; 4 5 6; 7 8 9; 10 11 12];% b = a;% for i = 2:4% b(i,:) = b(i-1,:) + b(i,:);% end% c = diff(b);%-----------------------Test Result --------------------------------------% a = Modulating signal% 1 2 3% 4 5 6% 7 8 9% 10 11 12% b = Modulated signal% 1 2 3% 5 7 9% 12 15 18% 22 26 30% c = Recovered signal% 4 5 6% 7 8 9% 10 11 12% ----------------------------------------------------------------------------% Name Size Bytes Class% Rx_phase 51x200 81600 double array% Rx_decoded_phase 50x200 80000 double array% ----------------------------------------------------------------------------phase_negative = find(Rx_decoded_phase < 0) ;Rx_decoded_phase(phase_negative)= rem(Rx_decoded_phase(phase_negative) + 360, 360) ;% ----------------------------------------------------------------------------% Extract phase differences (from the differential encoding)% - the matlab diff( ) function is perfect for this operation% - again, normalize the result to be between 0 and 359 degrees% 再次把负的相位转化为正的相位% ----------------------------------------------------------------------------% --------------------------------------------- %% QDPSK解调%% --------------------------------------------- %base_phase = 360 /2^bits_per_symbol;delta_phase = base_phase /2;Rx_decoded_symbols = zeros(size(Rx_decoded_phase,1),size(Rx_decoded_phase,2)) ;%for i = 1: (2^bits_per_symbol - 1)center_phase = base_phase*i;plus_delta = center_phase + delta_phase; % Decision threshold 1minus_delta = center_phase - delta_phase; % Decision threshold 2decoded = find((Rx_decoded_phase <= plus_delta)&(Rx_decoded_phase > minus_delta)) ;Rx_decoded_symbols(decoded) = i;end% ----------------------------------------------------------------------------% 仅仅对三个区域进行判决% 剩下的区域就是零相位的空间了% 这个区域在定义解调矩阵时已经定义为零% ----------------------------------------------------------------------------Rx_serial_symbols = reshape(Rx_decoded_symbols',1,size(Rx_decoded_symbols, 1)*size(Rx_decoded_symbols,2)) ;for i = bits_per_symbol: -1: 1if i ~= 1Rx_binary_matrix(i, : ) = rem(Rx_serial_symbols, 2) ;Rx_serial_symbols = floor(Rx_serial_symbols/2) ;elseRx_binary_matrix( i, : ) = Rx_serial_symbols;endend % Integer to binarybaseband_in = reshape(Rx_binary_matrix, 1,size(Rx_binary_matrix, 1)*size(Rx_binary_matrix, 2) ) ; % --------------------------------------------- %% 误码率计算%% --------------------------------------------- %bit_errors = find(baseband_in ~= baseband_out) ; % find的结果其每个元素为满足逻辑条件的输入向量的标号,其向量长度也就是收发不一样的bit的个数bit_error_count = size(bit_errors, 2) ;total_bits = size( baseband_out, 2) ;bit_error_rate = bit_error_count/ total_bits;fprintf ( '%f \n',bit_error_rate) ;。

基于MATLAB的OFMD仿真实验-OFDM关键技术

基于MATLAB的OFMD仿真实验-OFDM关键技术

Remove short trainings
test_fine_time_sync.m
Coarse vs. Fine Time Sync
Coarse sync:
Large Range (Rc) Multiplication: 2Rc
Fine sync:
Small Range (Rf) Multiplication: Rf NL
Fine Timing Synchronization
Tx training sequence c0, c1,......, cLTB 1
Rx match filter with
c0*
,
c1*
,
......,
c* LTB
1
OFDM Signal
c0*
Tsample c1*
Tsample ……
Tsample c*
LTB 1
Start index
Max()
Fine Timing Synchronization
conj
sum
Max
Cross correlation with long training sequence
Find the maximum correlated point
CFO has been compensated
test_channel_est.m test_channel_equ.m
Zero Forcing Equalization
Phase Compensation
test_phase_track.m
做补偿:*exp(-j*Phase) 这部分可以不作为重点
freq_data [52,Nsym]
Data subcarriers freq_data_syms [48, Nsym]

ofdm matlab代码

ofdm matlab代码

end
%********************** Output result ***************************
per=eop/nop;
ber=noe/nod;
fprintf('%f\t%e\t%e\t%d\t\n',ebn0,ber,per,nloop);
% direct wave.
itau = [0];
% Mean power for each multipath normalized by direct wave.
% If you would like to simulate under one path fading model, you have only to set
% You can insert your favorite value
fd=320;
% You can decide two mode to simulate fading by changing the variable flat
% flat : flat fading or not
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;
[demodata]=qpskdemod(ich7,qch7,para,nd,ml);

基于matlab实现OFDM的编码.

基于matlab实现OFDM的编码.

clc;clear all;close all;fprintf('OFDM系统仿真\n');carrier_count=input('输入系统仿真的子载波数: \n');%子载波数128,64,32,16 symbols_per_carrier=30;%每子载波含符号数bits_per_symbol=4;%每符号含比特数,16QAM调制IFFT_bin_length=1024;%FFT点数PrefixRatio=1/4;%保护间隔与OFDM数据的比例1/6~1/4GI=PrefixRatio*IFFT_bin_length ;%每一个OFDM符号添加的循环前缀长度为1/4*IFFT_bin_length ,即256beta=1/32;%窗函数滚降系数GIP=beta*(IFFT_bin_length+GI);%循环后缀的长度40SNR=10; %信噪比dB%================信号产生=================================== baseband_out_length=carrier_count*symbols_per_carrier*bits_per_symbol;%所输入的比特数目carriers=(1:carrier_count)+(floor(IFFT_bin_length/4)-floor(carrier_count/2));%共轭对称子载波映射复数数据对应的IFFT点坐标conjugate_carriers = IFFT_bin_length - carriers + 2;%共轭对称子载波映射共轭复数对应的IFFT点坐标rand( 'twister',0); %每次产生不相同得伪随机序列baseband_out=round(rand(1,baseband_out_length));%产生待调制的二进制比特流figure(1);stem(baseband_out(1:50));title('二进制比特流')axis([0, 50, 0, 1]);%==============16QAM调制==================================== complex_carrier_matrix=qam16(baseband_out);%列向量complex_carrier_matrix=reshape(complex_carrier_matrix',carrier_count,symbols_per_carrier)';%串并转换,转换为symbols_per_carrier*carrier_count 矩阵figure(2);plot(complex_carrier_matrix,'*r');%16QAM调制后星座图title('16QAM调制后星座图')axis([-4, 4, -4, 4]);grid on%==========分配载波到指定的IFFT位置========================== IFFT_modulation=zeros(symbols_per_carrier,IFFT_bin_length);%添0组成IFFT 运算IFFT_modulation(:,carriers ) = complex_carrier_matrix ;%未添加导频信号,子载波映射在此处IFFT_modulation(:,conjugate_carriers) =conj(complex_carrier_matrix);%共轭复数映射figure(3);stem(0:IFFT_bin_length-1, abs(IFFT_modulation(2,1:IFFT_bin_length)),'b*-')grid onaxis ([0 IFFT_bin_length -0.5 4.5]);ylabel('幅值');xlabel('频率');title('OFDM载波幅度谱');figure(4);plot(0:IFFT_bin_length-1,(180/pi)*angle(IFFT_modulation(2,1:IFFT_bin_length)),'go')hold onstem(0:carriers-1, (180/pi)*angle(IFFT_modulation(2,1:carriers)),'b*-');stem(0:conjugate_carriers-1,(180/pi)*angle(IFFT_modulation(2,1:conjugate_carriers)),'b*-');axis ([0 IFFT_bin_length -200 +200])grid onylabel('相位')xlabel('频率')title('OFDM载波相位谱')%========通过IFFT将频域转化为时域,得到时域信号=============== signal_after_IFFT=ifft(IFFT_modulation,IFFT_bin_length,2);%OFDM调制即IFFT time_wave_matrix =signal_after_IFFT;%时域波形矩阵,行为每载波所含符号数,列ITTF点数,子载波映射在其内,每一行即为一个OFDM符号figure(5);plot(0:IFFT_bin_length-1,time_wave_matrix(2,:));axis([0, 700, -0.2, 0.2]);grid on;ylabel('振幅');xlabel('时间');title('一个符号周期的时域OFDM信号');%==========添加循环前缀与后缀==========================XX=zeros(symbols_per_carrier,IFFT_bin_length+GI+GIP);for k=1:symbols_per_carrier;for i=1:IFFT_bin_length;XX(k,i+GI)=signal_after_IFFT(k,i);endfor i=1:GI;XX(k,i)=signal_after_IFFT(k,i+IFFT_bin_length-GI);%添加循环前缀endfor j=1:GIP;XX(k,IFFT_bin_length+GI+j)=signal_after_IFFT(k,j);%添加循环后缀endendtime_wave_matrix_cp=XX;%添加了循环前缀与后缀的时域信号矩阵,此时一个OFDM符号长度为IFFT_bin_length+GI+GIPfigure(6);plot(0:length(time_wave_matrix_cp)-1,time_wave_matrix_cp(2,:));axis([0, 700, -0.2, 0.2]);grid on;ylabel('振幅');xlabel('时间');title('加入循环前缀后缀的OFDM波形');%==============OFDM符号加窗======================windowed_time_wave_matrix_cp=zeros(1,IFFT_bin_length+GI+GIP);for i = 1:symbols_per_carrierwindowed_time_wave_matrix_cp(i,:) = real(time_wave_matrix_cp(i,:)).*rcoswindow(beta,IFFT_bin_length+GI)';%加窗升余弦窗endfigure(7);plot(0:IFFT_bin_length-1+GI+GIP,windowed_time_wave_matrix_cp(2,:));axis([0, 700, -0.2, 0.2]);grid on;ylabel('振幅');xlabel('时间');title('加窗之后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,:);for i = 1:symbols_per_carrier-1 ;windowed_Tx_data((IFFT_bin_length+GI)*i+1:(IFFT_bin_length+GI)*(i+1)+GIP)= windowed_time_wave_matrix_cp(i+1,:);%循环后缀与循环前缀相叠加end%=======================并串转换=========================Tx_data_withoutwindow=reshape(time_wave_matrix_cp',(symbols_per_carrier)*(IFFT_bin_length+GI+GIP), 1)'; %不加窗,循环前缀与后缀不叠加的串行信号Tx_data=reshape(windowed_time_wave_matrix_cp',(symbols_per_carrier)*(IFFT_bi n_length+GI+GIP),1)';%加窗后,循环前缀与后缀不叠加的串行信号temp_time1 = (symbols_per_carrier)*(IFFT_bin_length+GI+GIP);%加窗后循环前缀与后缀不叠加发送总位数figure (8)subplot(2,1,1);plot(0:temp_time1-1,Tx_data);%循环前缀与后缀不叠加发送的信号波形axis([0, 8000, -0.4, 0.4]);grid onylabel('振幅');xlabel('时间');title('循环前后缀不叠加的OFDM信号')temp_time2 =symbols_per_carrier*(IFFT_bin_length+GI)+GIP;subplot(2,1,2);plot(0:temp_time2-1,windowed_Tx_data);%循环后缀与循环前缀相叠加发送信号波形axis([0, 8000, -0.4, 0.4]);grid onylabel('振幅'); xlabel('时间');title('循环前后缀叠加的OFDM信号')%=================未加窗发送信号频谱========================= symbols_per_average = ceil(symbols_per_carrier/5);avg_temp_time = (IFFT_bin_length+GI+GIP)*symbols_per_average;averages = floor(temp_time1/avg_temp_time);average_fft(1:avg_temp_time) = 0;for a = 0:(averages-1)subset_ofdm= Tx_data_withoutwindow (((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);endaverage_fft_log = 20*log10(average_fft);figure (9)subplot(2,1,1);plot((0:(avg_temp_time-1))/avg_temp_time, average_fft_log)hold onplot(0:1/IFFT_bin_length:1, -35, 'rd')grid onaxis([0 0.5 -40 max(average_fft_log)])ylabel('幅值(dB)')xlabel('归一化频率(0.5 = fs/2)')title('OFDM不加窗信号频谱')%===============加窗的发送信号频谱======================= symbols_per_average = ceil(symbols_per_carrier/5);%符号数的1/5avg_temp_time = (IFFT_bin_length+GI+GIP)*symbols_per_average;%点数averages = floor(temp_time1/avg_temp_time);average_fft(1:avg_temp_time) = 0;%分成5段for a = 0:(averages-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);%总共的数据分为5段,分段进行FFT,平均相加endaverage_fft_log = 20*log10(average_fft);subplot(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_timehold onplot(0:1/IFFT_bin_length:1, -35, 'rd')grid onaxis([0 0.5 -40 max(average_fft_log)])ylabel('幅值(dB)')xlabel('归一化频率(0.5 = fs/2)')title('OFDM加窗信号频谱')%====================添加噪声=================================Tx_signal_power = var(windowed_Tx_data);%发送信号功率linear_SNR=10^(SNR/10);%线性信噪比noise_sigma=Tx_signal_power/linear_SNR;noise_scale_factor = sqrt(noise_sigma);%标准差sigmanoise=randn(1,((symbols_per_carrier)*(IFFT_bin_length+GI))+GIP)*noise_scale_fac tor;%产生正态分布噪声序列Rx_data=windowed_Tx_data +noise;%接收到的信号加噪声%============接收信号串并变换去除前缀与后缀===================Rx_data_matrix=zeros(symbols_per_carrier,IFFT_bin_length+GI+GIP);for i=1:symbols_per_carrier;Rx_data_matrix(i,:)=Rx_data(1,(i-1)*(IFFT_bin_length+GI)+1:i*(IFFT_bin_length+ GI)+GIP);%串并变换endRx_data_complex_matrix=Rx_data_matrix(:,GI+1:IFFT_bin_length+GI);%去除循环前缀与循环后缀,得到有用信号矩阵% OFDM解码%=================FFT变换=================================Y1=fft(Rx_data_complex_matrix,IFFT_bin_length,2);%OFDM解码即FFT变换Rx_carriers=Y1(:,carriers);%除去IFFT/FFT变换添加的0,选出映射的子载波Rx_phase =angle(Rx_carriers);%接收信号的相位Rx_mag = abs(Rx_carriers);%接收信号的幅度figure(10);polar(Rx_phase, Rx_mag,'bd');%极坐标中接收信号的星座图title('极坐标中接收信号的星座图')[M, N]=pol2cart(Rx_phase, Rx_mag);Rx_complex_carrier_matrix = complex(M, N);figure(11);plot(Rx_complex_carrier_matrix,'*r');%直角坐标系中接收信号的星座图title('直角坐标系中接收信号的星座图')axis([-4, 4, -4, 4]);grid on%====================并串转换,16qam解调====================== 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=demoduqam16(Rx_serial_complex_symbols); baseband_in = Rx_decoded_binary_symbols;figure(12);subplot(2,1,1);stem(baseband_out(1:100));title('输出待调制的二进制比特流')subplot(2,1,2);stem(baseband_in(1:100));title('接收解调后的二进制比特流')%================误码率计算=======================bit_errors=find(baseband_in ~=baseband_out);bit_error_count = size(bit_errors, 2)ber=bit_error_count/baseband_out_length。

基于matlab ofdm通信系统仿真代码

基于matlab ofdm通信系统仿真代码

基于matlab ofdm通信系统仿真代码
OFDM通信系统仿真模拟是以正交频分复用技术(OFDM)作为主要的信号传输技术,在实现对无线信号的检测、编码、调制、叠加噤等功
能时可以通过Matlab等软件来进行模拟仿真。

仿真工作首先建立OFDM系统的信号模型,OFDM的原理是通过将
一个OFDM信号分成多个相互正交的子载波,并在每个子载波上实现移相、移幅调制,从而在信道上传输多路符号。

由于子载波之间相互正交,故可以实现多路数据同时传输,从而提高数据传输率和传输容量。

仿真建模过程中,首先根据要求确定可用的OFDM子载波数目以
及子载波的调制方式。

然后设定数据信道的配置,选择需要用到的信
道编码,这些元素将影响OFDM系统的信噪比和数据传输率。

最后定义
噪声接收,模拟噪声叠加,并实现对接收端信号的处理,存储等步骤。

通过上述步骤,系统建模工作就完成了。

之后可以使用Matlab
对模型进行仿真,看看OFDM系统表现如何。

仿真结果可以以图像的形
式显示出来,从而更好地理解传输的性能,从而有利于调整系统参数,提高系统的效率和可靠性。

MATLAB实验OFDM误码率仿真(AWGN)

MATLAB实验OFDM误码率仿真(AWGN)

和梳状导频两种,本次实验中插入的是块状导频,所谓的块状分布就是指导频在时域周期 性的分配给 OFDM 符号,这种导频分布模式特别适用于慢衰落的无线信道,由于训练符号包 含了所有的导频,所以在频域就不需要插值,因此这种导频分布模式对频率选择性衰落相 对不敏感。 4、 IFFT 和插入保护间隔: OFDM 信号的调制表达式和信号的 IFFT 的表达式相吻合, 所以 OFDM 信号的调制可以通过 IFFT 来实现。 由于无线信道存在多径时延现象, 从而会产生码间干扰, 为了克服这种影响,可以再每个 OFDM 符号前面加入一段循环前缀,理论上只要循环前缀的 长度大于最大时延扩展,则能克服多径时延,从而消除了码间干扰。加入循环前缀之后再 对信号进行并串转换,此时得到的信号就是待发送信号。 5、信道建模:得到的待发送信号要通过信道到达接收端,因此在理论研究中要进行信道建 模,从而模拟信号真实的传播环境。本次实验中涉及到的信道为 AWGN 信道和瑞利衰落信道 信号经过信道后要经历的处理大致为发射端的逆过程,与发射端不同的是,在接收端存在 信道估计。 6、信道估计:无线信道的基本特性就是存在不稳定性,信号经过信道后可能会产生多径时 延、多普勒频移、相偏等现象。因此信号经过信道后会产生严重的失真,如果在接收端我 们知道信道的特性,也就是说,我们知道信道对信号的影响,那么我们就能将信道对信号 的影响去除掉。而在接收端信道的特性是通过信道估计来得到的。信道估计一般可以分为 盲信道估计和非盲信道估计,前者即通过接收信号的统计特性来得到信道的特性,这种方 法计算比较复杂,而且精度不高;基于训练序列的信道估计即为在发送端发送一些已知的 序列,接收端利用这些已知序列的接收信号来对信道进行估计,传统的估计方法有 LS 算法 和 MMSE 算法。
四、实验报告要求

ofdm的matlab例程

ofdm的matlab例程

OFDM(Orthogonal Frequency Division Multiplexing)是一种无线通信技术OFDM (Orthogonal Frequency Division Multiplexing)是一种无线通信技术,它将多个数据流映射到不同的子载波上,从而实现高带宽和低干扰的传输。

以下是一个简单的OFDM MATLAB例程:```matlab参数设置N = 1024; 符号数M = 8; 子载波数SNR = 10; 信噪比(dB)data_length = 1000; 数据长度生成随机数据data = randi([0, 1], 1, data_length);初始化OFDM信号ofdm_signal = zeros(1, N);将数据映射到子载波上for i = 1:data_lengthsymbol_index = mod(i-1, M) + 1;ofdm_signal(symbol_index) = data(i);end添加循环前缀cp = randi([0, 1], 1, M);ofdm_signal = [cp, ofdm_signal];添加频偏补偿码pilot_sequence = randi([0, 1], 1, M);pilot_symbols = zeros(1, N);pilot_symbols(mod(1:N, M) + 1) = pilot_sequence;生成OFDM调制信号modulated_signal = ifft(fft(ofdm_signal).*fft(pilot_symbols));添加高斯白噪声noise = awgn(modulated_signal, SNR, 'measured');接收信号received_signal = ifft(fft(noise).*fft(pilot_symbols));received_signal = received_signal(M+1:end);去除循环前缀received_signal = received_signal(cp+1:end);解调并提取数据demodulated_signal = fft(received_signal).*fft(pilot_symbols);demodulated_data = real(ifft(demodulated_signal));计算误比特率error_bits = sum(abs(data - demodulated_data));ber = error_bits / data_length;disp(['误比特率:', num2str(ber)]);```这个例程首先生成随机数据,然后将其映射到子载波上,接着添加循环前缀、频偏补偿码和高斯白噪声。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
figure(2);
plot(complex_carrier_matrix,'*r');%16QAM调制后星座图
title('16QAM调制后星座图')
axis([-4, 4, -4, 4]);
grid on
%==========分配载波到指定的IFFT位置==========================
clc;
clear all;
close all;
fprintf('OFDM系统仿真\n');
carrier_count=input('输入系统仿真的子载波数: \n');%子载波数128,64,32,16
symbols_per_carrier=30;%每子载波含符号数
bits_per_symbol=4;%每符号含比特数,16QAM调制
end
figure(7);
plot(0:IFFT_bin_length-1+GI+GIP,windowed_time_wave_matrix_cp(2,:));
axis([0, 700, -0.2, 0.2]);
grid on;
ylabel('振幅');
xlabel('时间');
title('加窗之后OFDM信号的波形');
%==============16QAM调制====================================
complex_carrier_matrix=qam16(baseband_out);%列向量
complex_carrier_matrix=reshape(complex_carrier_matrix',carrier_count,symbols_per_carrier)';%串并转换,转换为symbols_per_carrier*carrier_count矩阵
IFFT_bin_length=1024;%FFT点数
PrefixRatio=1/4;%保护间隔与OFDM数据的比例1/6~1/4
GI=PrefixRatio*IFFT_bin_length ;%每一个OFDM符号添加的循环前缀长度为1/4*IFFT_bin_length ,即256
beta=1/32;%窗函数滚降系数
XX=zeros(symbols_per_carrier,IFFT_bin_length+GI+GIP);
for k=1:symbols_per_carrier;
for i=1:IFFT_bin_length;
XX(k,i+GI)=signal_after_IFFT(k,i);
end
for i=1:GI;
XX(k,i)=signal_after_IFFT(k,i+IFFT_bin_length-GI);%添加循环前缀
end
for j=1:GIP;
XX(k,IFFT_bin_length+GI+j)=signal_after_IFFT(k,j);%添加循环后缀
end
end
time_wave_matrix_cp=XX;%添加了循环前缀与后缀的时域信号矩阵,此时一个OFDM符号长度为IFFT_bin_length+GI+GIP
for i = 1:symbols_per_carrier-1 ;
windowed_Tx_data((IFFT_bin_length+GI)*i+1:(IFFT_bin_length+GI)*(i+1)+GIP)=windowed_time_wave_matrix_cp(i+1,:);%循环后缀与循环前缀相叠加
title('OFDM载波相位谱')
%========通过IFFT将频域转化为时域,得到时域信号===============
signal_after_IFFT=ifft(IFFT_modulation,IFFT_bin_length,2);%OFDM调制即IFFT time_wave_matrix =signal_after_IFFT;%时域波形矩阵,行为每载波所含符号数,列ITTF点数,子载波映射在其内,每一行即为一个OFDM符号
Tx_data=reshape(windowed_time_wave_matrix_cp',(symbols_per_carrier)*(IFFT_bin_length+GI+GIP),1)';%加窗后,循环前缀与后缀不叠加的串行信号
temp_time1 = (symbols_per_carrier)*(IFFT_bin_length+GI+GIP);%加窗后循环前缀与后缀不叠加发送总位数
grid on
ylabel('振幅'); xlabel('时间');
title('循环前后缀叠加的OFDM信号')
%=================未加窗发送信号频谱=========================
symbols_per_average = ceil(symbols_per_carrier/5);
%==============OFDM符号加窗======================
windowed_time_wave_matrix_cp=zeros(1,IFFT_bin_length+GI+GIP);
for i = 1:symbols_per_carrier
windowed_time_wave_matrix_cp(i,:) = real(time_wave_matrix_cp(i,:)).*rcoswindow(beta,IFFT_bin_length+GI)';%加窗升余弦窗
GIP=beta*(IFFT_bin_length+GI);%循环后缀的长度40
SNR=10; %信噪比dB
%================信号产生===================================
baseband_out_length=carrier_count*symbols_per_carrier*bits_per_symbol;%所输入的比特数目
temp_time2 =symbols_per_carrier*(IFFT_bin_length+GI)+GIP;
subplot(2,1,2);
plot(0:temp_time2-1,windowed_Tx_data);%循环后缀与循环前缀相叠加发送信号波形
axis([0, 8000, -0.4, 0.4]);
end
average_fft_log = 20*log10(average_fft);
figure (9)
subplot(2,1,1);
plot((0:(avg_temp_time-1))/avg_temp_time, average_fft_log)
hold on
plot(0:1/IFFT_bin_length:1, -35, 'rd')
subset_ofdm= Tx_data_withoutwindow (((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);
avg_temp_time = (IFFT_bin_length+GI+GIP)*symbols_per_average;
averages = floor(temp_time1/avg_temp_time);
average_fft(1:avg_temp_time) = 0;
for a = 0:(averages-1)
figure(6);
plot(0:length(time_wave_matrix_cp)-1,time_wave_matrix_cp(2,:));
axis([0, 700, -0.2, 0.2]);
grid on;
ylabel('振幅');
xlabel('时间');
title('加入循环前缀后缀的OFDM波形');
IFFT_modulation=zeros(symbols_per_carrier,IFFT_bin_length);%添0组成IFFT运算
IFFT_modulation(:,carriers ) = complex_carrier_matrix ;%未添加导频信号,子载波映射在此处
IFFT_modulation(:,conjugate_carriers) =conj(complex_carrier_matrix);%共轭复数映射
end
%=======================并串转换=========================
Tx_data_withoutwindow=reshape(time_wave_matrix_cp',(symbols_per_carrier)*(IFFT_bin_length+GI+GIP),1)'; %不加窗,循环前缀与后缀不叠加的串行信号
figure(5);
plot(0:IFFT_bin_length-1,time_wave_matrix(2,:));
axis([0, 700, -0.2, 0.2]);
相关文档
最新文档