OFDM仿真

理论懒得推了,直接上代码吧。图也不上了,自己去画吧。


close all

%% generate data source and map them to qpsk symbols
N = 512; 
M = 4; 
src = randi([1, M], N,1); 
qpsk_set = [1+1i -1+1i -1-1i 1-1i]'; 
src_sym =  qpsk_set(src); 

%% ifft and add cp
cp_len = 32; 
src_mod = ifft(src_sym); 
src_mod = src_mod / max(abs(src_mod)); 
src_wave = [src_mod(end-cp_len+1:end); src_mod]; % add cp

%% transmit sig through channel (isi and noise)
h = [0.9 0.4 0.1]'; 
rx_wave = conv(src_wave, h); 
noise = randn(size(rx_wave)) / 1e15;
rx_wave = rx_wave + noise; 

%% remove cp and fft 
sample_start = cp_len; 
rx_2fft = rx_wave(sample_start + 1:sample_start + N); % remove cp
rx_fft = fft(rx_2fft);  

%% phase rotation compensation 
h_inverse_tmp1 = exp(-2*1i*pi*(0:N-1)'/N); 
h_inverse_tmp2 = h_inverse_tmp1.^2; 
h_inverse = 1 ./ ( 0.9 + 0.4 * h_inverse_tmp1 + 0.1 * h_inverse_tmp2 ); 
hat_src = h_inverse .* rx_fft; 

%% plot result
figure;
plot(src_sym,'ro'); 
figure; 
plot(hat_src,'b*'); 


转载于:https://www.cnblogs.com/songtianyu/p/7192534.html

你可能感兴趣的:(OFDM仿真)