You are on page 1of 6

Contents

  • Loop

  • Saprse Channel estimation

  • LSE

  • Figure

% In order to run this code you have to install the cvx from the following % webpage : http://www.stanford.edu/~boyd/software.html % cvx is a tool for convex optimization problems. To install the cvx simply % download it and save the unzip folder in the MATLAB working directory, % and from the unzip folder run cvx_setup.m. Then, you can run this mfile.

% In this mfile it is shown how we can use the sparsity concept for channel % estimation.

% clear

clear close all clc

 

% clear all variables % close all figures % clear command window

randn('seed',1214)

% setting the seed for normal random numbers

rand('seed',12524)

% setting the seed for uniform random numbers

% ofdm parameters

 

ofdm.N

=

128;

% number of subcarriers

ofdm.B

=

1;

% number of block in each channel

realization

ofdm.M

=

4;

% Modulation order (M=4)

ofdm.T

=

1e-7;

% OFDM sample time

ofdm.GI =

16;

% length of gaurd interval

ofdm.TS =

ofdm.N*ofdm.T;

% OFDM symbol time (not considering gaurd

interval)

ofdm.TT = (ofdm.N+ofdm.GI)*ofdm.T; % OFDM symbol time (considering gaurd interval)

ofdm.PP =

1:10:ofdm.N;

% Pilot locations in the subcarriers

ofdm.DP = setxor(1:ofdm.N,ofdm.PP);% Data locations in the subcarriers

ofdm.NP = length(ofdm.PP);

% number subcarriers which carry data

% channel parameters

chan.L

= 3;

% number of channel taps

chan.fd

= .1;

% doppler in Hz

chan.Nt

= 128;

% Number of columns in the

dictionary

chan.Gain

 

= (0:1/(chan.Nt):1)*0;

[~,chan.Delay] = sort([0,rand(1,chan.Nt)]);

% delay spread profile % generating random delay for

