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

📄 untitled5.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=') ;
for chi=1:5
for SNR=1:1:10
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);
for k = 1:(length(baseband_out)/bits_per_symbol)
    modulo_baseband(k)=0;
    for i=1:bits_per_symbol
        modulo_baseband(k) = modulo_baseband(k)+convert_matrix(i,k)*2^(bits_per_symbol-i);
    end
end
carrier_matrix=reshape(modulo_baseband,carrier_count,symbols_per_carrier)';
% 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*((2*pi)/(2^bits_per_symbol));
[X, Y]=pol2cart(carrier_matrix,ones(size(carrier_matrix,1),size(carrier_matrix,2)));
complex_carrier_matrix = complex(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=2*(rand(1,200)>0.5)-1;
training_symbols=cat(1,training_symbols,training_symbols);
training_symbols=cat(1,training_symbols,training_symbols);
complex_carrier_matrix=cat(1,training_symbols,complex_carrier_matrix);
IFFT_modulation=zeros(4+symbols_per_carrier+1,IFFT_bin_length);
IFFT_modulation(:,carriers)=complex_carrier_matrix;
IFFT_modulation(:,conjugate_carriers)=conj(complex_carrier_matrix);
time_wave_matrix=ifft(IFFT_modulation');
time_wave_matrix=time_wave_matrix';
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_matrix',1,IFFT_bin_length*(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;
copy(1,:)=Tx_data;
copy(2,:)=zeros(size(Tx_data));
for i=1+d1:length(Tx_data)
    copy(2,i)=a1*Tx_data(i-d1);
end
copy(3,:)=zeros(size(Tx_data));
for i =1+d2:length(Tx_data)
    copy(3,i)=a2*Tx_data(i-d2);
end
copy(4,:)=zeros(size(Tx_data)) ;
for i=1+d3:length(Tx_data)
    copy(4,i)=a3*Tx_data(i-d3);
end
copy(5,:)=zeros(size(Tx_data) ) ;
for i=1 + d4:length( Tx_data)
    copy(5,i) = a4*Tx_data( i - d4) ;
end
Tx_data = Tx_data + copy(chi,:);
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;
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, : )';
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.*Rx_carriers;
Rx_phase = angle(Rx_carriers)*(180/pi) ;
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_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
Rx_serial_symbols = reshape(Rx_decoded_symbols',1,size (Rx_decoded_symbols, 1)*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)*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(SNR) = bit_error_count/ total_bits;
fprintf('% f \n',bit_error_rate(SNR)) ;
end
ber(chi,:)=bit_error_rate;
end
semilogy(ber');

grid
xlabel('SNR(dB)');
ylabel('BER');
title('4 way channel interference ')
legend('no noise','1 noise','2 noise','3 noise','4 noise')

⌨️ 快捷键说明

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