## plz help me to find the solution of error in kron( )

on 28 Jun 2013

### Walter Roberson (view profile)

I am getting the error as:

*??? Error using ==> vertcat Out of memory. Type HELP MEMORY for your options.*

this is a code in 2*2 mimo in qpsk .

N = 1000000; % number of bits or symbols
Eb_N0_dB = [0:25]; % multiple Eb/N0 values
nTx = 2;
nRx = 2;
for ii = 1:length(Eb_N0_dB)
% Transmitter
ip = (rand(1,N)>0.5) + j*(rand(1,N)>0.5); % generating 0,1 with equal probability
s = 2*ip-(1+j);
sMod = kron(s,ones(nRx,1)); %
sMod = reshape(sMod,[nRx,nTx,N/nTx]); % grouping in [nRx,nTx,N/NTx ] matrix
h = 1/sqrt(2)*[randn(nRx,nTx,N/nTx) + j*randn(nRx,nTx,N/nTx)]; % Rayleigh channel
n = 1/sqrt(2)*[randn(nRx,N/nTx) + j*randn(nRx,N/nTx)]; % white gaussian noise, 0dB variance
% Channel and noise Noise addition
y = squeeze(sum(h.*sMod,2)) + 10^(-Eb_N0_dB(ii)/20)*n;
% ----------------------------
% if [s1 s2 ] = [-1-1, -1-1]
sHat1 = [-1-j -1-j];
sHat1 = repmat(sHat1,[1 N/2]);
sHat1Mod = kron(sHat1,ones(nRx,1));
sHat1Mod = reshape(sHat1Mod,[nRx,nTx,N/nTx]);
zHat1 = squeeze(sum(h.*sHat1Mod,2)) ;
J1 = sum(abs(y - zHat1),1);
% if [s1 s2 ] = [-1 -1 -1 1]
sHat2 = [-1-j -1+j];
sHat2 = repmat(sHat2,[1 N/2]);
sHat2Mod = kron(sHat2,ones(nRx,1));
sHat2Mod = reshape(sHat2Mod,[nRx,nTx,N/nTx]);
zHat2 = squeeze(sum(h.*sHat2Mod,2)) ;
J2 = sum(abs(y - zHat2),1);
% if [s1 s2 ] = [-1 -1 1 -1]
sHat3 = [-1-j 1-j];
sHat3 = repmat(sHat3,[1 N/2]);
sHat3Mod = kron(sHat3,ones(nRx,1));
sHat3Mod = reshape(sHat3Mod,[nRx,nTx,N/nTx]);
zHat3 = squeeze(sum(h.*sHat3Mod,2)) ;
J3 = sum(abs(y - zHat3),1);
% if [s1 s2] = [-1 -1 1 1]
sHat4 = [-1-j 1+j];
sHat4 = repmat(sHat4,[1 N/2]);
sHat4Mod = kron(sHat4,ones(nRx,1));
sHat4Mod = reshape(sHat4Mod,[nRx,nTx,N/nTx]);
zHat4 = squeeze(sum(h.*sHat4Mod,2)) ;
J4 = sum(abs(y - zHat4),1);
% if [s1 s2 ] = [-1 1 -1 -1]
sHat5 = [-1+j -1-j];
sHat5 = repmat(sHat5,[1 N/2]);
sHat5Mod = kron(sHat5,ones(nRx,1));
sHat5Mod = reshape(sHat5Mod,[nRx,nTx,N/nTx]);
zHat5 = squeeze(sum(h.*sHat5Mod,2)) ;
J5 = sum(abs(y - zHat5),1);
% if [s1 s2] = [-1 1 -1 1]
sHat6 = [-1+j -1+j];
sHat6 = repmat(sHat6,[1 N/2]);
sHat6Mod = kron(sHat6,ones(nRx,1));
sHat6Mod = reshape(sHat6Mod,[nRx,nTx,N/nTx]);
zHat6 = squeeze(sum(h.*sHat6Mod,2)) ;
J6 = sum(abs(y - zHat6),1);
% if [s1 s2 ] = [-1 1 1 -1]
sHat7 = [-1+j 1-j];
sHat7 = repmat(sHat7,[1 N/2]);
sHat7Mod = kron(sHat7,ones(nRx,1));
sHat7Mod = reshape(sHat7Mod,[nRx,nTx,N/nTx]);
zHat7 = squeeze(sum(h.*sHat7Mod,2)) ;
J7 = sum(abs(y - zHat7),1);
% if [s1 s2] = [-1 1 1 1]
sHat8 = [-1+j 1+j];
sHat8 = repmat(sHat8,[1 N/2]);
sHat8Mod = kron(sHat8,ones(nRx,1));
sHat8Mod = reshape(sHat8Mod,[nRx,nTx,N/nTx]);
zHat8 = squeeze(sum(h.*sHat8Mod,2)) ;
J8 = sum(abs(y - zHat8),1);
% if [s1 s2 ] = [1 -1 -1 -1]
sHat9 = [1-j -1-j];
sHat9 = repmat(sHat9,[1 N/2]);
sHat9Mod = kron(sHat9,ones(nRx,1));
sHat9Mod = reshape(sHat9Mod,[nRx,nTx,N/nTx]);
zHat9 = squeeze(sum(h.*sHat9Mod,2)) ;
J9 = sum(abs(y - zHat9),1);
% if [s1 s2 ] = [1 -1 -1 1]
sHat10 = [1-j -1+j];
sHat10 = repmat(sHat10,[1 N/2]);
sHat10Mod = kron(sHat10,ones(nRx,1));
sHat10Mod = reshape(sHat10Mod,[nRx,nTx,N/nTx]);
zHat10 = squeeze(sum(h.*sHat10Mod,2)) ;
J10 = sum(abs(y - zHat10),1);
% if [s1 s2] = [1 -1 1 -1]
sHat11 = [1-j 1-j];
sHat11 = repmat(sHat11,[1 N/2]);
sHat11Mod = kron(sHat11,ones(nRx,1));
sHat11Mod = reshape(sHat11Mod,[nRx,nTx,N/nTx]);
zHat11 = squeeze(sum(h.*sHat11Mod,2)) ;
J11 = sum(abs(y - zHat11),1);
% if [s1 s2 ] = [1 -1 1 1]
sHat12 = [1-j 1+j];
sHat12 = repmat(sHat12,[1 N/2]);
sHat12Mod = kron(sHat12,ones(nRx,1));
sHat12Mod = reshape(sHat12Mod,[nRx,nTx,N/nTx]);
zHat12 = squeeze(sum(h.*sHat12Mod,2)) ;
J12 = sum(abs(y - zHat12),1);
% if [s1 s2 ] = [1 1 -1 -1]
sHat13 = [1+j -1-j];
sHat13 = repmat(sHat13,[1 N/2]);
sHat13Mod = kron(sHat13,ones(nRx,1));
sHat13Mod = reshape(sHat13Mod,[nRx,nTx,N/nTx]);
zHat13 = squeeze(sum(h.*sHat13Mod,2)) ;
J13 = sum(abs(y - zHat13),1);
% if [s1 s2 ] = [1 1 -1 1]
sHat14 = [1+j -1+j];
sHat14 = repmat(sHat14,[1 N/2]);
sHat14Mod = kron(sHat14,ones(nRx,1));
sHat14Mod = reshape(sHat14Mod,[nRx,nTx,N/nTx]);
zHat14 = squeeze(sum(h.*sHat14Mod,2)) ;
J14 = sum(abs(y - zHat14),1);
% if [s1 s2 ] = [1 1 1 -1]
sHat15 = [1+j 1-j];
sHat15 = repmat(sHat15,[1 N/2]);
sHat15Mod = kron(sHat15,ones(nRx,1));
sHat15Mod = reshape(sHat15Mod,[nRx,nTx,N/nTx]);
zHat15 = squeeze(sum(h.*sHat15Mod,2)) ;
J15 = sum(abs(y - zHat15),1);
% if [s1 s2 ] = [1 1 1 1]
sHat16 = [1+j 1+j];
sHat16 = repmat(sHat16,[1 N/2]);
sHat16Mod = kron(sHat16,ones(nRx,1));
sHat16Mod = reshape(sHat16Mod,[nRx,nTx,N/nTx]);
zHat16 = squeeze(sum(h.*sHat16Mod,2)) ;
J16 = sum(abs(y - zHat16),1);
% finding the minimum from the four alphabet combinations
rVec = [J1;J2;J3;J4;J5;J6;J7;J8;J9;J10;J11;J12;J13;J14;J15;J16];
[jj dd] = min(rVec,[],1);
% mapping the minima to bits
ref = [['00' '00']; ['00' '01']; ['00' '10']; ['00' '11'];
['01' '00']; ['01' '01']; ['01' '10']; ['01' '11'];
['10' '00']; ['10' '01']; ['10' '10']; ['10' '11'];
['11' '00']; ['11' '01']; ['11' '10']; ['11' '11']];
ipHat = zeros(1,N);
ipHat(1:2:end) = ref(dd,1);
ipHat(2:2:end) = ref(dd,2);
% counting the errors
nErr(ii) = size(find([ip - ipHat]),2);
end
simBer = nErr/N; % simulated ber
% 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,simBer,'mo-','LineWidth',2) ;
hold on ;
axis([0 25 10^-5 1]);
title( 'BER for QPSK modulation with 2x2 MIMO and ML equalizer (Rayleigh channel)' );
grid on;
legend('sim (nTx=2, nRx=2, ML)');
xlabel('Average Eb/No,dB');
ylabel('Bit Error Rate');

Matt J

### Matt J (view profile)

on 28 Jun 2013
Undefined function or variable 'ip'.
Error in test (line 168)
nErr(ii) = size(find([ip - ipHat]),2);
168     nErr(ii) = size(find([ip - ipHat]),2);
Jan Simon

### Jan Simon (view profile)

on 28 Jun 2013

@abhilash: Please post a copy of the complete error message. Posting such a large block of code and hoping that a foreign reader will solve the problem, is not an efficient approach. At first using the debugger to narrow down the problem is the best strategy.

## Products

No products are associated with this question.

### Walter Roberson (view profile)

on 28 Jun 2013

Perhaps you can switch to using integer data types. (Yes, it is allowed to create complex numbers based on an integer type.)

As usual, the easiest fix is to use a 64 bit operating system, 64 bit version of MATLAB, and a system with a decent amount of physical memory.

Walter Roberson

### Walter Roberson (view profile)

on 4 Jul 2013

You flagged this with a note that the error message was still coming up. Which error message? The one about "ip" being undefined, or the one about running out of memory? What have you changed since I posted my Answer ? Have you added more RAM to your system?

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi