0

I'm working with an Octave script to process data files with high sample rates (up to 200kS/s collected over 3 minutes). The code runs into issues when processing any files with a sample rate above 50kS/s, regardless of size or number of samples but functions correctly otherwise.

The error I receive when attempting to run the code with files above 50kS/s is called from the hist function:

error: x(0): subscripts must be either integers 1 to (2^63)-1 or logicals
error:

I have narrowed the cause to the following section of code (note that FS is the detected sampling frequency):

FILTER_ORDER  = 1;
FILTER_CUTOFF = 1 / (2 * pi * 300e-3);       
[b_lp, a_lp] = butter(FILTER_ORDER, FILTER_CUTOFF / (FS / 2), 'low');
%

s = SCALING_FACTOR * filter(b_lp, a_lp, u_q) ;   
P = s ;                                    
%

tau  = 20;                            
transient    = tau * FS;            % index after the transient 
Pmax = max(P(transient:end));  
%

s = s(transient:end);                            
%

NUMOF_CLASSES = 10000;                              % number of bins used for the histogram
[bin_cnt, cpf.magnitude] = hist(s, NUMOF_CLASSES);  % sorts data into the number of bins specified 

I can try to provide more information if required, I'm not very familiar with Octave.

  • 1
    it's hard to see where x(0) is happening; I don't even see an x here so presumably it's coming from a called function. However, if you'd like to try to debug the error yourself using octave's debugger, one thing you can do is run `debug_on_error(1)` in your octave console before running your code, which will cause octave to drop into a debugging terminal as soon as the error occurs, and allow you to inspect the relevant code and workspaces yourself. – Tasos Papastylianou Jun 30 '22 at 11:24
  • Thanks Tasos, the error is being called from line 222 of the hist.m function. Is there a way to view variable values during or after code execution through sub routines? – PG_Tech Jun 30 '22 at 14:01
  • I have further identified that the lines to find Pmax and s that involve using values after an index until the end s(transient:end); are responsible for the error. They return NaN when handling files larger than 50kS/s. Is this a known issue? Are there known solutions? – PG_Tech Jun 30 '22 at 14:56
  • I don't understand. Isn't the code you wrote above your code? I would say have a look where in your code you're getting a NaN where you shouldn't. It's unlikely this is a bug in the functions called from your code. – Tasos Papastylianou Jun 30 '22 at 16:57
  • The code in the original post is in fact the segment from where the error is being generated. The reason the hist function is returning the error is because the value of s being passed to the function is NaN when FS is >50 000. When FS <=50 000, s returns a real number. I don't understand or know enough about Octave to know why s = s(transient:end) returns NaN if the file sample rate is above 50kS/s – PG_Tech Jun 30 '22 at 18:26
  • It is very unlikely that this is an 'octave bug', and more likely that it has something to do with the values you pass to filter leading to the formation of nans. (e.g. what is u_q?). It would be worth trying to convert the above problem into a minimal testcase. This makes it more likely to be able to help rather than guess what the offending code might have been, and often enough it helps you diagnose the problematic behaviour yourself! See https://stackoverflow.com/help/minimal-reproducible-example – Tasos Papastylianou Jul 01 '22 at 11:41

0 Answers0