cancel
Showing results for 
Search instead for 
Did you mean: 

FIR Low Pass Filter, first few values of array incorrect

willschneider
Associate II
Posted on August 15, 2013 at 16:32

Hi all,

I've been trying to implement a low pass filter, following closely the example found here - http://www.keil.com/pack/doc/arm/cmsis/cmsis/documentation/dsp/html/arm_fir_example_f32_8c-example.html#a15 Frustratingly its almost working perfectly, except that the first 12 values of my output array are incorrect, they are all near zero. The rest of the values are fine. I'm using an array of size 1024, seperated into blocks of 32, therefore 32 passes are required. Here is most of my code -

//SET UP VALUES FOR LOW PASS FILTER - TEMP - MOVE SOMEWHERE BETTER
static uint32_t blockSize = BLOCK_SIZE;
//static float32_t firStateF32[(blockSize + 29 - 1)];
static float32_t firStateF32[(BLOCK_SIZE +29 -1)];
void LPFilter(void)
{
arm_fir_instance_f32 V;
//1024/32 =  So 32 blocks of 32 to be processed in the filter...
uint32_t numBlocks = (BUFFERSIZE/2)/blockSize;
uint32_t i = 0;
float32_t *input, *output;
/* Initialize input and output buffer pointers */
input = &InDisplay2[0];
output = &OutDisplay2[0];
/* Call FIR init function to initialize the instance structure. */
arm_fir_init_f32(&V, 29, (float32_t *)&firCoeffs32[0], &firStateF32[0], blockSize);
/* ----------------------------------------------------------------------
** Call the FIR process function for every blockSize samples
** ------------------------------------------------------------------- */
for(i=0; i < numBlocks; i++)
{
arm_fir_f32(&V, (input + (i * blockSize)), (output + (i * blockSize)), blockSize);
}
}

Is this a known issue? After a bit of searching I couldnt find any others with the same problem. But my code seems to be following the example perfectly! #stm32f4
7 REPLIES 7
willschneider
Associate II
Posted on August 16, 2013 at 12:51

I'm still struggling with this.

Must the NUM_TAPS value (the size of the coefficients array) have a relationship to the size of the input array, or even the blocksize? I cant find any clear documentation on it.

zzdz2
Associate II
Posted on August 18, 2013 at 13:08

I think applying the FIR may cause a delay of about half the FIR size, it's OK.

If I understand correctly, when you put single max sample at the start and then all zeros you will get the finite impulse response itself at the output.

You can try to write your own filter code, it's not very complicated, google ''fir filter code''

willschneider
Associate II
Posted on August 18, 2013 at 20:45

Thanks for the reply, I really appreciate it. 

In this case, for real-time filtering, would I be better placed to try a different filtering method? (not an FIR filter)

zzdz2
Associate II
Posted on August 19, 2013 at 09:35

It depends on how much CPU power you can spend on it.

Also if you use high cutoff freq fir may be best, for low cutoff I would use state variable filter.

John F.
Senior
Posted on August 19, 2013 at 09:48

An FIR calculates a single output value from the scaled sum of several samples either side. An FIR is guaranteed stable. For a good introduction to DSP see (free on-line),

http://www.dspguide.com/

One of the best books for engineers in my view is, ''Understanding Digital Signal Processing'' (3rd Edition) by Richard G. Lyons - you have to pay for this book.

willschneider
Associate II
Posted on August 19, 2013 at 10:42

My suspicions that my filter is working incorrectly are now growing, I dont think the FIR delay you mention should be causing what I am seeing. I could well be wrong though.

At the start of each output, the first few values look to me like they are showing the frequency response itself (in a similar way to what knik described?), after this I get the filtered signal.

Surely this is not correct behaviour?

zzdz2
Associate II
Posted on August 20, 2013 at 14:02

The online book pointed by John F. explains it quite well:

http://www.dspguide.com/ch6/2.htm

''The mathematics behind convolution doesn't restrict how long these signals are. It does, however, specify the length of the output signal. The length of the output signal is equal to the length of the input signal, plus the length of the impulse response, minus one.''

With FIR you would get half of the impulse response at the start and half at the end of output.