when i tried this program getting the error as Subscripted assignment dimension mismatch Error in ==> mrczf at 79 EbN0EffSim(ii,jj) = (mean(abs(yHat))+simBer) ;.
조회 수: 2 (최근 30일)
이전 댓글 표시
clear N = 10^6; % number of bits or symbols Eb_N0_dB = [0:25]; % multiple Eb/N0 values nTx = 2; %number of transmitters nRx = 2; %number of receivers for ii = 1:length(Eb_N0_dB)
% Transmitter
ip = rand(1,N)>0.5; % generating 0,1 with equal probability
s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 0
sMod1 = kron(s,ones(nRx,1)); %
sMod1 = reshape(sMod1,[nRx,nTx,N/nTx]); % grouping in [nRx,nTx,N/NTx ] matrix
%conj vi du 1 ham 1+j se tra lai 1-j va nguoc lai
%reshape: sap xep lai cac phan tu cua 1 ma tran 3x4 thang 1 ma tran 2x6
%voi thu tu uu tien giu nguyen cot.
h1 = 1/sqrt(2)*[randn(nRx,nTx,N/nTx) + j*randn(nRx,nTx,N/nTx)]; % Rayleigh channel
n1 = 1/sqrt(2)*[randn(nRx,N/nTx) + j*randn(nRx,N/nTx)]; % white gaussian noise, 0dB variance
% Channel and noise Noise addition
y1 = squeeze(sum(h1.*sMod1,2)) + 10^(-Eb_N0_dB(ii)/20)*n1;
%B = squeeze(A) returns an array B with the same elements as A, but
%with all singleton dimensions removed.
% Receiver
% Forming the Zero Forcing equalization matrix W = inv(H^H*H)*H^H
% H^H*H is of dimension [nTx x nTx]. In this case [2 x 2]
% Inverse of a [2x2] matrix [a b; c d] = 1/(ad-bc)[d -b;-c a]
h1Cof = zeros(2,2,N/nTx) ;
h1Cof(1,1,:) = sum(h1(:,2,:).*conj(h1(:,2,:)),1); % d term
h1Cof(2,2,:) = sum(h1(:,1,:).*conj(h1(:,1,:)),1); % a term
h1Cof(2,1,:) = -sum(h1(:,2,:).*conj(h1(:,1,:)),1); % c term
h1Cof(1,2,:) = -sum(h1(:,1,:).*conj(h1(:,2,:)),1); % b term
h1Den = ((h1Cof(1,1,:).*h1Cof(2,2,:)) - (h1Cof(1,2,:).*h1Cof(2,1,:))); % ad-bc term
h1Den = reshape(kron(reshape(h1Den,1,N/nTx),ones(2,2)),2,2,N/nTx); % formatting for division
h1Inv = h1Cof./h1Den; % inv(H^H*H)
h1Mod = reshape(conj(h1),nRx,N); % H^H operation
y1Mod1 = kron(y1,ones(1,2)); % formatting the received symbol for equalization
y1Mod1 = sum(h1Mod.*y1Mod1,1); % H^H * y
y1Mod1 = kron(reshape(y1Mod1,2,N/nTx),ones(1,2)); % formatting
y1Hat1 = sum(reshape(h1Inv,2,N).*y1Mod1,1); % inv(H^H*H)*H^H*y
% receiver - hard decision decoding
ipHat1 = real(y1Hat1)>0;
% counting the errors
nErr(ii) = size(find([ip- ipHat1]),2);
end
simBer = nErr/N; % simulated ber
for jj = 1:length(nRx)
for ii = 1:length(Eb_N0_dB)
n = 1/sqrt(2)*[randn(nRx(jj),N) + j*randn(nRx(jj),N)]; % white gaussian noise, 0dB variance
h = 1/sqrt(2)*[randn(nRx(jj),N) + j*randn(nRx(jj),N)]; % Rayleigh channel
% Channel and noise Noise addition
sD = kron(ones(nRx(jj),1),s);%sD = 1;
y = h.*sD + 10^(-Eb_N0_dB(ii)/20)*n;
% maximal ratio combining
yHat = sum(conj(h).*y,1);
% effective SNR
EbN0EffSim(ii,jj) = (mean(abs(yHat))+simBer) ;
end
end
%EbN0Lin = 10.^(Eb_N0_dB/10); theoryBer_nRx1 = 0.5.*(1-1*(1+1./EbN0Lin).^(-0.5)); p = 1/2 - 1/2*(1+1./EbN0Lin).^(-1/2); theoryBerMRC_nRx2 = p.^2.*(1+2*(1-p));
close all figure semilogy(Eb_N0_dB,theoryBer_nRx1,'bp-','LineWidth',2); hold on semilogy(Eb_N0_dB,theoryBerMRC_nRx2,'kd-','LineWidth',2); semilogy(nRx, EbN0EffSim,'mo-','LineWidth',2); axis([0 25 10^-5 0.5]) grid on legend('theory (nTx=1,nRx=1)', 'theory (nTx=1,nRx=2, MRC)', 'sim (nTx=2, nRx=2, ZF)'); xlabel('Average Eb/No,dB'); ylabel('Bit Error Rate'); title('BER for BPSK modulation with 2x2 MIMO and ZF equalizer (Rayleigh channel)');
댓글 수: 0
답변 (1개)
Walter Roberson
2017년 1월 28일
simerr is a vector. I did not examine whether yhat is a vector. You add something to simerr so the results have to be a vector. You try to store that complete vector in the single numeric array position you designated on the left hand side of the assignment
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 BPSK에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!