8/10/2019 Subcarrier Diversity Matlab
1/54
echo off;clear all;close all;clc;
fprintf( 'OFDM\n') ;
tic
% --------------------------------------------- %% %
% --------------------------------------------- %
% nitiali!e the para"eters
#$"oop & ;
#$"$*c & +,;
8/10/2019 Subcarrier Diversity Matlab
2/54
#$". & ,;
/ncDela/ & ;
% 012 +,
% 34 56 +
8/10/2019 Subcarrier Diversity Matlab
3/54
8/10/2019 Subcarrier Diversity Matlab
4/54
% --------------------------------------------- %
% GHM MODRHAO# %
8/10/2019 Subcarrier Diversity Matlab
5/54
% --------------------------------------------- %
8/10/2019 Subcarrier Diversity Matlab
6/54
8/10/2019 Subcarrier Diversity Matlab
7/54
% Senerate the ranTo" *inar/ strea" for trans"it test
UitsAV & floor(ranT(W#$"oop@#$"$*c)@+);
% MoT$late (Senerates GHM s/"*ols)
% inp$tX UitsAV(W#$"oop@#$"$*c); o$tp$tX /"GHM(#$"oopW#$"$*c4+)/"GHMt"p & reshape(UitsAVW+W#$"oop@#$"$*c4+)Y';
/"GHMt"pt"p & *i+Te(/"GHMt"pW+W'left-"s*');
%--------------------------------------------------------------------
8/10/2019 Subcarrier Diversity Matlab
8/54
% Z[]
8/10/2019 Subcarrier Diversity Matlab
9/54
8/10/2019 Subcarrier Diversity Matlab
10/54
% *i+Tebdgjkm+CC
% D & U+Dq(YYYWMUFHS) $ses MUFHS to Teter"ine the inp$t
orientationY
% MUFHS has to possi*le `al$esW 'ri^ht-"s*' anT 'left-"s*'Y
Si`in^ a
% 'ri^ht-"s*' MUFHS Toes not chan^e the f$nction's Tefa$lt
*eha`iorY
% Si`in^ a 'left-"s*' MUFHS flips the inp$t orientation s$ch that
the
% MU is on the leftY
% % % D & U+Dq(YYYW.) con`erts a *ase . `ector to a Teci"al `al$eY
% % qVa"plesX
% % U & ; u;
% % A & ; + u;% % D & *i+Te(U) D & *i+Te(UW'left-"s*') D &
*i+Te(AW)
% % D & D & D &
% % + +
% % v v
%--------------------------------------------------------------------
% GHM "oT$lation
% ---iW--wiW--iW-wi
% xyz{|}GHM~GHMAa*le & --i -wi -i wiu;
/"GHM & GHMAa*le(/"GHMt"pt"pw);
% --------------------------------------------- %
% FFA %
% --------------------------------------------- %
% inp$tX /"GHM(#$"oopW#$"$*c4+); o$tp$tX /"FFA(#$"$*cW#$"oop)
/"FFA & !eros(#$"$*cW#$"oop);
/"FFAt"p & reshape(/"GHMW#$"$*c4+W#$"oop);
/"FFAt"pt"p & !eros(#$"$*cW#$"oop);
8/10/2019 Subcarrier Diversity Matlab
11/54
8/10/2019 Subcarrier Diversity Matlab
12/54
/"FFAt"pt"p(WX) & real(/"FFAt"p(WX)); %
/"FFAt"pt"p(#$"$*c4+wWX) & i"a^(/"FFAt"p(WX)); %
%
% ifft4fft #
% #4+
% #4+ #4+w #-#4+
/"FFAt"pt"p(+X#$"$*c4+WX) & /"FFAt"p(+X#$"$*c4+WX);
/"FFAt"pt"p((#$"$*c4+w+)X#$"$*cWX) &
flipTi"(con(/"FFAt"p(+X#$"$*c4+WX))W);
8/10/2019 Subcarrier Diversity Matlab
13/54
%--------------------------------------------------------------------
% Z[]
% U & flipTi"(HWTi") ret$rns H ith Ti"ension Ti" flippeTY
% hen the `al$e of Ti" is W the arra/ is flippeT ro-ise TonY
hen Ti" is +W
% the arra/ is flippeT col$"nise left to ri^htY flipTi"(HW) is the
sa"e as
% flip$T(H)W anT flipTi"(HW+) is the sa"e as fliplr(H)Y
%--------------------------------------------------------------------
8/10/2019 Subcarrier Diversity Matlab
14/54
% % a & + ; v ?; , ; +u
% % a &
% % +
% % v ?
% % ,
% % +
% % * & flipTi"(aW)
% % * &
% % +
% % ,
% % v ?
% % +
/"FFA & ifft(/"FFAt"pt"pW#$"$*cW);
% --------------------------------------------- %
% HTT c/clic prefiV %
% --------------------------------------------- %
% inp$tX /"FFA(#$"$*cW#$"oop); o$tp$tX /".(#$"$*c w
#$".W#$"oop)
#$"HTT.refiV & #$"$*c w #$".;
/". & !eros(#$"HTT.refiVW#$"oop);
o.refiV & (#$"$*c - #$". w )X#$"$*c;
/". & /"FFA(o.refiVWX);/"FFAu;
% --------------------------------------------- %
% So thro$^h the channel %
% --------------------------------------------- %
% inp$tX /".(#$"$*c w #$".W#$"oop); o$tp$tX /"h(W(#$"$*c w
#$".)@#$"oop)
/"h & !eros(W(#$"$*c w #$".)@#$"oop);
/"ht"p & /".(X)Y'; % }
% bd }d
h & 4+ 4u;
/"ht"pt"p & filter(hWW/"ht"p);
%--------------------------------------------------------------------
% Z[]
8/10/2019 Subcarrier Diversity Matlab
15/54
% Firlter Tata ith an infinite i"p$lse response () or finite
i"p$lse response
% (F) filter
8/10/2019 Subcarrier Diversity Matlab
16/54
% / & filter(*WaW) filters the Tata in `ector ith the filter
Tescri*eT */
% n$"erator coefficient `ector * anT Teno"inator coefficient `ector
aY f a() is
% not e_$al to W filter nor"ali!es the filter coefficients */ a()Y
f a() e_$als
% W filter ret$rns an errorY
%--------------------------------------------------------------------
8/10/2019 Subcarrier Diversity Matlab
17/54
8/10/2019 Subcarrier Diversity Matlab
18/54
% f is a "atriVW filter operates on the col$"ns of Y f is a
"$ltiTi"ensional
% arra/W filter operates on the first nonsin^leton Ti"ensionY
%--------------------------------------------------------------------
% HTT the HS#
UernrAa*le & !eros(+W);
for snr&X; % & # w @lo^(lo^+(+));
UernrAa*le(snrwW) & snr;
/"h & a^n(/"ht"pt"pWsnrW'"eas$reT');
%--------------------------------------------------------------------
% Z[]
% HS# HTT hite Sa$ssian noise to a si^nalY
% & HS#(W#) aTTs hite Sa$ssian noise to Y Ahe # is in
TUY
% Ahe poer of is ass$"eT to *e TUY f is co"pleVW then
% HS# aTTs co"pleV noiseY
% ------------------------------------------------------------------
% & HS#(W#WS.Oq) hen S.Oq is n$"ericW it
represents
% the si^nal poer in TUY hen S.Oq is '"eas$reT'W HS#
"eas$res
8/10/2019 Subcarrier Diversity Matlab
19/54
% the si^nal poer *efore aTTin^ noiseY
%
---------------------------------------------------------------------
8/10/2019 Subcarrier Diversity Matlab
20/54
% & HS#(W#WS.OqWAHAq) resets the state of H#D# to
AHAqY
%
% & HS#(YYYW .OqA.q) specifies the $nits of # anT
S.OqY
% .OqA.q can *e 'T*' or 'linear'Y f .OqA.q is 'T*'W then
#
8/10/2019 Subcarrier Diversity Matlab
21/54
% is "eas$reT in TU anT S.Oq is "eas$reT in TUY f
.OqA.q is
% 'linear'W then # is "eas$reT as a ratio anT S.Oq is
"eas$reT
% in attsY
%
% qVa"pleX Ao specif/ the poer of to *e TU anT aTT noise to
proT$ce
% an # of TUW $seX
% & s_rt(+)@sin(Xpi4,X?@pi);
% & HS#(WW);
8/10/2019 Subcarrier Diversity Matlab
22/54
8/10/2019 Subcarrier Diversity Matlab
23/54
% qVa"pleX Ao ca$se HS# to "eas$re the poer of W set H#D# to
the
% +th state anT aTT noise to proT$ce a linear # of
W $seX
% & s_rt(+)@sin(Xpi4,X?@pi);
8/10/2019 Subcarrier Diversity Matlab
24/54
% & HS#(WW'"eas$reT'W+W'linear');
% --------------------------------------------- %
8/10/2019 Subcarrier Diversity Matlab
25/54
% e"o`e S$arT nter`als %
% --------------------------------------------- %
8/10/2019 Subcarrier Diversity Matlab
26/54
% inp$tX /"h(W(#$"$*c w #$".)@#$"oop); o$tp$tX
/"De.(#$"$*cW#$"oop)
/"De. & !eros(#$"$*cW#$"oop);
/"De.t"p & reshape(/"hW#$"$*c w #$".W#$"oop);
/"De. & /"De.t"p((#$".ww/ncDela/)X#$"HTT.refiVw/ncDela/WX);
% --------------------------------------------- %
% FFA %
% --------------------------------------------- %
% inp$tX /"De.(#$"$*cW#$"oop); o$tp$tX /"FFA(#$"$*cW#$"oop)
/"FFA & fft(/"De.W#$"$*cW);
% --------------------------------------------- %
% Mae Decision(ncl$Te DeGHM) %
% --------------------------------------------- %% /"FFA(#$"$*cW#$"oop); o$tp$tX /"Dec(#$"$*cW#$"oop)
/"Dec & !eros(#$"$*cW#$"oop);
/"q_t"p(WX) & /"FFA(WX)wi@/"FFA(#$"$*c4+wWX);
/"q_t"p(+X#$"$*c4+WX) & /"FFA(+X#$"$*c4+WX);
for " & X#$"oop
for n & X#$"$*c4+
eal & real(/"q_t"p(nW"));
"a^ & i"a^(/"q_t"p(nW"));
8/10/2019 Subcarrier Diversity Matlab
27/54
if( a*s((eal -)) a*s((eal w)))
/"Dec(+@n-W") & ;
else
/"Dec(+@n-W") & ;
enT
if( a*s(("a^ -)) a*s(("a^ w )) )
/"Dec(+@nW") & ;
else
/"Dec(+@nW") & ;
enT
enT
8/10/2019 Subcarrier Diversity Matlab
28/54
8/10/2019 Subcarrier Diversity Matlab
29/54
enT
%
---------------------------------------------------------------------
% Aest */ la`a*in% Hnother a/ to DeGHM
% GHMAa*le & --i -wi -i wiu;
8/10/2019 Subcarrier Diversity Matlab
30/54
% ---iW--wiW--iW-wi
Aest/"Dec & !eros(#$"$*cW#$"oop);
Aest/"q_t"p(WX) & /"FFA(WX)wi@/"FFA(#$"$*c4+wWX);
Aest/"q_t"p(+X#$"$*c4+WX) & /"FFA(+X#$"$*c4+WX);
Aest/"q_t"p & reshape(Aest/"q_t"pWW#$"$*c@#$"oop4+);
"inT & !eros(si!e(Aest/"q_t"p));
"inTTT & !eros(W#$"$*c@#$"oop);
T & !eros(W);
"ininTeV & ;
8/10/2019 Subcarrier Diversity Matlab
31/54
for ii & XX(#$"$*c@#$"oop4+)
for & X
T() & a*s(Aest/"q_t"p(ii) - GHMAa*le());
enT
8/10/2019 Subcarrier Diversity Matlab
32/54
"inT(ii)W"ininTeVu & "in(T);
% % Wu & M#() ret$rns the inTices of the "ini"$" `al$es in
`ector Y
sitch "ininTeV
case
8/10/2019 Subcarrier Diversity Matlab
33/54
8/10/2019 Subcarrier Diversity Matlab
34/54
"inTTT(+@ii) & ;
case
"inTTT(+@ii-) & ;
"inTTT(+@ii) & ;
otherise
fprintf('"possi*le error \n\n');
8/10/2019 Subcarrier Diversity Matlab
35/54
enT
enT
%--------------------------------------------------------------------
% Z[]
% % & "in(H) ret$rns the s"allest ele"ents alon^ Tifferent
Ti"ensions of an
8/10/2019 Subcarrier Diversity Matlab
36/54
% % arra/Y
% % f H is a `ectorW "in(H) ret$rns the s"allest ele"ent in HY
% % f H is a "atriVW "in(H) treats the col$"ns of H as `ectorsW
ret$rnin^ a ro
8/10/2019 Subcarrier Diversity Matlab
37/54
% % `ector containin^ the "ini"$" ele"ent fro" each col$"nY
% % Wu & "in(YYY) finTs the inTices of the "ini"$" `al$es of HW
anT ret$rns% % the" in o$tp$t `ector Y f there are se`eral iTentical "ini"$"
`al$esW the
% % inTeV of the first one fo$nT is ret$rneTY
% Uit qrror
UitsV & !eros(W#$"$*c@#$"oop);
UitsV & /"Dec(X)Y';
#$"WUeru & s/"err(UitsAVWUitsV)
UernrAa*le(snrwW+) & #$" ;
UernrAa*le(snrwW) & Uer ;enT
%--------------------------------------------------------------------
% Aest */ la`a*in
8/10/2019 Subcarrier Diversity Matlab
38/54
8/10/2019 Subcarrier Diversity Matlab
39/54
if "inTTT && UitsV
fprintf('DeGHM to a/s the sa"e res$lts \n\n');
else
fprintf('DeGHM to a/s the Tifferent res$lts');
8/10/2019 Subcarrier Diversity Matlab
40/54
enT
%--------------------------------------------------------------------
fi^$re();
s$*plot(+WW);
se"ilo^/(UernrAa*le(XW)WUernrAa*le(XW+)W'o-');
8/10/2019 Subcarrier Diversity Matlab
41/54
s$*plot(+WW+);
se"ilo^/(UernrAa*le(XW)WUernrAa*le(XW)W'o-');
%--------------------------------------------------------------------
ti"eofsi" & toc
8/10/2019 Subcarrier Diversity Matlab
42/54
echo on;
% --------------------------------------------- %
% Ahe q#D %
% --------------------------------------------- %
% OFDMK62K6
% 12+,12+12n$ll12(+
12
% )?1212
% E
clc;clear all;close all;echo off;tic;
% -------------------------------------------------------------------
% .ara"eter Definition
% --------------------------------------------------------------
FT & ; % s/"*ol rate (!)
Fs & @FT; % n$"*er of sa"ple per s/"*ol
M & ; % inT(ran^e) of s/"*ol (WW+W)
#Tata & +; % all trans"itteT Tata s/"*ol
8/10/2019 Subcarrier Diversity Matlab
43/54
Tata & ?; % ? Tata s/"*ol per fra"e to ifft
8/10/2019 Subcarrier Diversity Matlab
44/54
len & +,; % +, len^th s/"*ol for FFA
#s/" & #Tata4Tata; % n$"*er of fra"es - #s/" fra"e
Slen & ; % s/"*ol ith S insertion Slen & len w S
S & ?; % ^$arT inter`al len^th
% ----------------------------------------------------------------
% ector nitiali!ation
8/10/2019 Subcarrier Diversity Matlab
45/54
8/10/2019 Subcarrier Diversity Matlab
46/54
& !eros(#TataW);
& !eros(#TataW);
+ & !eros(#TataW);
& !eros(lenW);
! & !eros(lenW);
8/10/2019 Subcarrier Diversity Matlab
47/54
8/10/2019 Subcarrier Diversity Matlab
48/54
% is a #Tata-*/-+ "atriVW is chan^eT into + */ a"oTce
& "oT"ap(W FTW FsW '_as'W M);
% co`ert to co"pleV n$"*er
+ & a"oTce(WW'_a"');% fi^$re();
% scatterplot(+Wlen^th(+)WW'*o');^riT on;
scatterplot(+WFTWW'*o');^riT on;
title('-GHM onstellation');
AVspectr$" & !eros(si!e());
for &X#s/";
for i&XTata;
(iwlen4+-Tata4+W)&+(iw(-)@TataW); AVspectr$" & AVspectr$" w a*s();
enT
!&ifft();
for i&Xlen; % ^enerate ti"e-To"ain `ectorW !W itho$t S
!(((-)@len)wi)&!(iW);
enT
%
for i&Xlen;
8/10/2019 Subcarrier Diversity Matlab
49/54
^(iw?)&!(iW);
enT
8/10/2019 Subcarrier Diversity Matlab
50/54
for i&XS;
^(i)&!(iwlen-SW);
enT
for i&XSlen; % ^enerate ti"e-To"ain `ectorW !+W ith S
8/10/2019 Subcarrier Diversity Matlab
51/54
!+(((-)@Slen)wi)&^(iW);
enT
enT
% ^raph on ti"e To"ain
fi^$re(+);
f & linspace(-TataWTataWlen^th(!));
plot(fWa*s(!));
8/10/2019 Subcarrier Diversity Matlab
52/54
8/10/2019 Subcarrier Diversity Matlab
53/54
& fft(!); % FFA operationW at recei`er
% if is $nTer Y &Yfor &X#Tata4Tata@len;
if a*s(()) Y
()&Y;
enT
enT
& @lo^(a*s()); % is $seT for spectr$" Tispla/Y
% ^raph on fre_$enc/ To"ain
fi^$re();
f & linspace(-TataWTataWlen^th());
plot(fW);^riT on;
aVis(-len4+ len4+ -+ +u);
title('ecei`eT OFDM si^nal spectr$"');
fi^$re();
f & linspace(-TataWTataWlen^th());
plot(fWa*s()W'*-'W'ineiTth'W?);^riT on;
aVis(-len4+ len4+ -+ +u);
title('Arans"itteT OFDM si^nal spectr$"');
si"$lationti"e & toc
8/10/2019 Subcarrier Diversity Matlab
54/54