Please help this semilogy error message

조회 수: 1 (최근 30일)
Seahawks
Seahawks 2020년 11월 20일
댓글: VBBV 2020년 11월 20일
Please help to fix this problem. I try to plot as semilogy the MRC in Rayleigh fading and BPSK scheme. This needs to display in the same figure the simBer1 in M_Rx=1, 2, 3 with M_Rx=1 in 0:2:12; M_Rx2=0:2:14; M_Rx=3 in 0:2:16
ip = rand(1,N)>0.5; % generating 0,1 with equal probability
s = 2*ip-1; % 0 -> -1; 1 -> 0 >> BPSK modulation
nRx_max = 3; %number of M branches
M_Rx = [1:nRx_max];
EbN0dB1 = [0:2:12]; EbN0dB2 = [0:2:14]; EbN0dB3 = [0:2:16];
%%%%% EGC %%%%%%%%%%%
for jj = 1:length(M_Rx)
%%%Common values
for k = 1:length(EbN0dB1)
n = 1/sqrt(2)*[randn(M_Rx(jj),N) + j*randn(M_Rx(jj),N)]; % White gaussian noise, 0dB variance
h = 1/sqrt(2)*[randn(M_Rx(jj),N) + j*randn(M_Rx(jj),N)]; % Rayleigh fading channel
% Channel and noise Noise addition
sD = kron(ones(M_Rx(jj),1),s);
%%% In different values of dBN0dB
y1 = h.*sD + 10^(-EbN0dB1(k)/20)*n; %%%%% EbN0dB1 = [0:2:14] %%%%%%%%%%%
% equalization with EGC
y1Hat = y1.*exp(-j*angle(h)); % removing the phase of the channel
y1Hat = sum(y1Hat,1); % adding values from all the receive chains
% receiver Rx
ip1Hat = real(y1Hat)>0;
% numbers the errors
nErr1(jj,k) = size(find([ip- ip1Hat]),2);
end
end
%theoryBer_nRx1 = 0.5.*(1-1*(1+1./EbN0Lin1).^(-0.5));
%theoryBer_nRx2 = 0.5*(1 - sqrt(EbN0Lin1.*(EbN0Lin1+2))./(EbN0Lin1+1) );
simBer1 = nErr1/N; % simulated ber
EbN0Lin1 = 10.^(EbN0dB1/10); %EbN0 linear
close all
figure(1)
semilogy(EbN0dB1,simBer1(1,:),'mo-','LineWidth',1);hold on;
semilogy(EbN0dB2,simBer1(2,:),'kp-','LineWidth',1);
semilogy(EbN0dB3,simBer1(3,:),'gs-','LineWidth',1);
grid on
legend('M=1', 'M=2', 'M=3');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation with Equal Gain Combining in Rayleigh channel');
axis([0 20 10^-6 2])
Error using semilogy
Vectors must be the same length.
Error in MRC_bpsk.m (line 41)
semilogy(EbN0dB2,simBer1(2,:),'kp-','LineWidth',1);
>>

채택된 답변

VBBV
VBBV 2020년 11월 20일
편집: VBBV 2020년 11월 20일
N = 100
ip = rand(1,N)>0.5; % generating 0,1 with equal probability
s = 2*ip-1; % 0 -> -1; 1 -> 0 >> BPSK modulation
nRx_max = 3; %number of M branches
M_Rx = [1:nRx_max];
%EbN0dB1 = [0:2:12]; EbN0dB2 = [0:2:14]; EbN0dB3 = [0:2:16];
EbN0dB = 0:2:16;
%%%%% EGC %%%%%%%%%%%
for jj = 1:length(M_Rx)
%%%Common values
for k = 1:length(EbN0dB)
n = 1/sqrt(2)*[randn(M_Rx(jj),N) + j*randn(M_Rx(jj),N)]; % White gaussian noise, 0dB variance
h = 1/sqrt(2)*[randn(M_Rx(jj),N) + j*randn(M_Rx(jj),N)]; % Rayleigh fading channel
% Channel and noise Noise addition
sD = kron(ones(M_Rx(jj),1),s);
%%% In different values of dBN0dB
y1 = h.*sD + 10^(-EbN0dB(k)/20)*n; %%%%% EbN0dB1 = [0:2:14] %%%%%%%%%%% % equalization with EGC
y1Hat = y1.*exp(-j*angle(h)); % removing the phase of the channel
y1Hat = sum(y1Hat,1); % adding values from all the receive chains
% receiver Rx
ip1Hat = real(y1Hat)>0;
% numbers the errors
nErr1(jj,k) = size(find([ip- ip1Hat]),2);
end
end
%theoryBer_nRx1 = 0.5.*(1-1*(1+1./EbN0Lin1).^(-0.5));
%theoryBer_nRx2 = 0.5*(1 - sqrt(EbN0Lin1.*(EbN0Lin1+2))./(EbN0Lin1+1) );
simBer1 = nErr1/N; % simulated ber
EbN0Lin1 = 10.^(EbN0dB/10); %EbN0 linear
close all
figure(1)
semilogy(EbN0dB(1:end-2),simBer1(1,1:end-2),'mo-','LineWidth',1);hold on;
semilogy(EbN0dB(1:end-1),simBer1(2,1:end-1),'kp-','LineWidth',1);hold on;
semilogy(EbN0dB,simBer1(3,:),'gs-','LineWidth',1);
grid on
legend('M=1', 'M=2', 'M=3');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation with Equal Gain Combining in Rayleigh channel');
axis([0 20 10^-6 2])
Since you are creating vectors EbN0dB1 ...3, incrementally, with steps of 2, you can create one vector and access those parts individually,
Try the above
  댓글 수: 4
Seahawks
Seahawks 2020년 11월 20일
Vasishta,
Could you please explain if I want EbN0dB1 = [0:2:14]; EbN0dB2 = [0:2:20]; EbN0dB3 = [0:2:24];?
Thanks Seahawkgo
VBBV
VBBV 2020년 11월 20일
EbN0dB = 0:2:24; % Again create a common vector with max value (24 in EbN0dB3)
>> EbN0dB =
0 2 4 6 8 10 12 14 16 18 20 22 24
EbN0dB(1:end-2); % since 20 is 2nd before last element
>> ans =
0 2 4 6 8 10 12 14 16 18 20
>> EbN0dB(1:end-5) % since 14 is 5th before last element
ans =
0 2 4 6 8 10 12 14

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 BPSK에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by