Sie sind auf Seite 1von 2

ASSIGNEMNT NO.

: 02
Title: MATLAB code for pilot based estimation in OFDM System.
% Error Probability Minimizing Pilots for
% OFDM with M-PSK Modulation over Rayliegh-Fading

% initialize
clear all
clc
% parameter definition
N = 4; % total number of subchannels
P = 16/4; % total number of Pilots
S = 4; % totla number of data subchannels
GI = N/4; % guard interval length
M = 4; % modulation
pilotInterval = 4; % pilot position interval
L = 4; % channel length
nIteration = 1; % number of iteration in each evaluation

SNR_V = [10:10:10]; % signal to noise ratio vector in dB


ber = zeros(1,length(SNR_V)); % initializing bit error rate

% Pilot Location and strength


Ip = [1:pilotInterval:N] % location of pilots
Is = setxor(1:N,Ip) % location of data

Ep = 2; % energy in pilot symbols in comparison


% to energy in data symbols

% fft matrix
F = exp(2*pi*sqrt(-1)/N .* meshgrid([0:N-1],[0:N-1])...
.* repmat([0:N-1]',[1,N]))

for( i = 1 : length(SNR_V))
SNR = SNR_V(i)
for(k = 1 : nIteration)
% generating random channel coefficients
h(1:L,1) = random('Normal',0,1,L,1) + ...
j * random('Normal',0,1,L,1)
h = h./sum(abs(h)) % normalization

% Tr Data
TrDataBit = randint(N,1,M)
TrDataMod = qammod(TrDataBit,M);
TrDataMod(Ip) = Ep * TrDataMod(Ip);
TrDataIfft = ifft(TrDataMod,N)
TrDataIfftGi = [TrDataIfft(N- GI + 1 : N);TrDataIfft]

% tx Data
TxDataIfftGi = filter(h,1,TrDataIfftGi); % channel effect
% adding awgn noise
TxDataIfftGiNoise = awgn(TxDataIfftGi ...
, SNR - db(std(TxDataIfftGi))); % normalization to signal power

TxDataIfft = TxDataIfftGiNoise(GI+1:N+GI);
TxDataMod = fft(TxDataIfft,N);

% Channel estimation
Spilot = TrDataMod(Ip) % trnasmitted pilots
Ypilot = TxDataMod(Ip) % received pilots

G = (Ep * length(Ip))^-1 ...


* ctranspose(sqrt(Ep)*diag(Spilot)*ctranspose(F(1:L,Ip)));
hHat = G*Ypilot % estimated channel coefficient in time domain

TxDataBit = qamdemod(TxDataMod./(fft(hHat,N)),M)

% bit error rate computation


[nErr bErr(i,k)] = symerr(TxDataBit(Is),TrDataBit(Is))
end
end

Result:
Ip = 1

Is = 2 3 4

F=

1.0000 + 0.0000i 1.0000 + 0.0000i 1.0000 + 0.0000i 1.0000 + 0.0000i

1.0000 + 0.0000i 0.0000 + 1.0000i -1.0000 + 0.0000i -0.0000 - 1.0000i

1.0000 + 0.0000i -1.0000 + 0.0000i 1.0000 - 0.0000i -1.0000 + 0.0000i

1.0000 + 0.0000i -0.0000 - 1.0000i -1.0000 + 0.0000i 0.0000 + 1.0000i

SNR = 10

h = (0.7825 + 0.4312i), (-1.4840 + 0.1873i), (-0.4604 - 0.9704i), (-0.9803 - 0.1469i)

h = (0.1757 + 0.0968i), (-0.3331 + 0.0420i), (-0.1034 - 0.2178i), (-0.2201 - 0.0330i)

TrDataBit = 2, 0, 2, 3

TrDataIfft = (0.7500 + 0.7500i), (-0.2500 - 0.2500i), (0.7500 + 0.7500i), (0.7500 + 0.7500i)

TrDataIfftGi = (0.7500 + 0.7500i), ( 0.7500 + 0.7500i), (-0.2500 - 0.2500i), (0.7500 + 0.7500i)

0.7500 + 0.7500i

Spilot = 2.0000 + 2.0000i

Ypilot = -0.6503 - 0.9831i

hHat = ( -2.3100 - 0.4707i), (-2.3100 - 0.4707i), (-2.3100 - 0.4707i), (-2.3100 - 0.4707i)

TxDataBit = 2 ; 1; 2 ; 0

nErr =2

bErr = 0.6667

Das könnte Ihnen auch gefallen