Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

OFDM Simulation In MAtlab

Status
Not open for further replies.

parisa66

Newbie level 3
Newbie level 3
Joined
Dec 15, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,346
Hi,I Have a transmitter-Reciever Of OFDM via Matlab Code and I want to add a rayleigh channel and then recieving it..could any one help me through this? This is Veryyy important!!!thanks
 

sure

5.1 OFDM Transmission

%DVB-T2KTransmission
%Theavailablebandwidthis8MHz
%2Kisintendedformobileservices
clearall;
closeall;
%DVB-TParameters
Tu=224e-6; %usefulOFDMsymbolperiod
T=Tu/2048; %basebandelementaryperiod
G=0; %choiceof1/4,1/8,1/16,and1/32
delta=G*Tu; %guardbandduration
Ts=delta+Tu; %totalOFDMsymbolperiod
Kmax=1705; %numberofsubcarriers
Kmin=0;
FS=4096; %IFFT/FFTlength
q=10; %carrierperiodtoelementaryperiodratio
fc=q*1/T; %carrierfrequency
Rs=4*fc; %simulationperiod
t=0:1/Rs:Tu;
%Datagenerator(A)
M=Kmax+1;
rand('state',0);
a=-1+2*round(rand(M,1)).'+i*(-1+2*round(rand(M,1))).';
A=length(a);
info=zeros(FS,1);
info(1:(A/2))=[a(1:(A/2)).']; %Zeropadding
info((FS-((A/2)-1)):FS)=[a(((A/2)+1):A).'];
%Subcarriersgeneration(B)
carriers=FS.*ifft(info,FS);
tt=0:T/2:Tu;
figure(1);
subplot(211);
stem(tt(1:20),real(carriers(1:20)));

subplot(212);
stem(tt(1:20),imag(carriers(1:20)));
figure(2);
f=(2/T)*(1:(FS))/(FS);
subplot(211);
plot(f,abs(fft(carriers,FS))/FS);
subplot(212);
pwelch(carriers,[],[],[],2/T);
%D/Asimulation
L=length(carriers);
chips=[carriers.';zeros((2*q)-1,L)];
p=1/Rs:1/Rs:T/2;
g=ones(length(p),1); %pulseshape
figure(3);
stem(p,g);
dummy=conv(g,chips:)));
u=[dummy(1:length(t))]; %(C)
figure(4);
subplot(211);
plot(t(1:400),real(u(1:400)));
subplot(212);
plot(t(1:400),imag(u(1:400)));
figure(5);
ff=(Rs)*(1:(q*FS))/(q*FS);
subplot(211);
plot(ff,abs(fft(u,q*FS))/FS);
subplot(212);
pwelch(u,[],[],[],Rs);
[b,a]=butter(13,1/20); %reconstructionfilter
[H,F]=FREQZ(b,a,FS,Rs);
figure(6);
plot(F,20*log10(abs(H)));
uoft=filter(b,a,u); %basebandsignal(D)
figure(7);
subplot(211);
plot(t(80:480),real(uoft(80:480)));
subplot(212);
plot(t(80:480),imag(uoft(80:480)));
figure(8);
subplot(211);
plot(ff,abs(fft(uoft,q*FS))/FS);
subplot(212);
pwelch(uoft,[],[],[],Rs);
%Upconverter
s_tilde=(uoft.').*exp(1i*2*pi*fc*t);
s=real(s_tilde); %passbandsignal(E)
figure(9);
plot(t(80:480),s(80:480));
figure(10);
subplot(211);
%plot(ff,abs(fft(((real(uoft).').*cos(2*pi*fc*t)),q*FS))/FS);
%plot(ff,abs(fft(((imag(uoft).').*sin(2*pi*fc*t)),q*FS))/FS);
plot(ff,abs(fft(s,q*FS))/FS);
subplot(212);
%pwelch(((real(uoft).').*cos(2*pi*fc*t)),[],[],[],Rs);
%pwelch(((imag(uoft).').*sin(2*pi*fc*t)),[],[],[],Rs);
pwelch(s,[],[],[],Rs);

5.2 OFDM Reception

%DVB-T2KReception
clearall;
closeall;
Tu=224e-6; %usefulOFDMsymbolperiod
T=Tu/2048; %basebandelementaryperiod
G=0; %choiceof1/4,1/8,1/16,and1/32
delta=G*Tu; %guardbandduration
Ts=delta+Tu; %totalOFDMsymbolperiod
Kmax=1705; %numberofsubcarriers
Kmin=0;
FS=4096; %IFFT/FFTlength
q=10; %carrierperiodtoelementaryperiodratio
fc=q*1/T; %carrierfrequency
Rs=4*fc; %simulationperiod
t=0:1/Rs:Tu;
tt=0:T/2:Tu;
%Datagenerator
sM=2;
[x,y]=meshgrid((-sM+1):2:(sM-1),(-sM+1):2:(sM-1));
alphabet=x:))+1i*y:));
N=Kmax+1;
rand('state',0);
a=-1+2*round(rand(N,1)).'+i*(-1+2*round(rand(N,1))).';
A=length(a);
info=zeros(FS,1);
info(1:(A/2))=[a(1:(A/2)).'];
info((FS-((A/2)-1)):FS)=[a(((A/2)+1):A).'];
carriers=FS.*ifft(info,FS);
%Upconverter
L=length(carriers);
chips=[carriers.';zeros((2*q)-1,L)];
p=1/Rs:1/Rs:T/2;
g=ones(length(p),1);
dummy=conv(g,chips:)));
u=[dummy;zeros(46,1)];
[b,aa]=butter(13,1/20);
uoft=filter(b,aa,u);
delay=64; %Reconstructionfilterdelay
s_tilde=(uoft(delay+(1:length(t))).').*exp(1i*2*pi*fc*t);
s=real(s_tilde);
%OFDMRECEPTION
%Downconversion
r_tilde=exp(-1i*2*pi*fc*t).*s; %(F)
figure(1);
subplot(211);
plot(t,real(r_tilde));
axis([0e-712e-7-6060]);
gridon;
figure(1);
subplot(212);
plot(t,imag(r_tilde));
axis([0e-712e-7-100150]);
gridon;
figure(2);
ff=(Rs)*(1:(q*FS))/(q*FS);
subplot(211);
plot(ff,abs(fft(r_tilde,q*FS))/FS);
gridon;
figure(2);
subplot(212);
pwelch(r_tilde,[],[],[],Rs);
%Carriersuppression
[B,AA]=butter(3,1/2);
r_info=2*filter(B,AA,r_tilde); %Basebandsignalcontinuous-time(G)
figure(3);
subplot(211);
plot(t,real(r_info));
axis([012e-7-6060]);
gridon;
figure(3);
subplot(212);
plot(t,imag(r_info));
axis([012e-7-100150]);
gridon;
figure(4);
f=(2/T)*(1:(FS))/(FS);
subplot(211);
plot(ff,abs(fft(r_info,q*FS))/FS);
gridon;
subplot(212);
pwelch(r_info,[],[],[],Rs);
%Sampling
r_data=real(r_info(1:(2*q):length(t)))... %Basebandsignal,discrete-
time
+1i*imag(r_info(1:(2*q):length(t))); %(H)
figure(5);
subplot(211);
stem(tt(1:20),(real(r_data(1:20))));
axis([012e-7-6060]);
gridon;
figure(5);
subplot(212);
stem(tt(1:20),(imag(r_data(1:20))));
axis([012e-7-100150]);
gridon;
figure(6);
f=(2/T)*(1:(FS))/(FS);
subplot(211);
plot(f,abs(fft(r_data,FS))/FS);
gridon;
subplot(212);
pwelch(r_data,[],[],[],2/T);
%FFT
info_2N=(1/FS).*fft(r_data,FS); %(I)
info_h=[info_2N(1:A/2)info_2N((FS-((A/2)-1)):FS)];
%Slicing
for k=1:N,
a_hat(k)=alphabet((info_h(k)-alphabet)==min(info_h(k)-alphabet)
(J)
end;
figure(7)
plot(info_h((1:A)),'.k');
title('info-hReceivedConstellation')
axissquare;
axisequal;
figure(8)
plot(a_hat((1:A)),'or');
title('a_hat4-QAM')
axissquare;
axisequal;
gridon;
axis([-1.51.5-1.51.5]);
Can you help me? this is urgent!!! thnx
 

sure

5.1 OFDM Transmission

%DVB-T2KTransmission
%Theavailablebandwidthis8MHz
%2Kisintendedformobileservices
clearall;
closeall;
%DVB-TParameters
Tu=224e-6; %usefulOFDMsymbolperiod
T=Tu/2048; %basebandelementaryperiod
G=0; %choiceof1/4,1/8,1/16,and1/32
delta=G*Tu; %guardbandduration
Ts=delta+Tu; %totalOFDMsymbolperiod
Kmax=1705; %numberofsubcarriers
Kmin=0;
FS=4096; %IFFT/FFTlength
q=10; %carrierperiodtoelementaryperiodratio
fc=q*1/T; %carrierfrequency
Rs=4*fc; %simulationperiod
t=0:1/Rs:Tu;
%Datagenerator(A)
M=Kmax+1;
rand('state',0);
a=-1+2*round(rand(M,1)).'+i*(-1+2*round(rand(M,1))).';
A=length(a);
info=zeros(FS,1);
info(1:(A/2))=[a(1:(A/2)).']; %Zeropadding
info((FS-((A/2)-1)):FS)=[a(((A/2)+1):A).'];
%Subcarriersgeneration(B)
carriers=FS.*ifft(info,FS);
tt=0:T/2:Tu;
figure(1);
subplot(211);
stem(tt(1:20),real(carriers(1:20)));

subplot(212);
stem(tt(1:20),imag(carriers(1:20)));
figure(2);
f=(2/T)*(1:(FS))/(FS);
subplot(211);
plot(f,abs(fft(carriers,FS))/FS);
subplot(212);
pwelch(carriers,[],[],[],2/T);
%D/Asimulation
L=length(carriers);
chips=[carriers.';zeros((2*q)-1,L)];
p=1/Rs:1/Rs:T/2;
g=ones(length(p),1); %pulseshape
figure(3);
stem(p,g);
dummy=conv(g,chips:)));
u=[dummy(1:length(t))]; %(C)
figure(4);
subplot(211);
plot(t(1:400),real(u(1:400)));
subplot(212);
plot(t(1:400),imag(u(1:400)));
figure(5);
ff=(Rs)*(1:(q*FS))/(q*FS);
subplot(211);
plot(ff,abs(fft(u,q*FS))/FS);
subplot(212);
pwelch(u,[],[],[],Rs);
[b,a]=butter(13,1/20); %reconstructionfilter
[H,F]=FREQZ(b,a,FS,Rs);
figure(6);
plot(F,20*log10(abs(H)));
uoft=filter(b,a,u); %basebandsignal(D)
figure(7);
subplot(211);
plot(t(80:480),real(uoft(80:480)));
subplot(212);
plot(t(80:480),imag(uoft(80:480)));
figure(8);
subplot(211);
plot(ff,abs(fft(uoft,q*FS))/FS);
subplot(212);
pwelch(uoft,[],[],[],Rs);
%Upconverter
s_tilde=(uoft.').*exp(1i*2*pi*fc*t);
s=real(s_tilde); %passbandsignal(E)
figure(9);
plot(t(80:480),s(80:480));
figure(10);
subplot(211);
%plot(ff,abs(fft(((real(uoft).').*cos(2*pi*fc*t)),q*FS))/FS);
%plot(ff,abs(fft(((imag(uoft).').*sin(2*pi*fc*t)),q*FS))/FS);
plot(ff,abs(fft(s,q*FS))/FS);
subplot(212);
%pwelch(((real(uoft).').*cos(2*pi*fc*t)),[],[],[],Rs);
%pwelch(((imag(uoft).').*sin(2*pi*fc*t)),[],[],[],Rs);
pwelch(s,[],[],[],Rs);

5.2 OFDM Reception

%DVB-T2KReception
clearall;
closeall;
Tu=224e-6; %usefulOFDMsymbolperiod
T=Tu/2048; %basebandelementaryperiod
G=0; %choiceof1/4,1/8,1/16,and1/32
delta=G*Tu; %guardbandduration
Ts=delta+Tu; %totalOFDMsymbolperiod
Kmax=1705; %numberofsubcarriers
Kmin=0;
FS=4096; %IFFT/FFTlength
q=10; %carrierperiodtoelementaryperiodratio
fc=q*1/T; %carrierfrequency
Rs=4*fc; %simulationperiod
t=0:1/Rs:Tu;
tt=0:T/2:Tu;
%Datagenerator
sM=2;
[x,y]=meshgrid((-sM+1):2:(sM-1),(-sM+1):2:(sM-1));
alphabet=x:))+1i*y:));
N=Kmax+1;
rand('state',0);
a=-1+2*round(rand(N,1)).'+i*(-1+2*round(rand(N,1))).';
A=length(a);
info=zeros(FS,1);
info(1:(A/2))=[a(1:(A/2)).'];
info((FS-((A/2)-1)):FS)=[a(((A/2)+1):A).'];
carriers=FS.*ifft(info,FS);
%Upconverter
L=length(carriers);
chips=[carriers.';zeros((2*q)-1,L)];
p=1/Rs:1/Rs:T/2;
g=ones(length(p),1);
dummy=conv(g,chips:)));
u=[dummy;zeros(46,1)];
[b,aa]=butter(13,1/20);
uoft=filter(b,aa,u);
delay=64; %Reconstructionfilterdelay
s_tilde=(uoft(delay+(1:length(t))).').*exp(1i*2*pi*fc*t);
s=real(s_tilde);
%OFDMRECEPTION
%Downconversion
r_tilde=exp(-1i*2*pi*fc*t).*s; %(F)
figure(1);
subplot(211);
plot(t,real(r_tilde));
axis([0e-712e-7-6060]);
gridon;
figure(1);
subplot(212);
plot(t,imag(r_tilde));
axis([0e-712e-7-100150]);
gridon;
figure(2);
ff=(Rs)*(1:(q*FS))/(q*FS);
subplot(211);
plot(ff,abs(fft(r_tilde,q*FS))/FS);
gridon;
figure(2);
subplot(212);
pwelch(r_tilde,[],[],[],Rs);
%Carriersuppression
[B,AA]=butter(3,1/2);
r_info=2*filter(B,AA,r_tilde); %Basebandsignalcontinuous-time(G)
figure(3);
subplot(211);
plot(t,real(r_info));
axis([012e-7-6060]);
gridon;
figure(3);
subplot(212);
plot(t,imag(r_info));
axis([012e-7-100150]);
gridon;
figure(4);
f=(2/T)*(1:(FS))/(FS);
subplot(211);
plot(ff,abs(fft(r_info,q*FS))/FS);
gridon;
subplot(212);
pwelch(r_info,[],[],[],Rs);
%Sampling
r_data=real(r_info(1:(2*q):length(t)))... %Basebandsignal,discrete-
time
+1i*imag(r_info(1:(2*q):length(t))); %(H)
figure(5);
subplot(211);
stem(tt(1:20),(real(r_data(1:20))));
axis([012e-7-6060]);
gridon;
figure(5);
subplot(212);
stem(tt(1:20),(imag(r_data(1:20))));
axis([012e-7-100150]);
gridon;
figure(6);
f=(2/T)*(1:(FS))/(FS);
subplot(211);
plot(f,abs(fft(r_data,FS))/FS);
gridon;
subplot(212);
pwelch(r_data,[],[],[],2/T);
%FFT
info_2N=(1/FS).*fft(r_data,FS); %(I)
info_h=[info_2N(1:A/2)info_2N((FS-((A/2)-1)):FS)];
%Slicing
for k=1:N,
a_hat(k)=alphabet((info_h(k)-alphabet)==min(info_h(k)-alphabet)
(J)
end;
figure(7)
plot(info_h((1:A)),'.k');
title('info-hReceivedConstellation')
axissquare;
axisequal;
figure(8)
plot(a_hat((1:A)),'or');
title('a_hat4-QAM')
axissquare;
axisequal;
gridon;
axis([-1.51.5-1.51.5]);
Can you help me? this is urgent!!! thnx


can u help me with the receiver code of the ofdm
in the following lines the no.
52,47,76,84,85,89,94,105 and 108

matlab is showing errors in them..i will be very thankful to you!!!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top