Error using .* .Matrix dimensions must agree

12 visualizzazioni (ultimi 30 giorni)
psychecrew
psychecrew il 26 Apr 2016
Modificato: John BG il 26 Apr 2016
Hi, I been simulating the data transmission in Rayleigh and AWGN channel. I want to include CRC in the simulation. My code is as follows:
clear
NoBits =4; % number of bits
noPacket=4;
%-------------------------At the transmitter-------------------------------
DataIn =randi([0,1],noPacket,NoBits); % generating 0,1 with equal probability
%~~~~~~~~~~Cyclic Redundancy Check (CRC)~~~~~~~~~~
div=[1 0 0 1]; % predetermined divisor
for i=1:noPacket
[q,r]=deconv(DataIn(i,:),div);
y(i,:)=[DataIn(i,:),zeros(1,3)];
for k=1:NoBits
r(k)=mod(r(k),2);
end
fcs=[zeros(1,3),r]; % frame check sequence
DataOut(i,:)=bitxor(y(i,:),fcs);
end
%~~~~~~~~~~BPSK Modulation~~~~~~~~~~
BPSK1 = 2*DataOut-1; % BPSK modulation 0 -> -1; 1 -> 0
Eb_N0_dB = [-3:35]; % multiple Eb/N0 values
%-------------------------Channel Modelling-------------------------------
for ii = 1:length(Eb_N0_dB)
awgn = 1/sqrt(2)*[randn(1,NoBits) + j*randn(1,NoBits)]; % white gaussian noise, 0dB variance
Ray = 1/sqrt(2)*[randn(1,NoBits) + j*randn(1,NoBits)]; % Rayleigh channel
% Channel and noise Noise addition
y = Ray.*BPSK1 + 10^(-Eb_N0_dB(ii)/20)*awgn;
%----------------------------At the Receiver-------------------------------
% equalization
yHat = y./Ray;
% receiver - hard decision decoding
recDat = real(yHat)>0;
% counting the errors
nErr(ii) = size(find([DataIn-recDat]),2);
end
simBer = nErr/NoBits; % simulated ber
theoryBerAWGN = 0.5*erfc(sqrt(10.^(Eb_N0_dB/10))); % theoretical ber
EbN0Lin = 10.^(Eb_N0_dB/10);
theoryBer = 0.5.*(1-sqrt(EbN0Lin./(EbN0Lin+1)));
% plot
close all
figure
semilogy(Eb_N0_dB,theoryBerAWGN,'cd-','LineWidth',2);
hold on
semilogy(Eb_N0_dB,theoryBer,'bp-','LineWidth',2);
semilogy(Eb_N0_dB,simBer,'mx-','LineWidth',2);
axis([-3 35 10^-5 0.5])
grid on
legend('AWGN-Theory','Rayleigh-Theory', 'Rayleigh-Simulation');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation in Rayleigh channel');
However, i encounter "Error using .* .Matrix dimensions must agree" on line :
y = Ray.*BPSK1 + 10^(-Eb_N0_dB(ii)/20)*awgn;
I know the error must have the problem regarding mismatching of matrix dimension. I have tried repmat and other but, i wonder if there is any other solution that can make the BER become more accurate and reliable? Any help would be appreciated. Thank You.

Risposta accettata

John BG
John BG il 26 Apr 2016
Modificato: John BG il 26 Apr 2016
In line
% Channel and noise Noise addition
y = Ray.*BPSK1 + 10^(-Eb_N0_dB(ii)/20)*awgn;
The
Ray.*BPSK1
only works if instead you start the line with
y=BPSK1'*Ray'+ ..
-0.478487048890906 + 3.821695518247046i
1.171402651187593 - 0.797604495033111i
1.249572268765731 - 1.118081175144724i
-0.896870514142436 - 0.718652054769934i
1.171402651187593 - 0.797604495033111i
1.249572268765731 - 1.118081175144724i
-1.524104405810888 + 2.634337724947769i
yet
BPSK1'*Ray' does not match the second attempt to add noise
10^(-Eb_N0_dB(ii)/20)*awgn;
what do you mean by
% Channel and noise Noise addition
I keep hearing and reading about MATLAB communications applications being developed mainly in SIMULINK.
Can you build the SIMULINK equivalent of the script in the question, i dare say it will simplify it all, quite
Regards
John

Più risposte (0)

Categorie

Scopri di più su Propagation and Channel Models in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by