BER for BPSK through frequency selective fading channel using rayleighchan function and rls algorithm for adaptive equalizer

4 次查看(过去 30 天)
please help me with my project I need to measure the performance evaluation of BPSK through a three path frequency selective fading channel... I search in the help browser of the matlab and I found the following code but it doesn't work correctly.. so if you please help me and I will very thankful clear
clc
close all
k=0;
for EsNodB=27:5:27
s1=RandStream('mrg32k3a','Seed',0);
s4=RandStream('mrg32k3a','Seed',1);
s5=RandStream('mrg32k3a','Seed',2);
errcount=0;
Tsym = 1e-6; % Symbol period (s)
bitsPerSymbol = 1; % Number of bits per BPSK symbol
M = 2.^bitsPerSymbol; % BPSK alphabet size (number of modulation levels)
nPayload = 40; % Number of payload symbols
nTrain = 10; % Number of training symbols
nTail = 20; % Number of tail symbols
hStream = RandStream.create('mt19937ar', 'seed', 12345);
hStream1 = RandStream.create('mt19937ar', 'seed', 12354);
for i=1:1:1
pskmodObj = modem.pskmod(M); % modulator object
xTextSym=randi(s1, [0 M-1], 1, nPayload)
xText = modulate(pskmodObj, xTextSym)
% Training sequence symbols
xTrainSym = randi(hStream, [0 M-1], 1, nTrain);
% Modulated training sequence
xTrain = modulate(pskmodObj, xTrainSym);
% Tail sequence symbols
xTailSym = randi(hStream1, [0 M-1], 1, nTail);
% Modulated tail sequence
xTail = modulate(pskmodObj, xTailSym);
nSymFilt = 8; % Number of symbol periods spanned by each filter
osfFilt = 4; % Oversampling factor for filter (samples per symbol)
rolloff =0.25; % Rolloff factor
Tsamp = Tsym/osfFilt; % TX signal sample period (s)
orderFilt = nSymFilt*osfFilt; % Filter order (number of taps - 1) % Filter responses and structures
hTxFilt = fdesign.interpolator(osfFilt, 'Square Root Raised Cosine', ... osfFilt, 'N,Beta', orderFilt, rolloff)
hRxFilt = fdesign.decimator(osfFilt, 'Square Root Raised Cosine', ... osfFilt, 'N,Beta', orderFilt, rolloff)
hDTxFilt = design(hTxFilt)
hDRxFilt = design(hRxFilt)
hDTxFilt.PersistentMemory = true; hDRxFilt.PersistentMemory = true;
% Multipath channel
fd = 0; % Maximum Doppler shift (Hz)
chan = rayleighchan(Tsamp, fd); % Create channel object.
chan.PathDelays = [0 0.4 0.9 ]*Tsym; % Path delay vector (s)
chan.AvgPathGaindB = [0 -15 -20]; % Average path gain vector (dB)
chan.ResetBeforeFiltering = 0; % Allow state retention across blocks.
delay = chan.ChannelFilterDelay
%simName = 'Linear equalization for frequency-selective fading';
ri=filter(chan,xText)
rx=filter(chan,xTrain)
snrdB = EsNodB - 10*log10(osfFilt); % Signal-to-noise ratio per sample (dB)
%n = randn(s4,1,nPayload) + 1i*randn(s5,1,nPayload); % white gaussian noise, 0dB variance
n = randn(s4,1,nPayload); % white gaussian noise, 0dB variance
std=sqrt(10^(-snrdB/10));
ni=std*n;
%ri1=ri+ni;
% Adaptive equalizer
nWeights = 8;
forgetFactor = 0.99; % RLS algorithm forgetting factor
alg = rls(forgetFactor); % RLS algorithm object
eqObj = lineareq(nWeights, alg) % Equalizer object
eqObj.RefTap = 3; % Reference tap
y = equalize(eqObj,ri,rx)
%disp('y');disp(y);
pskdmodObj = modem.pskdemod(M);
y1 = demodulate(pskdmodObj, y)
%y1 = real(y)>0;
disp('y1');disp(y1);
%nErr = size(find(xTextSym- y1),2);
%for j=1:1:100 % if y1(j)~=xTextSym(j) % errcount=errcount+1; % end % end
%errcount=errcount+nErr;
%reset(pskmodObj); %reset(pskdmodObj); % Compute bit error rate, taking delay into account. % Truncate to account for channel delay.
xTextSym_trunc = xTextSym(1:end-delay); y1_trunc = y1(delay+1:end);
[num,ber] = biterr(xTextSym_trunc,y1_trunc) % Bit error rate
errcount=errcount+ber;
end
k=k+1;
%BER(k)=ber
BER(k)=(errcount/1)
theoryBerAWGN(k) = 0.5*erfc(sqrt(10^(snrdB/10))) % theoretical ber
%EbN0Lin = 10^(snrdB/10);
%theoryBer(k) = 0.5*(1-sqrt(EbN0Lin/(EbN0Lin+1)))
theoryBer(k) = berfading(snrdB,'dpsk',M,1)
snr(k) =snrdB
end
figure
%semilogy(snr,theoryBerAWGN,'cd-','LineWidth',2);
%hold on
semilogy(snr,theoryBer,'bp-','LineWidth',2);
hold on
semilogy(snr,BER,'mx-','LineWidth',2);
grid on
legend('Rayleigh-Theory', 'Rayleigh-Simulation');
%legend('AWGN-Theory','Rayleigh-Theory', 'Rayleigh-Simulation');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation in Rayleigh channel');
grid on

