ofdm carrier frequency offset estimation code
조회 수: 22 (최근 30일)
이전 댓글 표시
%Initilization %%%%%%%%%%%%%%%%%%%%
nBitPerSym = 64;
nSym = 10^3;
nFFT = 64; % fft size
nDSC = 64; % number of data subcarriers
samplesPerSymbol = 1;
Ts = 1e-6; % Sample time of each symbol / bit
samplesPerFrame = nBitPerSym;
carriersQ = (1:nBitPerSym) ;
% NORMALIZED DOPPLER SHIFT
ep = [0 .15 .3];
EbN0dB = [1:20]; % bit to noise ratio
% Input Data Generation
ipBit = rand(1,nBitPerSym*nSym) > 0.5; % random 1's and 0's
oddData = ipBit(1:2:end);
evenData = ipBit(2:2:end);
qpskModulated = sqrt(1/2)*(1i*(2*oddData-1)+(2*evenData-1)); %QPSK Mapping
for lll= 1:length(ep)
for iii=EbN0dB,
k1 = 1;
for n1 = 1:nSym/2
ofdm_symbol = zeros(1,nFFT);
% Map modulated data to FFT bins in OFDM symbol
ofdm_symbol(carriersQ) = qpskModulated(k1:k1+nBitPerSym-1);
% Time Signal to transmit
tx_signal = (nFFT/sqrt(nDSC))*ifft(ofdm_symbol,nFFT);
% DOPPLER SHIFT
freqOffset = 0; phaseOffset = 0;
hPFO = comm.PhaseFrequencyOffset('FrequencyOffset', freqOffset, ... 'PhaseOffset', phaseOffset, ... 'SampleRate', samplesPerSymbol/Ts);
rx_signal1l = step(hPFO,tx_signal);
rx_signal = rx_signal1l.';
%%========================= Carrier Recovery =================
hDelayInstFreq = dsp.Delay;
hMovAve = dsp.DigitalFilter('TransferFunction','FIR (all zeros)', ... 'Numerator', ones(1,100)/100);
hCumSum = dsp.CumulativeSum('Dimension','Channels (running sum)', ... 'FrameBasedProcessing', true);
%% Calculate the frequency shift estimate
P = 2;
currInstFreq = rx_signal.^(2*P);
prevInstFreq = step(hDelayInstFreq, currInstFreq);
freqShiftEst1 = currInstFreq .* conj(prevInstFreq);
% Average over 1 frame
freqShiftEst = mean(freqShiftEst1);
% Moving average over 100 frames
freqShiftEst = step(hMovAve, freqShiftEst);
freqShiftEst = angle(freqShiftEst) / (2*P);
% Convert digital frequency to Hertz
freqShiftEst = freqShiftEst / (2*pi*Ts);
%% Apply frequency correction
freqCorr = repmat(-freqShiftEst*Ts, samplesPerFrame, 1);
% Calculate cumulative phase shift
freqCorr = step(hCumSum, freqCorr);
% Apply frequency shift correction
rxSym = rx_signal .* exp(1i*2*pi*freqCorr);
rxSym = abs(rx_signal) .* exp(1i*freqCorr);
rxSym = rxSym.';
% FFT
received_ofdm = (sqrt(nDSC)/nFFT)*fft(rxSym.', nFFT);
% Extract data from carriers in OFDM symbol
received_symbolsQ(k1:k1+nBitPerSym-1) = received_ofdm(carriersQ);
k1 = k1 + nBitPerSym;
end
% PERFROM DEMODULATION
yFQ=received_symbolsQ;
%--------------Demodulation-----------------------------
%Threshold Detector
TX = reshape(yFQ.',nBitPerSym*nSym/2,1).';
detected_real = real(TX)>=0;
detected_img = imag(TX)>=0;
estimatedBits=reshape([detected_img;detected_real],1,[]);
% counting the errors
nErrQ1(lll,iii) = size(find(estimatedBits - ipBit),2)/(nSym*nBitPerSym);
end end
% Plotting output data
close all;
figure
semilogy(EbN0dB, nErrQ1(1,:),'r--');
hold on
semilogy(EbN0dB, nErrQ1(2,:),'r*-');
semilogy(EbN0dB, nErrQ1(3,:),'r.-');
axis([1 20 10^-4 1])
grid on
legend('QPSK- CFO Recovery ep=0','QPSK- CFO Recovery ep= 0.15','QPSK- CFO Recovery ep=0.3');
xlabel('Eb/No, dB')
ylabel('Bit Error Rate')
title('Bit error probability curve for QPSK with Frequency estimation and recovery OFDM') =========================================================================== 0 Comments Comment on this Question
댓글 수: 0
답변 (1개)
Zeyad Qasem
2018년 10월 8일
Hello, Did you solve this issue ?
Could you please share the solution with us
thnx
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Detection, Range and Doppler Estimation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!