Hi guys this is "my first" ofdm code.could you tell me how it is and how to
add
the cyclic prefix?
Another question is:
in the function ifft should i insert the IFFT SIZE?
%--------1---------2---------3---------4---------5---------6---------7---------8
% OFDM Simulation
clear all;
close all;
%
% Basic OFDM system parameters
% - choice of defaults or user selections
%
fprintf ('OFDM Analysis Program\n\n');
defaults = input('To use default parameters, input "1", otherwise input
"0": ');
%
if defaults == 1
IFFT_bin_length = 1024; % IFFT bin count for Tx, FFT bin count for Rx
carrier_count = 200; % number of carriers
bits_per_symbol = 2; % bits per symbol
symbols_per_carrier = 50; % symbols per carrier
SNR = 10; % channel signal to noise ratio (dB)
else
IFFT_bin_length = input('IFFT bin length = ');
carrier_count = input('carrier count = ');
bits_per_symbol = input('bits per symbol = ');
symbols_per_carrier = input('symbols per carrier =');
SNR = input('SNR = ');
end
%
% Derived parameters
%
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
%
%
%--------1---------2---------3---------4---------5---------6---------7---------8
%
% TRANSMIT
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%
%
% Generate a random binary output signal:
% - a row of uniform random numbers (between 0 and 1), rounded to 0 or 1
% - this will be the baseband signal which is to be transmitted.
%
baseband_out = round(rand(1,baseband_out_length));
Baseband_out2= reshape(baseband_out,bits_per_symbol,symbols_per_carrier
*carrier_count)
h = modem.pskmod('M',2^bits_per_symbol, 'InputType',
'Bit');
Symbols_matrix=modulate(h,Baseband_out2);
scatterplot(Symbols_matrix)
% %
%
%--------1---------2---------3---------4---------5---------6---------7---------8
% %
% % Serial to Parallel Conversion
carrier_matrix = reshape(Symbols_matrix, carrier_count,
symbols_per_carrier)';
% %
%
%--------1---------2---------3---------4---------5---------6---------7---------8
% %
% % Zero Padding
IFFT_modulation = zeros(symbols_per_carrier , IFFT_bin_length);
IFFT_modulation(:,carriers) = carrier_matrix;
% %
%
%--------1---------2---------3---------4---------5---------6---------7---------8
% %
% % IFFT
%OFDM_SYM= ifft( IFFT_modulation,IFFT_bin_length )
OFDM_SYM2= ifft( IFFT_modulation);
%ofdm_msg_tx2 = reshape(OFDM_SYM, 1,IFFT_bin_length* symbols_per_carrier);
ofdm_msg_tx2 = reshape(OFDM_SYM2, 1,IFFT_bin_length* symbols_per_carrier);
% %awgn channel
ofdm_msg_rx2=awgn(ofdm_msg_tx2 ,SNR)
%%rx
ofdm_msg_rx3 = reshape(ofdm_msg_rx2, symbols_per_carrier,IFFT_bin_length);
%
OFDM_SYM2_rxt(ofdm_msg_rx3);
%
symbols_rx=OFDM_SYM2_rx(:,carriers)
symbols_rx2=reshape(symbols_rx,1,carrier_count * symbols_per_carrier)
scatterplot(symbols_rx2)