回答(2 个)

shaik
shaik 2014-1-19
clc
close all
k=40;
for EsNodB=1:k
s1=RandStream('mrg32k3a','Seed',0);
s4=RandStream('mrg32k3a','Seed',1);
s5=RandStream('mrg32k3a','Seed',2);
errcount=0;
Tsym = 1e-6; % Symbol period (s)
bitsPerSymbol = 1; % Number of bits per BPSK symbol
M = 2.^bitsPerSymbol; % BPSK alphabet size (number of modulation levels)
nPayload = 40; % Number of payload symbols
nTrain = 10; % Number of training symbols
nTail = 20; % Number of tail symbols
hStream = RandStream.create('mt19937ar', 'seed', 12345);
hStream1 = RandStream.create('mt19937ar', 'seed', 12354);
for i=1:1:1
pskmodObj = modem.pskmod(M); % modulator object
xTextSym=randi(s1, [0 M-1], 1, nPayload)
xText = modulate(pskmodObj, xTextSym)
% Training sequence symbols
xTrainSym = randi(hStream, [0 M-1], 1, nTrain);
% Modulated training sequence
xTrain = modulate(pskmodObj, xTrainSym);
% Tail sequence symbols
xTailSym = randi(hStream1, [0 M-1], 1, nTail);
% Modulated tail sequence
xTail = modulate(pskmodObj, xTailSym);
nSymFilt = 8; % Number of symbol periods spanned by each filter
osfFilt = 4; % Oversampling factor for filter (samples per symbol)
rolloff =0.25; % Rolloff factor
Tsamp = Tsym/osfFilt; % TX signal sample period (s)
orderFilt = nSymFilt*osfFilt; % Filter order (number of taps - 1) % Filter responses and structures
hTxFilt = fdesign.interpolator(osfFilt, 'Square Root Raised Cosine', osfFilt, 'N,Beta', orderFilt, rolloff)
hRxFilt = fdesign.decimator(osfFilt, 'Square Root Raised Cosine',osfFilt, 'N,Beta', orderFilt, rolloff)
hDTxFilt = design(hTxFilt)
hDRxFilt = design(hRxFilt)
hDTxFilt.PersistentMemory = true; hDRxFilt.PersistentMemory = true;
% Multipath channel
fd = 0; % Maximum Doppler shift (Hz)
chan = rayleighchan(Tsamp, fd); % Create channel object.
chan.PathDelays = [0 0.4 0.9 ]*Tsym; % Path delay vector (s)
chan.AvgPathGaindB = [0 -15 -20]; % Average path gain vector (dB)
chan.ResetBeforeFiltering = 0; % Allow state retention across blocks.
delay = chan.ChannelFilterDelay
%simName = 'Linear equalization for frequency-selective fading';
ri=filter(chan,xText)
rx=filter(chan,xTrain)
snrdB = EsNodB - 10*log10(osfFilt); % Signal-to-noise ratio per sample (dB)
n = randn(s4,1,nPayload) + 1i*randn(s5,1,nPayload); % white gaussian noise, 0dB variance
n = randn(s4,1,nPayload); % white gaussian noise, 0dB variance
std=sqrt(10^(-snrdB/10));
ni=std*n;
ri1=ri+ni;
% Adaptive equalizer
nWeights = 8;
forgetFactor = 0.99; % RLS algorithm forgetting factor
alg = rls(forgetFactor); % RLS algorithm object
eqObj = lineareq(nWeights, alg) % Equalizer object
eqObj.RefTap = 3; % Reference tap
y = equalize(eqObj,ri,rx)
disp('y');disp(y);
pskdmodObj = modem.pskdemod(M);
y1 = demodulate(pskdmodObj, y)
y1 = real(y)>0;
disp('y1');disp(y1);
nErr = size(find(xTextSym- y1),2);
for j=1:1:40 if y1(j)~=xTextSym(j) errcount=errcount+1; end end
errcount=errcount+nErr;
reset(pskmodObj); reset(pskdmodObj); % Compute bit error rate, taking delay into account. % Truncate to account for channel delay.
xTextSym_trunc = xTextSym(1:end-delay); y1_trunc = y1(delay+1:end);
[num,ber] = biterr(xTextSym_trunc,y1_trunc) % Bit error rate
errcount=errcount+ber;
end
k=k+1;
BER(k)=ber
BER(k)=(errcount/1)
theoryBerAWGN(k) = 0.5*erfc(sqrt(10^(snrdB/10))) % theoretical ber
EbN0Lin = 10^(snrdB/10);
theoryBer(k) = 0.5*(1-sqrt(EbN0Lin/(EbN0Lin+1)))
theoryBer(k) = berfading(snrdB,'dpsk',M,1)
snr(k) =snrdB
end snr figure
semilogy(snr,theoryBerAWGN,'*','LineWidth',2);
hold on
semilogy(snr,theoryBer,'g-*','LineWidth',2);
hold on
semilogy(snr,BER,'r-*','LineWidth',2);
grid on
legend('Rayleigh-Theory', 'Rayleigh-Simulation');
legend('AWGN-Theory','Rayleigh-Theory', 'Rayleigh-Simulation');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation in Rayleigh channel');
grid on
this is the coding whose error has been removed

