You are on page 1of 2

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Final Project: F04; Statistical Signal Processing for Communications


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all;
close all;
clc;
%-------------Parameters----------------
M = 16; % constellation size 16-QAM
k=log2(M);
c_real=1000; %number of different channel realizations
N=64; %IFFT/FFT length
L=16; %cyclic prefix length
l_path=L+1;
Eb_N0_dB=0:5:30;
Es_N0_dB = Eb_N0_dB + 10*log10(k);
Nb=k*c_real*N;
n_code=15;
k_code=7; % 11

for i = 1:length(Eb_N0_dB)
err(i)=0;
end

for i = 1:length(Eb_N0_dB)

%---------------Transmitter---------------

% Symbol Generation
sig_bit=rand(1,Nb,1)>0.5; % random 1's and 0's

% BCH coder
[code_bit, added] = encode(sig_bit, n_code, k_code,'Linear block');

% Interleaver
sig_inter = interleaving(l_row,k_column,sig_bit)

% mapping
sig_mapped=mapping(sig_inter,M); %mapping using Gray code
% group to n_real groupe of N symbols for doing ifft
sig_mapped = reshape(sig_mapped,N,c_real);

% do ifft and normalization


sig_ifft = ifft(sig_mapped)*sqrt(N);

% add cyclic prefix


sig_prefix = [ sig_ifft(N-L+1:N,:) ; sig_ifft ];

%----------------Noise-----------------

k_=sqrt(10);
s=sig_mapped/k_;

% Generate random channel coefficients (Rayleigh fading)


ht = 1/sqrt(2*l_path)*( randn(l_path,c_real) + j*randn(l_path,c_real) );

% Calculate frequency response


h_pad = [ht ; zeros(N-l_path,c_real)];
hf = fft(h_pad);

% Compute the effect of the multipath channel on the signal


for j=1:c_real
sig_multipath(:,j) = conv( sig_prefix(:,j) , ht(:,j) );
end

% AWGN noise
[row col] = size(sig_multipath); %find the size of sig_multipath, (col =
c_real)
noise = 1/sqrt(2)*[randn(row,col) + j*randn(row,col)]; % white guassian
noise, 0dB variance
x=10.^(-Es_N0_dB/20);
n=noise*x(i);
sig_afterchan = sig_multipath + noise;

% Remove last l_path-1 received values resulting from convolution


sig_afterchan(end-l_path+2:end,:) = [];

% -------------RECEIVER--------------

% Remove cyclic prefix


sig_unprefix = sig_afterchan(L+1:end,:);

% do fft and normalize with factor sqrt(N)


sig_fft = fft(sig_unprefix)/sqrt(N);

% zero forcing
sig_zfe = sig_fft./hf;

% Reshape sig_zfe for doing demodulation


sig_zfe = sig_zfe(:);

%Do QPSK/QAM demodulation


sig_demapped = demap_qam(sig_zfe,M);
% Do deblock-interleaving

% counting errors
err(i) = sum(abs(sig_demapped-sig_bit));
end

You might also like