07-02-2012 03:56 AM
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?
Solved! Go to Solution.
07-02-2012 04:06 AM
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
07-02-2012 04:11 AM
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]
But this isn't the problem: it is Decimate that expects an array of size dFact * Nout
07-02-2012 04:16 AM
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
07-02-2012 04:21 AM
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];
07-02-2012 04:34 AM - edited 07-02-2012 04:34 AM
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.