Page 1 of 1

Simple or modifiable delay box ?

Posted: Wed Dec 23, 2015 12:18 am
by Jeff_B
Hi there
Is there a way to delay signals (by a number of samples or ms) or is there a way to implement it (via a FIR filter ?) in the designer ? I am looking for a way to implement easily a CSSP or CSSSP method.
Jeff

Re: Simple or modifiable delay box ?

Posted: Sun Dec 27, 2015 2:35 pm
by Jeff_B
Hi Openvibers,
I am not an experimented user of OV (just managed to compile it with an exotic driver) but I guess I will have to make a basic signal processing box to augment the regular (current or non delayed) signal flow with delayed versions of it. It would have two parameters (order and base_delay) and would augment the signal flow buffer this way:

channel 0 samples - channel 1 samples - .... - channel N samples - channel 0 samples delayed by base_delay - ..... - channel N samples delayed by base_delay - channel 0 samples delayed by 2*base_delay - ..... - channel N samples delayed by 2*base_delay - .............. - channel 0 samples delayed by order*base_delay - ..... - channel N samples delayed by order*base_delay

My original intend is to build a classifier for cursor control using a bank of spatio frequential filters built via CSP followed by a SVM. To include this frequential dimension in the CSP (FIR filtering), I was thinking to create new (virtual) channels with time delayed versions of the existing ones, and to deal with them in the same way we process the spatial samples using the regularized version of the CSP. A CSP filtered signal would thus be a linear combination of both spatial samples (spatial filtering) and their time delayed versions (temporal/frequential filtering). This brings a question about this regularized CSP: is there a way to apply a different amount of regularization /whitenning for the varied channels (enabling me to apply a different amount of regularization accross spatial (0-lagged) or temporal/frequential (lagged) dimensions ?). Or should I have to modify it ? o.O
Have a pleasing solstice and a gratifying ew year of research,
Jean-François B.

Re: Simple or modifiable delay box ?

Posted: Mon Dec 28, 2015 4:46 pm
by Jeff_B
Hi there,
I have implemented this DelayLines as a basic signal processing box (see attached files).

It compiles but keep crashing if played under the designer with a sinus generator as input, ending in a C0000005 error code.

The problem seems linked to fifo_buffer, since when I comment out the lines where I use the fifo_buffer in the implementation of CBoxAlgorithmDelayLines::process():

Code: Select all

for(uint32 i = 0 ; i < m_ui64channel_count ; i++)
{
	for(uint32 j = 0 ; j < m_ui64max_sample ; j++)
	{
		fifo_buffer[j + m_ui64sample_count + i*m_ui64sample_fifo] = fifo_buffer[j + i*m_ui64sample_fifo];
		if(j < m_ui64sample_count)
			fifo_buffer[j + i*m_ui64sample_fifo] = l_pBuffer[m_ui64sample_count - 1 - j + i*m_ui64sample_count];
	}
}
... the box can be played without any crash/unhandled exception (even if it does not produce any meaninful values).

I can write into fifo_buffer using for exemple: fifo_buffer[m_ui64sample_fifo]=1.0; but I cannot use for exemple:

Code: Select all

for(int i=0; i<m_ui64sample_fifo; i++)
{
      fifo_buffer[i]=1.0;
}
fifo_buffer is a private attribute of the CBoxAlgorithmDelayLines class, and declared as:
OpenViBE::float64 *fifo_buffer;
I have tried to dynamically allocate it in the CBoxAlgorithmDelayLines::initialize() via:

Code: Select all

fifo_buffer = new OpenViBE::float64[m_ui64channel_count*m_ui64sample_fifo];
or
	  std::vector<OpenViBE::float64> fifo_buffer(m_ui64channel_count*m_ui64sample_fifo, 0);
or
	  fifo_buffer = (OpenViBE::float64 *) calloc(m_ui64channel_count*m_ui64sample_fifo, sizeof(OpenViBE::float64));
followed (not in the case of std::vector) by

Code: Select all

memset(fifo_buffer, 0, sizeof(OpenViBE::float64)*m_ui64channel_count*m_ui64sample_fifo);
... without much success (always this C0000005 error code).

Any idea guys ? I am really stuck with this !
Best,
Jeff

Re: Simple or modifiable delay box ?

Posted: Tue Dec 29, 2015 5:58 am
by Jeff_B
The box works properly with a fixed (large) size array for fifo_buffer. Any clue about the reason why the dynamic allocation fails ?
Jeff

Re: Simple or modifiable delay box ?

Posted: Mon Jan 04, 2016 12:05 pm
by jtlindgren
Hello Jeff,

welcome on board and thanks for the detailed report! The reason for the crash is clear from the source code. The thing is that the size of the matrix is information that is passed from box to another *during* the processing, in a specific 'header' segment, usually sent as the very first chunk of the stream. You need to allocate your buffer inside this block in process(),

Code: Select all

if(m_oInput0Decoder.isHeaderReceived())
{
   // ...
}
if you do it in initialize(), the decoder does not yet know what the actual sizes are.

About the other things, I think you're right, there's no explicit delay box in OV at the moment. About the CSP, you can't do per-channel regularization without modifying the box, but you might try learning two differently regularized CSP filters altogether by splitting the signal with Channel Selector -- although this might hamper your original purpose. :)

Good luck,
Jussi

Re: Simple or modifiable delay box ?

Posted: Tue Jan 19, 2016 5:28 pm
by Jeff_B
Hum... after the 1st header is received is far better... of course, thank you Jussi :mrgreen: :arrow: