MATLAB Answers

How can I simulate OFDM with Rayleigh fading by using Communications System Toolbox?

132 ビュー (過去 30 日間)
QuestionAsker
QuestionAsker 2017 年 12 月 14 日
I would like to adapt the example code in the following link such that the AWGN channel is preceded by a Rayleigh fading channel.
https://www.mathworks.com/help/comm/gs/qpsk-and-ofdm-with-matlab-system-objects-1.html
My code gives a bit-error rate of approximately 0.5, regardless of the signal-to-noise ratio. Could you please tell me what I am doing wrong?
M = 4; % Modulation alphabet
k = log2(M); % Bits/symbol
numSC = 128; % Number of OFDM subcarriers
cpLen = 32; % OFDM cyclic prefix length
maxBitErrors = 1e2; % Maximum number of bit errors
maxNumBits = 1e7; % Maximum number of bits transmitted
qpskMod = comm.QPSKModulator('BitInput',true);
qpskDemod = comm.QPSKDemodulator('BitOutput',true);
ofdmMod = comm.OFDMModulator('FFTLength',numSC,'CyclicPrefixLength',cpLen);
ofdmDemod = comm.OFDMDemodulator('FFTLength',numSC,'CyclicPrefixLength',cpLen);
rayleighChannel = comm.RayleighChannel;
awgnChannel = comm.AWGNChannel('NoiseMethod','Variance', 'VarianceSource','Input port');
errorRate = comm.ErrorRate('ResetInputPort',true);
ofdmDims = info(ofdmMod);
numDC = ofdmDims.DataInputSize(1);
frameSize = [k*numDC 1];
EbNoVec = (0:20)';
snrVec = EbNoVec + 10*log10(k) + 10*log10(numDC/numSC);
berVec = zeros(length(EbNoVec),3);
errorStats = zeros(1,3);
for m = 1:length(EbNoVec)
snr = snrVec(m);
while errorStats(2) <= maxBitErrors && errorStats(3) <= maxNumBits
dataIn = randi([0,1],frameSize); % Generate binary data
qpskTx = qpskMod(dataIn); % Apply QPSK modulation
txSig = ofdmMod(qpskTx); % Apply OFDM modulation
fadedSig = rayleighChannel(txSig);
powerDB = 10*log10(var(fadedSig)); % Calculate Tx signal power
noiseVar = 10.^(0.1*(powerDB-snr)); % Calculate the noise variance
rxSig = awgnChannel(fadedSig,noiseVar); % Pass the signal through a noisy channel
qpskRx = ofdmDemod(rxSig); % Apply OFDM demodulation
dataOut = qpskDemod(qpskRx); % Apply QPSK demodulation
errorStats = errorRate(dataIn,dataOut,0); % Collect error statistics
end
berVec(m,:) = errorStats; % Save BER data
errorStats = errorRate(dataIn,dataOut,1); % Reset the error rate calculator
end
berTheory = berawgn(EbNoVec,'psk',M,'nondiff');
berTheory_2 = berfading(EbNoVec,'psk',M,1);
figure
semilogy(EbNoVec,berVec(:,1),'*')
hold on
semilogy(EbNoVec,berTheory_2)
legend('Simulation','Theory','Location','Best')
xlabel('Eb/No (dB)')
ylabel('Bit Error Rate')
grid on
hold off

  0 件のコメント

サインインしてコメントする。

回答 (5 件)

imane khelouani
imane khelouani 2019 年 7 月 8 日
Did you find the problem with your program ?

  0 件のコメント

サインインしてコメントする。


mustafa sami
mustafa sami 2020 年 2 月 15 日
Did you find the problem with your program ?

  0 件のコメント

サインインしてコメントする。


Yasantha Samarawickrama
Yasantha Samarawickrama 2020 年 9 月 8 日
I am encountering the same problem? Can you please share if you found the solution for this issue?

  0 件のコメント

サインインしてコメントする。


imane khelouani
imane khelouani 2020 年 9 月 9 日
I think the problem is when you generate the rayleigh channel, try to add some inputs such as the sampling time/frequency, the maximum doppler shift and you can add also the delays and there pdp,
Here is an exampe of how I simulate an EVA channel :
DS = 1e-9;
Tau = [0 30 150 310 370 710 1090 1730 2510]*DS;
Pdp = [0 -1.5 -1.4 -3.6 -0.6 -9.1 -7 -12 -16.9];
fd = 20/3.6*fc/c; % Maximum Doppler Shift
chan = rayleighchan(Ts, fd, Tau, Pdp);
with Ts being the sampling time,

  0 件のコメント

サインインしてコメントする。


Ahmed Aladi
Ahmed Aladi 2020 年 9 月 24 日
clear all;
M = 4; % Modulation alphabet
k = log2(M); % Bits/symbol
numSC = 128; % Number of OFDM subcarriers
cpLen = 32; % OFDM cyclic prefix length
maxBitErrors = 1e3; % Maximum number of bit errors
maxNumBits = 1e7; % Maximum number of bits transmitted
qpskMod = comm.QPSKModulator('BitInput',true);
qpskDemod = comm.QPSKDemodulator('BitOutput',true);
ofdmMod = comm.OFDMModulator('FFTLength',numSC,'CyclicPrefixLength',cpLen);
ofdmDemod = comm.OFDMDemodulator('FFTLength',numSC,'CyclicPrefixLength',cpLen);
awgnChannel = comm.AWGNChannel('NoiseMethod','Variance', 'VarianceSource','Input port');
errorRate = comm.ErrorRate('ResetInputPort',true);
ofdmDims = info(ofdmMod);
numDC = ofdmDims.DataInputSize(1);
frameSize = [k*numDC 1];
EbNoVec = (0:20)';
snrVec = EbNoVec + 10*log10(k) + 10*log10(numDC/numSC);
berVec = zeros(length(EbNoVec),3);
errorStats = zeros(1,3);
for m = 1:length(EbNoVec)
snr = snrVec(m);
while errorStats(2) <= maxBitErrors && errorStats(3) <= maxNumBits
dataIn = randi([0,1],frameSize); % Generate binary data
qpskTx = qpskMod(dataIn); % Apply QPSK modulation
txSig = ofdmMod(qpskTx); % Apply OFDM modulation
%fadedSig = rayleighChannel(txSig);
%% Rayleigh Fading Channel
taps=3; %number of channel taps
h = [randn(1,taps)+j*randn(1,taps) zeros(1,size(txSig,1)-taps)].' ; % generate channel taps and pad with zeros
h_t = toeplitz(h); % channel matrix
fadedSig=h_t*txSig; % Apply Rayleigh fading
powerDB = 10*log10(var(fadedSig)); % Calculate Tx signal power
noiseVar = 10.^(0.1*(powerDB-snr)); % Calculate the noise variance
rxSig = awgnChannel(fadedSig,noiseVar); % Pass the signal through a noisy channel
rxSig_eq = inv(h_t'*h_t)*(h_t')*rxSig; % zero forcing equalization
% Apply OFDM demodulation
qpskRx = ofdmDemod(rxSig_eq);
dataOut = qpskDemod(qpskRx); % Apply QPSK demodulation
errorStats = errorRate(dataIn,dataOut,0); % Collect error statistics
end
berVec(m,:) = errorStats; % Save BER data
errorStats = errorRate(dataIn,dataOut,1); % Reset the error rate calculator
end
berTheory = berawgn(EbNoVec,'psk',M,'nondiff');
berTheory_2 = berfading(EbNoVec,'psk',M,1);
figure
semilogy(EbNoVec,berVec(:,1),'*')
hold on
semilogy(EbNoVec,berTheory_2)
legend('Simulation','Theory','Location','Best')
xlabel('Eb/No (dB)')
ylabel('Bit Error Rate')
grid on
hold off

  3 件のコメント

Yasantha Samarawickrama
Yasantha Samarawickrama 2020 年 10 月 16 日
Hi Ahmed! Many thanks for the solution. It works fine with the tap based Rayleigh channel. However, when i use comm.RayleighChannel block it gives i Bit error rate around 0.5 like random decoding. can't we use comm.RayleighChannel block in MATLAB so then we can customize channel properties better? Thanks in advance!
Ahmed Aladi
Ahmed Aladi 2020 年 10 月 16 日
Enable PathGainsOutputPort then get the path gains and use them for the equalization.
clear all;
M = 4; % Modulation alphabet
k = log2(M); % Bits/symbol
numSC = 128; % Number of OFDM subcarriers
cpLen = 32; % OFDM cyclic prefix length
maxBitErrors = 5e3; % Maximum number of bit errors
maxNumBits = 1e7; % Maximum number of bits transmitted
qpskMod = comm.QPSKModulator('BitInput',true);
qpskDemod = comm.QPSKDemodulator('BitOutput',true);
ofdmMod = comm.OFDMModulator('FFTLength',numSC,'CyclicPrefixLength',cpLen);
ofdmDemod = comm.OFDMDemodulator('FFTLength',numSC,'CyclicPrefixLength',cpLen);
rayleighChannel = comm.RayleighChannel;
rayleighChannel.PathGainsOutputPort =true;
%rayleighChannel.PathDelays= [0 1e-3 3e-3 ];
%rayleighChannel.AveragePathGains=[0 -1 -2 ];
awgnChannel = comm.AWGNChannel('NoiseMethod','Variance', 'VarianceSource','Input port');
errorRate = comm.ErrorRate('ResetInputPort',true);
ofdmDims = info(ofdmMod);
numDC = ofdmDims.DataInputSize(1);
frameSize = [k*numDC 1];
EbNoVec = (0:20)';
snrVec = EbNoVec + 10*log10(k) + 10*log10(numDC/numSC);
berVec = zeros(length(EbNoVec),3);
errorStats = zeros(1,3);
for m = 1:length(EbNoVec)
snr = snrVec(m);
while errorStats(2) <= maxBitErrors && errorStats(3) <= maxNumBits
dataIn = randi([0,1],frameSize); % Generate binary data
qpskTx = qpskMod(dataIn); % Apply QPSK modulation
txSig = ofdmMod(qpskTx); % Apply OFDM modulation
[fadedSig pathGains] = rayleighChannel(txSig); % Apply fading and get the path gains
powerDB = 10*log10(var(txSig)); % Calculate Tx signal power
noiseVar = 10.^(0.1*(powerDB-snr)); % Calculate the noise variance
rxSig = awgnChannel(fadedSig,noiseVar); % Pass the signal through a noisy channel
rxSig_eq=rxSig./sum(pathGains, 2); % Equalize
qpskRx = ofdmDemod(rxSig_eq); % Apply OFDM demodulation
dataOut = qpskDemod(qpskRx); % Apply QPSK demodulation
errorStats = errorRate(dataIn,dataOut,0); % Collect error statistics
end
berVec(m,:) = errorStats; % Save BER data
errorStats = errorRate(dataIn,dataOut,1); % Reset the error rate calculator
end
berTheory = berawgn(EbNoVec,'psk',M,'nondiff');
berTheory_2 = berfading(EbNoVec,'psk',M,1);
figure
semilogy(EbNoVec,berVec(:,1),'*')
hold on
semilogy(EbNoVec,berTheory_2)
legend('Simulation','Theory','Location','Best')
xlabel('Eb/No (dB)')
ylabel('Bit Error Rate')
grid on
hold off
Yasantha Samarawickrama
Yasantha Samarawickrama 2020 年 10 月 16 日
Hi Ahmed! Many thanks for your reply. It works fine for Frequency flat fading channels using comm.Rayleighchannel block. However, when the channel becomes Frequency selective, again the BER is high like random decoding. So do you use a different type of Equalization when channel is Frequency selective? Please include a code if you have got. Thanks in advance!

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by