0
我想模擬CRC在瑞利衰落和AWGN中的影響。我的代碼如下:「用錯誤* .Matrix尺寸必須同意」關於通道噪聲添加的「錯誤維度必須一致」
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');
我已經得到了錯誤的路線:
y = Ray.*BPSK1 + 10^(-Eb_N0_dB(ii)/20)*awgn;
希望有人能幫助我解決這個。
您試圖在1x4向量和4x7矩陣之間執行元素明智的乘法。 – ritualmagick