each ta[

chan.snrdB

= 15;

% channel signal to noise ration

chan.snrdBV = 5:2:30;

% channel signal to noise

ration for sweep

 

% loop parameters

loop.End1

= 1e2;

% number of iterations

loop.End2 = length(chan.snrdBV); loop.Sparse = zeros(loop.End1,loop.End2);

% length of inner loop % memory allocation for the BER

using sparse method

loop.LSE

= zeros(loop.End1,loop.End2);

% memory allocation for the BER

using LSE method

% building dictionary (please check different papers to learn how to build the dictionary)

chan.tau_p = linspace(0,ofdm.GI*ofdm.T - ofdm.GI*ofdm.T./chan.Nt,chan.Nt); chan.Gamma = exp(-sqrt(-1)*2*pi.*repmat

(((1:ofdm.N).'),1,chan.Nt)./ofdm.TS.*repmat(chan.tau_p,ofdm.N,1));

% fft matrix for LSE estimation (please check the following link for LSE channel estimation :

% http://www.mathworks.com/matlabcentral/fileexchange/13127-ofdm-lse-channel- estimation ) F = exp(2*pi*sqrt(-1)/ofdm.N .* meshgrid(0:ofdm.N-1,0:ofdm.N-1)... .* repmat((0:ofdm.N-1)',[1,ofdm.N]));

Loop

for cnt1 = 1 :

loop.End1

for cnt2 = 1 : loop.End2

 

% loop parameters

chan.snrdB = chan.snrdBV(cnt2);

 

% Data generation

data = randi([0 ofdm.M-1],ofdm.N,ofdm.B);

% modulation if ofdm.M == 4 dataMod = qammod(data,ofdm.M)/sqrt(2);

else

error('Not defined')

end

 

% pilot insertion

ofdm.Pilot = ones(ofdm.NP,1);% or randsrc(ofdm.NP,ofdm.B,[-1 1]).*exp(-sqrt

(-1)*pi*rand(ofdm.NP,ofdm.B));

dataMod(ofdm.PP,:) = ofdm.Pilot;

 

% ifft operation

dataIFFT

= sqrt(ofdm.N)*ifft(dataMod);

% adding gaurd interval

dataIFFTGI = [dataIFFT((ofdm.N-ofdm.GI+1):ofdm.N,:);dataIFFT;];

% channel (rayleigh and gaussian noise)

ch = rayleighchan(ofdm.T,chan.fd,chan.tau_p(chan.Delay(1:chan.L)),chan.Gain

(chan.Delay(1:chan.L)));

dataChann = awgn(filter(ch,dataIFFTGI(:)),chan.snrdB );

% reshaping the signal

dataChann = reshape(dataChann,ofdm.N+ofdm.GI,ofdm.B);

 

% Guard interval removal

dataRx

= dataChann((ofdm.GI+1):(ofdm.N+ofdm.GI),:);

% ofdm demodulation

dataRxFFT =1/sqrt(ofdm.N)*fft(dataRx);

Saprse Channel estimation

H_Sparse = zeros(ofdm.N,ofdm.B); lambda1 = ofdm.NP*10^(-chan.snrdB/10)/sum(abs(ch.pathGains)); for b = 1 : ofdm.B y = dataRxFFT(ofdm.PP,b); A = chan.Gamma(ofdm.PP,:).*repmat(ofdm.Pilot(:,b),1,chan.Nt); cvx_begin quiet

variable x(chan.Nt) complex % sparse minimization formula (A is built from dictionary, y is received data and x is the channel coeff at pilot locations)

minimize( quad_form(y-A*x,eye(ofdm.NP))+lambda1*norm(x,1) )

cvx_end

% building channel at all location (simply from the dictionar)

H_Sparse(:,b) = chan.Gamma*x;

end

dataRxMod_Sparse = dataRxFFT(ofdm.DP,:)./H_Sparse(ofdm.DP,:);

dataRxDeMod_Sparse = qamdemod(dataRxMod_Sparse,ofdm.M); [~,BER_Sparse] = biterr(dataRxDeMod_Sparse,data(ofdm.DP,:),ofdm.M);

LSE

H_LSE = zeros(ofdm.N,ofdm.B);

for b = 1 : ofdm.B H_LSE(:,b) = ofdm.N/ofdm.NP * fft(ifft(dataRxFFT(ofdm.PP,b)./dataMod (ofdm.PP,b)),ofdm.N);

end

dataRxMod_LSE = dataRxFFT(ofdm.DP,:)./H_LSE(ofdm.DP,:); dataRxDeMod_LSE = qamdemod(dataRxMod_LSE,ofdm.M); [~,BER_LSE] = biterr(dataRxDeMod_LSE,data(ofdm.DP,:),ofdm.M);

% saving the output

loop.Sparse(cnt1,cnt2) = BER_Sparse;

loop.LSE(cnt1,cnt2)

= BER_LSE;

end disp([num2str(round(cnt1/loop.End1*100)),'% has been done'])

end

1% has been done 2% has been done 3% has been done 4% has been done 5% has been done 6% has been done 7% has been done 8% has been done 9% has been done 10% has been done 11% has been done 12% has been done 13% has been done 14% has been done 15% has been done 16% has been done 17% has been done 18% has been done 19% has been done 20% has been done 21% has been done 22% has been done 23% has been done 24% has been done 25% has been done 26% has been done 27% has been done 28% has been done 29% has been done 30% has been done 31% has been done 32% has been done 33% has been done 34% has been done 35% has been done 36% has been done 37% has been done 38% has been done 39% has been done 40% has been done 41% has been done 42% has been done

43% has been done 44% has been done 45% has been done 46% has been done 47% has been done 48% has been done 49% has been done 50% has been done 51% has been done 52% has been done 53% has been done 54% has been done 55% has been done 56% has been done 57% has been done 58% has been done 59% has been done 60% has been done 61% has been done 62% has been done 63% has been done 64% has been done 65% has been done 66% has been done 67% has been done 68% has been done 69% has been done 70% has been done 71% has been done 72% has been done 73% has been done 74% has been done 75% has been done 76% has been done 77% has been done 78% has been done 79% has been done 80% has been done 81% has been done 82% has been done 83% has been done 84% has been done 85% has been done 86% has been done 87% has been done 88% has been done 89% has been done 90% has been done 91% has been done 92% has been done 93% has been done

94% has been done 95% has been done 96% has been done 97% has been done 98% has been done 99% has been done 100% has been done

Figure

f1 = figure(1);

semilogy(chan.snrdBV,mean(loop.Sparse,1),'b-o')

hold on

semilogy(chan.snrdBV,mean(loop.LSE,1),'r.-')

hold off legend('Sparse','LSE') grid on

94% has been done 95% has been done 96% has been done 97% has been done

Published with MATLAB® R2012b