Search code examples
matlabencodingoctavequantizationmodulation

What does the error "error: ones: invalid data type specified" mean?


This is my code it generates a signal, quantizes it, encodes it, then demodulates it.

 %Quantization
 n=8; 
 L=2^n; 
 vmax=8;
 vmin=-vmax;
 del=(vmax-vmin)/L;
 part=vmin:del:vmax;                   % level are between vmin and vmax with difference of del
 code=vmin-(del/2):del:vmax+(del/2);   % Contaion Quantized valuses 
 [ind,q]=quantiz(s,part,code);         % Quantization process
 

%  Encoding Process
figure;
code=de2bi(ind,'left-msb');   % Cnvert the decimal to binary
k=1;
l1=length(ind);
l2=length(q);
for i=1:l1
    for j=1:n
        coded(k)=code(i,j);   % convert code matrix to a coded row vector
        j=j+1;
        k=k+1;
    end
    i=i+1;
end

When I run it (already did pkg load communications for the quantiz function) I get this line of errors.

error: ones: invalid data type specified
error: called from
    de2bi at line 79 column 5
    PCM1 at line 33 column 6

(PCM1 is the file name) I tried removing 'left-msb' parameter from the de2bi function and that makes the code run with no errors but the final output is not correct so I need the 'left-msb'. To my knowledge this code works fine on MATLAB but I don't have a MATLAB key to try it.

Any ideas as to what this error means and how I could fix it? the array ind is of type double with all positive values so I don't understand why the function would not work.

Edit: The code was ran in Octave. Removed unneccesary code.


Solution

  • there appears to be an incompatibility between Matlab and Octave in the implementation of de2bi. Octave does not appear to properly handle a two-input call to de2bi with the second input being the significant bit flag. It requires you to provide both the input number and the number of columns as first two inputs, then the flag can be successfully handled as 3rd input (or 4th if you specify a different base). Octave appears to not handle an empty placeholder for the base values either, but it can for the number of columns to display.

    e.g., for :

    >> de2bi(19)
    ans =
         1     1     0     0     1
    

    in Matlab 2020a, the following all produce the same output:

    >> de2bi(19,'left-msb')
    ans =
         1     0     0     1     1
    
    >> de2bi(19,[],'left-msb')
    ans =
         1     0     0     1     1
    
    >> de2bi(19,[],[],'left-msb')
    ans =
         1     0     0     1     1
    

    However in Octave 5.2.0 with communications pkg 1.2.2:

    >> de2bi(19)
    ans =
       1   1   0   0   1
    
    >> de2bi(19, 'left-msb')
    error: ones: invalid data type specified
    error: called from
        de2bi at line 79 column 5
    
    >> de2bi(19,[],'left-msb')
    ans =
       1   0   0   1   1
    
    >> de2bi(19,[],[],'left-msb')
    ans = [](0x0)
    
    >> de2bi(19,[],2,'left-msb')
    ans =
       1   0   0   1   1
    
    >> de2bi(19,5,2,'left-msb')
    ans =
       1   0   0   1   1
    

    Until this compatibility bug is reported and repaired, it appears the best fix for now is to use the 2nd to last syntax above, using an empty place holder for the number of columns to display and a 2 for the base. This syntax will produce the same output in both Matlab and Octave.

    Bug report 59466 has been created on the Octave bug tracker.

    UPDATE: a patch has been submitted to the bug report mentioned above that corrects the incompatible input handling between Octave and Matlab versions of di2be. A compatible version of di2be.m is also included there if the workaround above is insufficient until an updated version of the package is released with the patch.