Error using .* .Matrix dimensions must agree
이전 댓글 표시
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Propagation and Channel Models에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!