I am trying to solve following error in my code, Error using .* Matrix dimensions must agree.
Show older comments
clear all;
EbN0_dB = 0:2.5:30;
EbN0 = 10.^(EbN0_dB/10); % convert from dB scale
Analytical_BER_ASK = Q(sqrt(EbN0)); % BER of ASK
Analytical_BER_BPSK = Q(sqrt(2*EbN0)); % BER of QPSK and BPSK
L = 1000;
Numerical_BER_ASK = zeros(1,length(EbN0));
Numerical_BER_BPSK = zeros(1,length(EbN0));
for i=1:length(EbN0) % run simulation for each EbN0 value
ASK_error = 0; % to count number of error with ASK
BPSK_error = 0; % to count number of errors with BPSK
noOfL = 0; % to keep track number of bit sequences
while BPSK_error < 100
N0 = 1/(EbN0(i)); % with Eb = 1, N0 = 1/(EbN0)
s = randi([0,1],1,L); % random bit sequence of length L
ASK_TX_signal = s*sqrt(2); % ASK modulated signal
BPSK_RX_signal = 2*s - 1; % BPSK modulated signal
noise = sqrt(N0/2) * randn(1,L); % Gaussian noise;
% Generate the fading channel, it's a Gaussian random variables
channel = sqrt(1/2)*(randn(1,L) + 1i*randn(1,L));
ASK_RX_signal = channel.*ASK_TX_signal + noise; % receive ASK signal
BPSK_RX_signal = channel.*BPSK_RX_signal + noise; % receive BPSK signal
% Before doing demodulation, you do equalizer and co-phases the
% channel
ASK_RX_signal = conj(channel).*ASK_RX_signal;
BPSK_RX_signal = conj(channel).*BPSK_RX_signal;
% demodulate ASK signal with threshold at sqrt(2)/2
ASK_s = double(ASK_RX_signal > sqrt(2)/2);
% demodulate BPSK signal with thresshold at 0;
BPSK_s = double(BPSK_RX_signal > 0);
ASK_error = ASK_error + sum(ASK_s~=s); % count error with ASK
BPSK_error = BPSK_error + sum(BPSK_s~=s); % count error with BPSK
noOfL = noOfL + 1;
end
Numerical_BER_ASK(i) = ASK_error/L/noOfL;
Numerical_BER_BPSK(i) = BPSK_error/L/noOfL;
end
A_ASK = semilogy(EbN0_dB,Analytical_BER_ASK,'-');
hold on
A_BPSK = semilogy(EbN0_dB,Analytical_BER_BPSK,'--');
N_ASK = semilogy(EbN0_dB,Numerical_BER_ASK,'o');
N_BPSK = semilogy(EbN0_dB,Numerical_BER_BPSK,'s');
xlabel('Eb/N0 in dB');
ylabel('BER');
legend([A_ASK A_BPSK N_ASK N_BPSK],'Analytical ASK','Analytical BPSK',...
'Numerical ASK','Numerical BPSK');
Accepted Answer
More Answers (0)
Categories
Find more on BPSK in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!