DSPRelated.com
Forums

OFDM matlab files .. need ur help !

Started by gloria57_99 December 11, 2003
Iam doing my final project in OFDM software implementation ... using
matlab programing ... and DQPSK modulation technique ... I have
problem in the QPSKEncoder code that when any M-file calls it , it
gives me error message saying that :
??? Index exceeds matrix dimensions.
Error in ==> C:\MATLAB6p5\work\DQPSKEncoder.m
On line 5 ==> PhaseShift(1)cPhase([a(1,1),a(2,1)]);

here u r the all matlab files which Iam using :

1.DQPSKEncoder.m
%PI/4 -DQPSK Encoder
function [ModulatedSymbol]=DQPSKEncoder(BitStream)
a=buffer(BitStream,2);
InitialSymbol =(1+i*0);
PhaseShift(1)cPhase([a(1,1),a(2,1)]);
ModulatedSymbol(1) =(InitialSymbol)*exp(i*PhaseShift(1));
for index =2:1:length(BitStream)/2;
PhaseShift(index)cPhase([a(1,index),a(2,index)]);
ModulatedSymbol(index)=ModulatedSymbol(index-1)*exp(j*PhaseShift
(index));
end

***************************************************
2.%OFDM with Guard Interval.m
clc;
clear;
delay=5;
GI=6;
nIters=2;
LogEbNo=[5:5:40];
lenSim=length(LogEbNo);
BitStreamLengthd*500;
BitStreamo=randint(BitStreamLength,1,2)';
[ModulatedSymbol]=DQPSKEncoder(BitStreamo);
for EbNoIndex=1:lenSim
EbNo^(LogEbNo(EbNoIndex)/10);
TSBOo.*ModulatedSymbol;
y=buffer(TBSO,64);
q=length(ModulatedSymbol)/64;
u=ifft(y);
for i=1:q
a=u(:,i);
a1=[a.'a(1:6)'];
u1(:,i).';
end
s=u1(:).';
s1=s/2;
v=length(s1)-delay;
ss=[randn(1,delay)s1(1:v)];
s2=ss+s;
for iters=1:nIters
[RBS]=AWGNChannel4(s2);
k=(64+GI);
w=buffer(RBS,k);
k1=length(s1)/k;
for i=1:64
for j=1:k1
h1(i,j)=w(i,j);
end
end
ht(h1);
DI=h(:).';
RRBS=clip(DI);
[OBS]=DQPASKDecoder(RRBS);
Errors=sum(OBS~=BitStreamo);
BER(iters)=Errors/BitStreamLength
end
AvBER(EbNoIndex)=sum(BER)/nIters;
end
semilogy(LogEbNo,AvBER,'k')
grid
xlabel('Eb/No')
ylabel('BER')
title('OFDM with Guard Interval ')
**************************************

3.CalcPhase.m
%CalcPhase the phase mapping
function Phase= CalcPhase(BitVector)
switch BitVector(1)
case 0,
switch BitVector(2)
case 0, %[0,0]case
Phase=pi/4;
case 1, %[0,1]case
Phase=3*pi/4;
end
case 1,
switch BitVector(2)
case 0,%[1,0]case
Phase= -pi/4;
case 1,%[1,1]case
Phase= -3*pi/4;
end
end
***********************************
4.AWGNCannel.m

%AWGNChannel
function [RBS]=AWGNCannel(f);
m=(2*rand(1,length(f))-1)/2;
amp1s(f);
phase1=angle(f);
ampp= amp1+m;
RBS=ampp.*cos(phase1)+j.*ampp.*sin(phase1);
********************************

