レイリーフェージングとAWGNでCRCの効果をシミュレートしたい。次のように私のコードは次のとおりです。「ノイズの次元が合致しなければならない」チャンネルノイズ追加
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');
私はエラー得ている行に「使用してエラーを* .Matrix寸法が同意しなければなりません。」:
y = Ray.*BPSK1 + 10^(-Eb_N0_dB(ii)/20)*awgn;
誰も私がこれを解決するのに役立ちます願っています。
1x4ベクトルと4x7行列の間で要素の賢明な乗算を実行しようとしています。 – ritualmagick