Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

FIRInitAlloc and FIRInit

peterp
Beginner
790 Views
Hi:
I'm having a problem with IPP. I don't know what's causing it, but I want to
try something that might fix it.
Currently, I use code that looks like this:

Code:

	_numQuads = numTaps;

	if (_numQuads)
	{
		_tapVals = ippsMalloc_32f(_numQuads);
		_delayVals = ippsMalloc_16s(_numQuads);

		RealVector firCoefs = ds.ImpulseResponse(numTaps);

		for (long i=0; i<_numQuads; ++i)
		{	// fill in the taps
			_tapVals = (float)firCoefs;
			_delayVals = 0;
		}

		ippsFIRInitAlloc32f_16s
		(
			&_statePtr,
			_tapVals,
			_numQuads,
			_delayVals
		);
	}


I would like to use the FirInit function and allocate and retain the state myself

I think that's the idea of this function - not sure.

I've put in some code that I think works.

Code:

{
	_numQuads = numTaps;

	if (_numQuads)
	{
		_tapVals = ippsMalloc_32f(_numQuads);
		_delayVals = ippsMalloc_16s(_numQuads);

		int BufferSize = ippFirGetStateSize32f_16s(_numQuads);
		// okay - I have the state size, now what do I do with it?

		// I'm thinking, since it's called buffer size that it is the
		// size of pBuffer that is passed?
		_pBuffer = malloc(BufferSize);

		RealVector firCoefs = ds.ImpulseResponse(numTaps);

		for (long i=0; i<_numQuads; ++i)
		{	// fill in the taps
			_tapVals = (float)firCoefs;
			_delayVals = 0;
		}

		ippsFIRInit32f_16s
		(
			&_statePtr,
			_tapVals,
			_numQuads,
			_delayVals,
			_pBuffer
		);

		// is this right?  What about the intialization of _statePtr?
	}
}

BTW the documentation is terrible on this topic and there are no examples.

could someone please tell me:

  1. Why would I use FirInit instead of FirInitAlloc?
  2. Isthe value returned by FIRGetStateSize the size of the buffer provided in the last argument of FIRInit? Is it the size of the what is pointedto by*pState?
  3. Which one of these do I need to allocate myself?
  4. Which malloc function should I use.
  5. - better yet - fill in the codeabove that works.
  6. Will I need to callFIRInit prior to using the filterevery time? (i.e.if I've initialized the filter using FIRInit once and I holdpState, can I simply call FIR with this state pointer each time I want to filter some data?

Answers are greatly appreciated.


0 Kudos
1 Reply
Vladimir_Dudnik
Employee
790 Views

Hi,

there are comments from our expert:

1) Why would I use FirInit instead of FirInitAlloc?

To have ability to manipulate with memory buffers yourself. For example itmight bevery critical for using IPP in device drivers or for using external threading.

2) Is the value returned by FIRGetStateSize the size of the buffer provided in the last argument of FIRInit? Is it the size of the what is pointed to by *pState?

Yes, it is size of State structure + several extra bytes for alignment. You should use BufferSize variable for amount of bytes to allocate. Because of the possible alignment procedure pBuffer pointer and pState pointer can differ. Therefore you should use one returned by FIRInit.

3) Which one of these do I need to allocate myself?

Of course pBuffer.

4) Which malloc function should I use.

BufferSize has the same root as SizeOf() Size always is provided in bytes. Therefore you should use ippsMalloc_8u().

- better yet - fill in the code above that works.

5) Will I need to call FIRInit prior to using the filter every time? (i.e. if I've initialized the filter using FIRInit once and I hold pState, can I simply call FIR with this state pointer each time I want to filter some data?

You dont need to call FIRInit() each time once created, filter can be used as many times as you need. If you need to clear filter history you can simply use ippsFIRSetDelayLine(), if you need to change taps (for example in case of taps adaptation through LMS) (but not filter order) you can use ippsFIRSetTaps() function.

Regards,
Vladimir

0 Kudos
Reply