- #1
O.J.
- 199
- 0
Homework Statement
I am simulating an OFDM transceiver using MATLAB. I am trying to investigate the effect of frequency offsets on the system performance by measuring different offsets against their respective bit error rate with a SNR of 10 dB.
Homework Equations
All equations and variables are presented in the code. I am uncertain as to what is the fundamental frequency though but I used 1/T (where T is the symbol period without guard time of each subcarrier).
The Attempt at a Solution
Here is my code:
%% OFDM Model (CP and GT) with AWGN at different SNR's
% NOTE! OFDM Parameters used in WiMAX are found in the ebook page 42!
%% OFDM parameters
Tu = 0.001; %symbol period for each subcarrier
N = 128; %number of carriers
R = 1/8; %guard time ratio (WiMAX standard)
G = Tu*R; %guard time
Ti = Tu + G; %OFDM symbol period
T = Ti/N; %original symbol period
fi = 1/Ti; %symbol rate of each datastream
f = fi*N;
Q = 8; %sampling frequency factor (should be chosen such that Q*R = whole number)
Fs = Q*f; %sampling frequency
z = 4*N;
t = 0:1/Fs:(z*Ti-1/Fs); %simulation period (upper limit should
%be an integer K ==> K*N*Ti -1/Fs
%% TRANSMITTER
%generate message
L = length(t)/Q;
M1 = round(rand(1,L));
tn = 0:Q/Fs:(z*Ti-1/Fs);
%using BPSK (mapping 0's to -1's)
M=2*M1-1;
stem (tn,M); %plot the original message (BPSK)
xlabel('Time (seconds)');
ylabel('Digital Message Signal (in discrete bits)');
title ('Message vs Time');
%S/P conversion
A = reshape(M,N,L/N);
%modulate each subcarrier using IFFT
B = ifft(A);
%P/S conversion
C = reshape(B,1,L);
%oversample by a factor of Q (DAC ~)
D=ones(Q,1)*C;
D=conj(D(:)');
%guard time insertion
i=1;
k=1;
for t0=1:L;
for t1=1:R*Q;
D(1,k*Q-R*Q+i)=0;
i=i+1;
end
k=k+1;
i=1;
end
%cyclic prefix insertion
j=1;
i=Q-R*Q+1;
k=1;
a=1;
for f = 1:length(C);
for g = 1:R*Q;
D(:,Q*k-R*Q+j) = D(:,a);
j=j+1;
a=a+1;
end
j=1;
a=1+k*Q;
k=k+1;
end
plot (t,D); %plot the OFDM signal
xlabel ('Time (seconds)');
ylabel ('OFDM Signal');
title ('OFDM Signal (with guard time & cyclic prefix) vs Time');
%% Add frequency offset
SNR = 10;
index=1;
f0 = 1/Tu;
S = zeros(2,10);
BER = 0;
BER1 = 0;
per = 0;
N_max = 100;
h = modem.pskdemod(2,pi);
for tr = 0:0.05:0.5
D1 = D*exp(2*pi*sqrt(-1)*per*f0);
for tk = 1:N_max
%% RECEIVER
%undersampling (ADC ~) removing Tg and CP
Dn = awgn(D1, SNR,'measured');
E = zeros(1,L);
i = 1;
j = 1;
for t0=1:L;
E(1,i) = Dn(1,j);
i=i+1;
j=j+Q;
if j>Q*L
j=j-1;
end
end
%S/P
F = reshape(E, N, L/N);
%demodulation
G = fft(F);
%P/S
Mr = reshape(G, 1, L);
Mr = real(Mr);
%BPSK Demodulation
M2 = demodulate(h,Mr);
%comparing the received and the sent message (0's & 1's)
bit_error = length(find(M1~=M2));
BER = bit_error/length(M2);
BER1 = BER1+BER;
end
S(1,index) = BER1/N_max;
S(2,index) = per;
per = per + 0.05;
index = index + 1;
BER1 = 0;
BER = 0;
end
semilogy(S(2,:),S(1,
xlabel ('Normalized frequency offset')
ylabel ('Bit Error Rate')
title ('BER vs Frequency Offset')
grid on