LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Fatal Run-Time error with Decimate function

Solved!
Go to solution

I have a buffer where the samples are interleaved (ch0, ch1, ch0, ch1, ....) and I need to separate the channel, so I tried to use Decimate as suggested here.

 

The code is really simple:

 

double    interleavedSamples[100], ch0[50], ch1[50];
    
    Decimate (interLeavedSamples, 100, 2, 0, ch0);
    Decimate (interleavedSamples + 1, 100, 2, 0, ch1);

 

but the second call to Decimate gives Fatal Run-Time Engine - Array argument too small.

This is not true, because with a decimation factor of dFactor, you can get Nout samples if the input buffer has at least dFactor*(Nout-1)+1 and not dFactor*Nout

 

I tried a workaround, specifying 99 as numberOfElements parameters in the second call to Decimate, but this doesn't work, because as written in the help file

size = trunc(numberOfElements/dFactor) is the size of the output sequence

and so only 49 elements are returned in ch1 buffer.

 

How can Decimate be used to separate interleaved samples?

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
0 Kudos
Message 1 of 6
(3,649 Views)

Vix,

 

in the second function call you should give the address of the second element of your array, i.e. &interleavedSamples [ 1 ]; this is different from your code because the elements need more than 1 byte Smiley Wink

0 Kudos
Message 2 of 6
(3,647 Views)

Hi Wolfgang,

my code and your suggestion are exactly the same, because interleavedSamples is in reality the address of the first element of the buffer and a pointer to a double.

For this reason interleavedSamples +1 is the same as &interleavedSamples[1] Smiley Wink

But this isn't the problem: it is Decimate that expects an array of size dFact * Nout

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
0 Kudos
Message 3 of 6
(3,644 Views)

Ok,

 

attempt number 2: Did you consider increasing your initial array by one element, i.e. using a size of 101? Only the first 100 elements are filled with data, but this should avoid accessing an element outside of the array if you start with an odd element

0 Kudos
Message 4 of 6
(3,641 Views)

the fact is that the buffer comes from a DAQmx acquisition.

 

I tried this workaorund:

 

Decimate (interleavedSamples+1, 99, 2, 0, ch1);
ch1[49] = interleavedSamples[99];

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
0 Kudos
Message 5 of 6
(3,639 Views)
Solution
Accepted by topic author vix

You should have noted that the size error is on interleavedSamples argument of Decimate. In effect the function expects to have 100 elements to treat starting from interleadedSamples[1] element, so you must size your starting array as interleavedSamples[101]. next you'll acquire 100 measures and the second Decimate will correctly extract samples [1] to [99], leaving (empty) sample [100] untouched.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 6 of 6
(3,633 Views)