ylabel('Amplitude') xlabel('Time')
title('OFDM Time Signal, One Symbol Period') %画出每一个载波对应的时域信号(分离的OFDM信号) for f = 1:carrier_count
temp_bins(1:IDFT_bin_length)=0+0j;
temp_bins(carriers(f))=IDFT_modulation(2,carriers(f));
temp_bins(conjugate_carriers(f))=IDFT_modulation(2,conjugate_carriers(f));
temp_time = idft(temp_bins'); figure(3)
plot(0:IDFT_bin_length-1, temp_time) hold on end grid on
ylabel('Amplitude') xlabel('Time')
title('Separated Time Waveforms Carriers') for i = 1:symbols_per_carrier + 1
windowed_time_wave_matrix(i,:)=real(time_wave_matrix(i,:)).*hamming(IDFT_bin_length)';
windowed_time_wave_matrix(i,:) = real(time_wave_matrix(i,:)); end %串并转换
ofdm_modulation=reshape(windowed_time_wave_matrix',1,IDFT_bin_length*(symbols_per_carrier+1)); % 画出整个时域OFDM
temp_time = IDFT_bin_length*(symbols_per_carrier+1); figure (4)
plot(0:temp_time-1,ofdm_modulation) grid on
ylabel('Amplitude (volts)') xlabel('Time (samples)') title('OFDM Time Signal')
% 上变频,这个模型中我们把经过IFFT运算后OFDM直接发送 Tx_data = ofdm_modulation; %信道
% The channel model is Gaussian (AWGN) +Multipath(时延为1) 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))*noise_scale_factor; copy1=zeros(1,length(ofdm_modulation)); for i=2:length(ofdm_modulation) copy1(i)=ofdm_modulation(i-1); end
Rx_Data = Tx_data + noise;
% 根据符号长度和符号数将串行的符号转换为并行的 % - 每一列是符号周期
Rx_Data_matrix=reshape(Rx_Data,IDFT_bin_length, symbols_per_carrier + 1); %对每一列信号做FFT得到频域信号 Rx_spectrum = dft(Rx_Data_matrix); % 抽取接收信号中有载波的点
Rx_carriers = Rx_spectrum(carriers,:)'; % 计算载波的相位 % - 弧度转换为角度 % - 归一化相位(0-360)
Rx_phase = angle(Rx_carriers)*(180/pi); phase_negative = find(Rx_phase < 0);
Rx_phase(phase_negative) = rem(Rx_phase(phase_negative)+360,360); % 用diff()计算相位差
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); % 相位转化为符号
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; minus_delta = center_phase-delta_phase;
decoded=find((Rx_decoded_phase<=plus_delta)&(Rx_decoded_phase>minus_delta));
Rx_decoded_symbols(decoded)=i; end
% Convert the matrix into a serial symbol stream
Rx_serial_symbols=reshape(Rx_decoded_symbols',1,size(Rx_decoded_symbols,1)*size(Rx_decoded_symbols,2)); % Convert the symbols to binary 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)*size(Rx_binary_matrix,2)); % 查找错位比特计算误码率
bit_errors = find(baseband_in ~= baseband_out); bit_error_count = size(bit_errors,2) baseband_out_length k=bit_error_count b=baseband_out_length ber=k/b
OFDM系统原理及其实现
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)