如何用matlab产生一个ofdm信号

如何用matlab产生一个ofdm信号,第1张

clear all

close all

Tu=224e-6%符号周宽滑期

T=Tu/2048%基带元素周期

G=1/4

delta=G*Tu

Ts=delta+Tu

Kmax=1705

Kmin=0

FS=4096

q=10

fc=q*1/T

Rs=4*fc

t=0:1/和巧毕Rs:Tu

M=Kmax+1

rand('state',0)

a=-1+2*round(rand(M,1)).'+i*(-1+2*round(rand(M,1))).'

A=length(a)

info=zeros(FS,1)

info(1:(A/2))=[a(1:(A/2)).'唤芹]

info((FS-((A/2)-1)):FS)=[a(((A/2)+1):A).']

carriers=FS.*ifft(info,FS)

tt=0:T/2:Tu

figure(1)

subplot(211)

stem(tt(1:20),real(carriers(1:20)))

subplot(212)

stem(tt(1:20),imag(carriers(1:20)))

figure(2)

f=(2/T)*(1:(FS))/(FS)

subplot(211)

plot(f,abs(fft(carriers,FS))/FS)

[Pxx,f]=pwelch(carriers,[],[],[],2/T)

plot_Pxx1=10*log10(Pxx)

subplot(212)

plot(f,plot_Pxx1)

L=length(carriers)

chips=[carriers.'zeros((2*q)-1,L)]

p=1/Rs:1/Rs:T/2

g=ones(length(p),1)

figure(3)

stem(p,g)

dummy=conv(g,chips(:))

u=[dummy(1:length(t))]

figure(4)

subplot(211)

plot(t(1:400),real(u(1:400)))

subplot(212)

plot(t(1:400),imag(u(1:400)))

figure(5)

ff=(Rs)*(1:(q*FS))/(q*FS)

subplot(211)

plot(ff,abs(fft(u,q*FS))/FS)

[Pxx,f]=pwelch(u,[],[],[],Rs)

plot_Pxx2=10*log10(Pxx)

subplot(212)

plot(f,plot_Pxx2)

[b,a]=butter(13,1/20)

[H,F]=FREQZ(b,a,FS,Rs)

figure(6)

plot(F,20*log10(abs(H)))

uoft=filter(b,a,u)

figure(7)

subplot(211)

plot(t(80:480),real(uoft(80:480)))

subplot(212)

plot(t(80:480),imag(uoft(80:480)))

figure(8)

subplot(211)

plot(ff,abs(fft(uoft,q*FS))/FS)

[Pxx,f]=pwelch(uoft,[],[],[],Rs)

plot_Pxx3=10*log10(Pxx)

plot(f,plot_Pxx3)

s_tilde=(uoft.').*exp(1i*2*pi*fc*t)

s=real(s_tilde)

figure(9)

plot(t(80:480),s(80:480))

figure(10)

subplot(211)

plot(ff,abs(fft(s,q*FS))/FS)

[Pxx,f]=pwelch(s,[],[],[],Rs)

plot_Pxx4=10*log10(Pxx)

subplot(212)

plot(f,plot_Pxx4)

figure(11)

subplot(211)

plot(ff,abs(fft(((real(uoft).').*cos(2*pi*fc*t)),q*FS))/FS)

figure(12)

subplot(211)

plot(ff,abs(fft(((imag(uoft).').*sin(2*pi*fc*t)),q*FS))/FS)

[Pxx,f]=pwelch(((imag(uoft).').*sin(2*pi*fc*t)),[],[],[],Rs)

plot_Pxx6=10*log10(Pxx)

subplot(212)

plot(f,plot_Pxx6)

%

可以试一试,具体的我也不是很懂

附 录程序:clear allclose allfprintf('OFDM信道估计仿真\n\n')carrier_count=64%-----------载波数目核岁num_symbol=50%--------------OFDM符号个数Guard=8%--------------------循环前缀pilot_Inter=8%--------------导频间隔modulation_mode=16%---------调制方式SNR=[0:2:20]%-------------信噪比取值NumLoop=15%-----------------循环次数num_bit_err=zeros(length(SNR),NumLoop)num_bit_err_dft=zeros(length(SNR),NumLoop)num_bit_err_ls=zeros(length(SNR),NumLoop)MSE=zeros(length(SNR),NumLoop)MSE1=zeros(length(SNR),NumLoop)MSE2=zeros(length(SNR),NumLoop)%%%%%%%%%%%%%%%%%%%%%%%主程序镇虚循环%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%for c1=1:length(SNR)fprintf('\n\n\n仿真信噪比为%f\n\n',SNR(c1))for num1=1:NumLoop%---------------产生发送的随机序列——————————改旅睁————-BitsLen=carrier_count*num_symbolBitsTx=randint(1,BitsLen)%---------------符号调制---------------------------------------Modulated_Sequence=qammod(BitsTx,modulation_mode)%---------------导频格式---------------------------------------pilot_len=carrier_countpilot_symbols=round(rand(1,pilot_len))for i=1:pilot_lenif pilot_symbols(1,i)==0pilot_symbols(1,i)=pilot_symbols(1,i)-1elsepilot_symbols(1,i)=pilot_symbols(1,i)endendpilot_symbols=pilot_symbols'%----------------计算导频和数据数目----------------------------num_pilot=ceil(num_symbol/pilot_Inter)if rem(num_symbol,pilot_Inter)==0num_pilot=num_pilot+1endnum_data=num_symbol+num_pilot%----------------导频位置计算----------------------------------pilot_Indx=zeros(1,num_pilot)Data_Indx=zeros(1,num_pilot*(pilot_Inter+1))for i=1:num_pilot-1pilot_Indx(1,i)=(i-1)*(pilot_Inter+1)+1endpilot_Indx(1,num_pilot)=num_datafor j=0:num_pilotData_Indx(1,(1+j*pilot_Inter):(j+1)*pilot_Inter)=(2+j*(pilot_Inter+1)):((j+1)*(pilot_Inter+1))endData_Indx=Data_Indx(1,1:num_symbol)%----------------导频插入-------------------------------------piloted_ofdm_syms=zeros(carrier_count,num_data)piloted_ofdm_syms(:,Data_Indx)=reshape(Modulated_Sequence,carrier_count,num_symbol)piloted_ofdm_syms(:,pilot_Indx)=repmat(pilot_symbols,1,num_pilot)%----------------IFFT变换———————————————————time_signal=sqrt(carrier_count)*ifft(piloted_ofdm_syms)%----------------加循环前缀------------------------------------add_cyclic_signal=[time_signal((carrier_count-Guard+1:carrier_count),:)time_signal]Tx_data_trans=reshape(add_cyclic_signal,1,(ca

rrier_count+Guard)*num_data)%----------------信道处理--------------------------------------Tx_signal_power=sum(abs(Tx_data_trans(:)).^2)/length(Tx_data_trans(:))noise_var=Tx_signal_power/(10^(SNR(c1)/10))Rx_data=awgn(Tx_data_trans,SNR(c1),'measured')%----------------信号接收、去循环前缀、FFT变换-----------------Rx_signal=reshape(Rx_data,(carrier_count+Guard),num_data)Rx_signal_matrix=zeros(carrier_count,num_data)Rx_signal_matrix=Rx_signal(Guard+1:end,:)Rx_carriers=fft(Rx_signal_matrix)/sqrt(carrier_count)%----------------导频和数据提取--------------------------------Rx_pilot=Rx_carriers(:,pilot_Indx)Rx_fre_data=Rx_carriers(:,Data_Indx)%----------------导频位置信道响应LS估计------------------------pilot_patt=repmat(pilot_symbols,1,num_pilot)pilot_esti=Rx_pilot./pilot_patt%----------------LS估计的线性插值———————————————int_len=pilot_Indxlen=1:num_datafor ii=1:carrier_countchannel_H_ls(ii,:)=interp1(int_len,pilot_esti(ii,1:(num_pilot)),len,'linear')endchannel_H_data_ls=channel_H_ls(:,Data_Indx)%----------------LS估计中发送数据的估计值----------------------Tx_data_estimate_ls=Rx_fre_data.*conj(channel_H_data_ls)./(abs(channel_H_data_ls).^2)%----------------DFT估计--------------------------------------Tx_pilot_estimate_ifft=ifft(pilot_esti)padding_zero=zeros(1024,7)Tx_pilot_estimate_ifft_padding_zero=[Tx_pilot_estimate_ifftpadding_zero]Tx_pilot_estimate_dft=fft(Tx_pilot_estimate_ifft_padding_zero)%----------------DFT估计的线性插值———————————————int_len=pilot_Indxlen=1:num_datafor ii=1:carrier_countchannel_H_dft(ii,:)=interp1(int_len,Tx_pilot_estimate_dft(ii,1:(num_pilot)),len,'linear')endchannel_H_data_dft=channel_H_dft(:,Data_Indx)%----------------DFT估计中发送数据的估计值----------------------Tx_data_estimate_dft=Rx_fre_data.*conj(channel_H_data_dft)./(abs(channel_H_data_dft).^2)%----------------DFT符号解调------------------------------------demod_in_dft=Tx_data_estimate_dft(:).'demod_out_dft=qamdemod(demod_in_dft,modulation_mode)%----------------LS符号解调------------------------------------demod_in_ls=Tx_data_estimate_ls(:).'demod_out_ls=qamdemod(demod_in_ls,modulation_mode)%----------------误码率的计算----------------------------------for i=1:length(BitsTx)if demod_out_dft(i)~=BitsTx(i)num_bit_err_dft(c1,num1)=num_bit_err_dft(c1,num1)+1endif dem

od_out_ls(i)~=BitsTx(i)num_bit_err_ls(c1,num1)=num_bit_err_ls(c1,num1)+1endendendendBER_dft=mean(num_bit_err_dft.')/length(BitsTx)BER_ls=mean(num_bit_err_ls.')/length(BitsTx)%%%%%%%%%%%%%%%%%%%a%%%%%%%%主程序循环换结束%%%%%%%%%%%%%%%%%%%%%%%%%%%%figuresemilogy(SNR,BER_dft,'-mp',SNR,BER_ls,'-k+')title('OFDM系统的LS和DFT信道估计')xlabel('SNR'),ylabel('BER')legend('LS信道估计','DFT信道估计')


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12460073.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存