5.clip.m
%Clipping
function RRBS =clip(RBS)
amps(RBS);
phas=angle(RBS);
if amp>1
amp=1;
phas=phas;
elseifamp<-1
amp=-1;
phas=phas
else
amp=amp;
phas=phas;
end
RRBS=amp.*cos(phas)+j.*amp.*sin*(phas);
******************************************
6.
%Coherent PI/4-DQPSK Decoder
function [OBS]=DQPSKDecoder(DI)
IntialSymbol=1+j*0;
ModSymbols=DI;
ModAngles=angle(ModSymbols);
DiffAngles=[ModAngles 0 ]-[0 ModAngles];
DiffAngles = DiffAngles(1:end-1);
BS1=sin(DiffAngles)<0;
BS2=cos(DiffAngles)<0;
a=[BS1,BS2];
OBS=a(:)';
**************************
7.
% DQPSK system in AWGN Channel
clc;
clear;
nIters=1;
LogEbNo=[0:9];
lenSim=length(LogEbNo);
BitStreamLengthd*500;
BitStreamo=randint(BitStreamLength,1,2)';
[ModulatedSymbol]=DQPSKEncoder(BitStreamo);
for EbNoIndex=1:lenSim
EbNo^(LogEbNo(EbNoIndex)/10);
ModulatedSymbol2o.*ModulatedSymbol;
for iters=1:nIters
[RBS]=AWGNChannel(ModulatedSymbol2);
[OBS]=DQPSKDecoder(RBS);
Errors=sum(OBS~=BitStreamo);
BER(iters)= Errors/BitStreamLength
end
AvBER(EbNoIndex)=sum(BER)/nIters;
end
semilogy(LogEbNo,AvBER,'k')
grid
xlabel('Eb/No')
ylabel('BER')
title('DQPSK system in AWGN Channel')
*************************************
8.
%DQPSK in Multipath Channel
clc;
clear;
delay=5;
nIters=2;
LogEbNo=[10:5:50];
lenSim=length(LogEbNo);
BitStreamLengthd*500;
BitStreamo=randint(BitStreamLength,1,2)';
[ModulatedSymbol]=DQPSKEncoder(BitStreamo);
for EbNoIndex=1:lenSim
EbNo^(LogEbNo(EbNoIndex)/10);
ModulatedSymbolo.*ModulatedSymbol;
s1=ModualtedSymbol/2;
v=(BitStreamLength/2)-dealy;
ss=[randn(1,delay)s1(1:v)];
s2=ss+ModulatedSymbol;
for iters=1:nIters
[RBS]=AWGNChannel(s2);
[OBS]=DQPSKDecoder(RBS);
Errors=sum(OBS~=BitStreamo);
BER(iters)=Errors/BitStreamLength
end
AvBER(EbNoIndex)=sum(BER)/nIters;
end
semilogy(LogEbNo,AvBER,'k')
grid
xlabel('Eb/No')
ylabel('BER')
title('DQPASK in MultipathChannel ')
*************************
9.
% DQPSK with OFDM in AWGN Channel
clc;
clear;
nIters=1;
LogEbNo=[0:9];
lenSim=length(LogEbNo);
BitStreamLengthd*500;
BitStreamo=randint(BitStreamLength,1,2)';
[ModulatedSymbol]=DQPSKEncoder(BitStreamo);
for EbNoIndex=1:lenSim
EbNo^(LogEbNo(EbNoIndex)/10);
TBSOo.*ModulatedSymbol;
for iters=1:nIters
y=buffer(TBSO,64);
u=ifft(y);
s=u(:).';
[RBS]=AWGNChannel(s);
RRBS=clip(RBS);
w=buffer(RRBS,64);
ht(w);
DI=h(:).';
[OBS]=DQPSKDecoder(DI);
Errors=sum(OBS~=BitStreamo);
BER(iters)=Errors/BitStreamLength;
end
AvBER(EbNoIndex)=sum(BER)/nIters;
end
semilogy(LogEbNo,AvBER,'k')
grid
xlabel('Eb/No')
ylabel('BER')
title('DQPSK with OFDM in AWGN Channel ')
*************************
10.
%OFDM in MultiPath Channel
clc;
clear;
delay=5;
nIters=1;
LogEbNo=[5:5:40];
lenSim=length(LogEbNo);
BitStreamLengthd*500;
BitStreamo=randint(BitStreamLength,1,2)';
[ModulatedSymbol]=DQPSKEncoder(BitStreamo);
for EbNoIndex=1:lenSim
EbNo^(LogEbNo(EbNoIndex)/10);
TBSOo.*ModulatedSymbol;
for iters=1:nIters
y=buffer(TBSO,64);
u=ifft(y);
s=u(:)';
v=length(s)-delay;
ss=[randn(1,delay) 0.5*s(1:v)];
s2=ss+s;
[RBS]=AWGNChannel(s2);
w=buffer(RBS,64);
ht(w);
DI=h(:).';
RRBS=clip(DI);
[OBS]=DQPSKDecoder(RRBS);
Errors=sum(OBS~=BitStreamo);
BER(iters) = Errors/BitStreamLength
end
AvBER(EbNoIndex)=sum(BER)/nIters;
end
semilogy(LogEbNo,AvBER,'k')
grid
xlabel('Eb/No')
ylabel('BER')
title('OFDM System in Multipath Channel ')
***************************** thanks in advance,,
gloria57_99