キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

Fatal Run-Time error with Decimate function

解決済み
解決策を見る

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 件の賞賛
メッセージ1/6
3,831件の閲覧回数

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 スマイリー ウインク

0 件の賞賛
メッセージ2/6
3,829件の閲覧回数

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

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

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
0 件の賞賛
メッセージ3/6
3,826件の閲覧回数

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 件の賞賛
メッセージ4/6
3,823件の閲覧回数

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 件の賞賛
メッセージ5/6
3,821件の閲覧回数
解決策
トピック作成者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?
メッセージ6/6
3,815件の閲覧回数