Professional Documents
Culture Documents
Page 1 of 6
Contents
% % % % %
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 randn('seed',1214) rand('seed',12524)
% % % % %
clear all variables close all figures clear command window setting the seed for normal random numbers setting the seed for uniform random numbers
% ofdm parameters ofdm.N = 128; % ofdm.B = 1; % realization ofdm.M = 4; % ofdm.T = 1e-7; % ofdm.GI = 16; % ofdm.TS = ofdm.N*ofdm.T; % interval) ofdm.TT = (ofdm.N+ofdm.GI)*ofdm.T; % interval) ofdm.PP = 1:10:ofdm.N; % ofdm.DP = setxor(1:ofdm.N,ofdm.PP);% ofdm.NP = length(ofdm.PP); %
number of subcarriers number of block in each channel Modulation order (M=4) OFDM sample time length of gaurd interval OFDM symbol time (not considering gaurd OFDM symbol time (considering gaurd Pilot locations in the subcarriers Data locations in the subcarriers number subcarriers which carry data
% channel parameters chan.L = 3; chan.fd = .1; chan.Nt = 128; dictionary chan.Gain = (0:1/(chan.Nt):1)*0; [~,chan.Delay] = sort([0,rand(1,chan.Nt)]); each ta[ chan.snrdB = 15; chan.snrdBV = 5:2:30; ration for sweep
% number of channel taps % doppler in Hz % Number of columns in the % delay spread profile % generating random delay for % channel signal to noise ration % channel signal to noise
file:///C:/Users/Solo/SkyDrive/Codes/html/chabEst01_Para.html
22-Jul-13
chabEst01_Para
Page 2 of 6
% loop parameters loop.End1 = 1e2; loop.End2 = length(chan.snrdBV); loop.Sparse = zeros(loop.End1,loop.End2); using sparse method loop.LSE = zeros(loop.End1,loop.End2); using LSE method
% number of iterations % length of inner loop % memory allocation for the BER % memory allocation for the BER
% 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-channelestimation ) 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;];
file:///C:/Users/Solo/SkyDrive/Codes/html/chabEst01_Para.html
22-Jul-13
chabEst01_Para
Page 3 of 6
% 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);
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,:);
file:///C:/Users/Solo/SkyDrive/Codes/html/chabEst01_Para.html
22-Jul-13
chabEst01_Para
Page 4 of 6
loop.LSE(cnt1,cnt2)
= BER_LSE;
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
file:///C:/Users/Solo/SkyDrive/Codes/html/chabEst01_Para.html
22-Jul-13
chabEst01_Para
Page 5 of 6
43% 44% 45% 46% 47% 48% 49% 50% 51% 52% 53% 54% 55% 56% 57% 58% 59% 60% 61% 62% 63% 64% 65% 66% 67% 68% 69% 70% 71% 72% 73% 74% 75% 76% 77% 78% 79% 80% 81% 82% 83% 84% 85% 86% 87% 88% 89% 90% 91% 92% 93%
has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has has
been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been been
done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done done
file:///C:/Users/Solo/SkyDrive/Codes/html/chabEst01_Para.html
22-Jul-13
chabEst01_Para
Page 6 of 6
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
file:///C:/Users/Solo/SkyDrive/Codes/html/chabEst01_Para.html
22-Jul-13