Sophiya
Sophiya 2025-3-18
clc;
clear;
close all;
% Simulation Parameters
N = 1e6; % Number of bits
EbN0_dB = 0:2:20; % SNR range in dB
BER_rayleigh = zeros(size(EbN0_dB));
% Generate random binary data (0s and 1s)
bits = randi([0 1], 1, N);
% BPSK Modulation (0 -> -1, 1 -> +1)
bpsk_mod = 2*bits - 1;
% Rayleigh fading channel
h = (randn(1, N) + 1j*randn(1, N)) / sqrt(2); % Complex fading (Rayleigh)
for i = 1:length(EbN0_dB)
% Convert Eb/N0 from dB to linear scale
EbN0 = 10^(EbN0_dB(i) / 10);
noise_variance = 1 / (2*EbN0);
% Apply Rayleigh fading
faded_signal = h .* bpsk_mod;
% Add AWGN noise
noise = sqrt(noise_variance) * (randn(1, N) + 1j*randn(1, N));
received_signal = faded_signal + noise;
% Coherent Detection (assuming perfect channel estimation)
received_equalized = received_signal ./ h;
% BPSK Demodulation
bits_received = real(received_equalized) > 0;
% Compute Bit Error Rate (BER)
BER_rayleigh(i) = sum(bits ~= bits_received) / N;
end
% Theoretical BER for BPSK in Rayleigh fading
theoretical_BER_rayleigh = 0.5 * (1 - sqrt(EbN0_dB ./ (EbN0_dB + 1)));
% Plot Results
figure;
semilogy(EbN0_dB, BER_rayleigh, 'ro-', 'LineWidth', 2);
hold on;
semilogy(EbN0_dB, theoretical_BER_rayleigh, 'b--', 'LineWidth', 2);
grid on;
xlabel('Eb/N0 (dB)');
ylabel('Bit Error Rate (BER)');
legend('Simulated BER (Rayleigh)', 'Theoretical BER (Rayleigh)');
title('BPSK Performance in Rayleigh Fading Channel');
hold off;clear;close all;% Simulation ParametersN = 1e6; % Number of bitsEbN0_dB = 0:2:20; % SNR range in dBBER_rayleigh = zeros(size(EbN0_dB));% Generate random binary data (0s and 1s)bits = randi([0 1], 1, N); % BPSK Modulation (0 -> -1, 1 -> +1)bpsk_mod = 2*bits - 1;% Rayleigh fading channelh = (randn(1, N) + 1j*randn(1, N)) / sqrt(2); % Complex fading (Rayleigh)for i = 1:length(EbN0_dB) % Convert Eb/N0 from dB to linear scale EbN0 = 10^(EbN0_dB(i) / 10); noise_variance = 1 / (2*EbN0); % Apply Rayleigh fading faded_signal = h .* bpsk_mod; % Add AWGN noise noise = sqrt(noise_variance) * (randn(1, N) + 1j*randn(1, N)); received_signal = faded_signal + noise; % Coherent Detection (assuming perfect channel estimation) received_equalized = received_signal ./ h; % BPSK Demodulation bits_received = real(received_equalized) > 0; % Compute Bit Error Rate (BER) BER_rayleigh(i) = sum(bits ~= bits_received) / N;end% Theoretical BER for BPSK in Rayleigh fadingtheoretical_BER_rayleigh = 0.5 * (1 - sqrt(EbN0_dB ./ (EbN0_dB + 1)));% Plot Resultsfigure;semilogy(EbN0_dB, BER_rayleigh, 'ro-', 'LineWidth', 2);hold on;semilogy(EbN0_dB, theoretical_BER_rayleigh, 'b--', 'LineWidth', 2);grid on;xlabel('Eb/N0 (dB)');ylabel('Bit Error Rate (BER)');legend('Simulated BER (Rayleigh)', 'Theoretical BER (Rayleigh)');title('BPSK Performance in Rayleigh Fading Channel');hold off;

类别

Help CenterFile Exchange 中查找有关 Propagation and Channel Models 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by