⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ofdm1.m

📁 这些代码包括ofdm的实现和信道估计,可以运行,有指导程序的说明文档.
💻 M
字号:
clear all;
close all;
fprintf ('OFDM 仿真\n \n') ;
IFFT_bin_length = 1024;
carrier_count = 200;
bits_per_symbol = 2;
symbols_per_carrier = 50;
SNR = input ( 'SNR = ') ;
baseband_out_length = carrier_count * symbols_per_carrier*bits_per_symbol;

carriers = (1: carrier_count) + ( floor ( IFFT_bin_length /4)- floor ( carrier_count/2) ) ;

conjugate_carriers = IFFT_bin_length - carriers + 2;
% 信号发射
baseband_out = round ( rand (1, baseband_out_length) ) ;
convert_matrix = reshape ( baseband_out, bits_per_symbol,length ( baseband_out) /bits_per_symbol) ;
number=length (baseband_out) /bits_per_symbol;
for k = 1:number
     modulo_baseband(k) = 0;
 for i = 1: bits_per_symbol
      modulo_baseband ( k) = modulo_baseband ( k) +convert_matrix ( i, k) 3 2^( bits_per_symbol - i) ;

 end
end
carrier_matrix = reshape (modulo_baseband, carrier_ count,
symbols_per_carrier) p;
% QDPSK调制
carrier_matrix = [ zeros(1, carrier_count) ; carrier_ matrix];
for i = 2: ( symbols_per_carrier + 1)
 carrier_matrix( i, : ) = rem ( carrier_matrix( i, : ) + carrier_
matrix ( i - 1, : ) , 2^bits_per_symbol) ;
end
carrier_matrix = carrier_matrix 3 ( (23 p i) / (2^bits_per_
symbol) ) ;
[X, Y]  = pol2cart ( carrier_matrix, ones( size ( carrier_
matrix, 1) , size ( carrier_matrix, 2) ) ) ;
comp lex_carrier_matrix = comp lex(X, Y) ;
% 加训练序列
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 ];
training_symbols = cat(1, training_symbols, training_ symbols) ;
training_symbols = cat(1, training_symbols, training_ symbols) ;
comp lex_carrier_matrix = cat (1, training_symbols, comp lex_
carrier_matrix) ;
IFFT_modulation = zeros (4 + symbols_per_carrier + 1,
IFFT_bin_length) ;
IFFT_modulation (: , carriers) = comp lex_ carrier_ matrix;
IFFT_modulation (: , conjugate_carriers)
= conj ( comp lex _ carrier_matrix) ;
time_wave_matrix = ifft ( IFFT_modulationp) ;
time_wave_matrix = time_wave_matrixp;
for i = 1: 4 + symbols_per_carrier + 1
 windowed_time_wave_matrix( i, : ) = real ( time_wave
_matrix ( i, : ) ) ;
end
ofdm_modulation = reshape (windowed_time_wave_matrixp,
1, IFFT_bin_length3 (4 + symbols_per_carrier + 1) ) ;
Tx_data = ofdm_modulation;
% 信道
d1 = 4; a1 = 0. 2; d2 = 5; a2 = 0. 3; d3 = 6; a3 = 0. 4;
d4 = 7; a4 = 0. 5;
copy1 = zeros( size ( Tx_data) ) ;
for i = 1 + d1: length ( Tx_data)
 copy1 ( i) = a13 Tx_data ( i - d1) ;
end
copy2 = zeros( size ( Tx_data) ) ;
for i = 1 + d2: length ( Tx_data)
 copy1 ( i) = a23 Tx_data ( i - d2) ;
end
copy3 = zeros( size ( Tx_data) ) ;
for i = 1 + d3: length ( Tx_data)
 copy1 ( i) = a33 Tx_data ( i - d3) ;
end
copy4 = zeros( size ( Tx_data) ) ;
for i = 1 + d4: length ( Tx_data)
 copy1 ( i) = a43 Tx_data ( i - d4) ;
end
Tx_data = Tx_data + copy1 + copy2;
Tx_signal_power = var ( Tx_data) ;
linear_SNR = 10^( SNR /10) ;
noise_sigma = Tx_signal_power/ linear_SNR;
noise_scale_factor = sqrt ( noise_sigma) ;
noise = randn (1, length (Tx_data) ) 3 noise_scale_ factor;
Rx_Data = Tx_data + noise;
% 信号接收
Rx_Data_matrix = reshape (Rx_Data, IFFT_bin_length, 4 +
symbols_per_carrier + 1) ;
Rx_spectrum = fft (Rx_Data_matrix) ; %
Rx_carriers = Rx_spectrum ( carriers, : ) p;
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) ;
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. 3 Rx_carriers;
Rx_phase = angle (Rx_carriers) 3 (180 /p i) ;
phase_negative = find (Rx_phase < 0) ;
Rx_phase (phase_negative) =
rem (Rx_phase (phase_negative) + 360, 360) ;
Rx_decoded_phase = diff (Rx_phase) ;
phase_negative = find (Rx_decoded_phase < 0) ;
Rx_decoded_phase (phase_negative)
= rem (Rx_decoded_phase (phase_negative) + 360, 360) ;
% 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_phase3 i;
 p lus_delta = center_phase + delta_phase;
 minus_delta = center_phase - delta_phase;
 decoded = find ( (Rx_decoded_phase < = p lus_delta) &
(Rx_decoded_phase > minus_delta) ) ;
 Rx_decoded_symbols( decoded) = i;
end
Rx_serial_symbols = reshape (Rx_decoded_symbolsp,
1,
size (Rx_decoded_symbols, 1) 3 size (Rx_decoded_symbols,
2) ) ;
for i = bits_per_symbol: - 1: 1
 if i ~ = 1
  Rx_binary_matrix( i, : ) = rem (Rx_serial_ symbols, 2) ;
  Rx_serial_symbols = floor (Rx_serial_symbols/2) ;
else
  Rx_binary_matrix( i, : ) = Rx_serial_symbols;
 end
 end
baseband_in = reshape (Rx_binary_matrix, 1,
size (Rx_binary_matrix, 1) 3 size (Rx_binary_matrix, 2) ) ;
%误码率计算
bit_errors = find ( baseband_in ~ = baseband_out) ;
bit_error_count = size ( bit_errors, 2) ;
total_bits = size ( baseband_out, 2) ;
bit_error_rate = bit_error_count/ total_bits;
fp rintf ( p% f \np,
bit_error_rate) ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -