I use this code to High pass filter accelerometer data but the problem is the reading at "m/2 "although the sensor is stabilized always around -46 ... if there is any one that understands FIR filter please check this code and tell me where is the problem ..also if any one can provide a working FIR code that would be very helpful ...Thanks in Advance

//******************************************************************// "m" : is the order of filter NOTE : it must be even. #// #// "IMPORTANT" : Please set m in te main file. #// #//more info: #// http://www.labbookpages.co.uk/audio/firWindowing.html #//******************************************************************

I use this code to High pass filter accelerometer data but i keep getting results tends to 200--> if there is any one that understands FIR filter please check this code and tell me where is the problem ..also if any one can provide a working FIR code that would be very helpful ...

//******************************************************************// "m" : is the order of filter NOTE : it must be even. // // "IMPORTANT" : Please set m in te main file. // //more info: // http://www.labbookpages.co.uk/audio/firWindowing.html //******************************************************************

This isn't going to work very well because it uses the value 3 for PI. The term (22/7) is an integer division which throws away the fractional part, resulting in 3. Even if you change it to use floating point (22./7.) it is still not a good approximation to PI and will throw off the results.

first: thanks pete I'm attaching here the full code the problem is the output is so huge when it comes to m/2 although other readings around zero. so I have doubt I'm using the wrong equations as I'm new to FIR Concept .finally : how can I fix the PI problem ?Here also attached a snapshot of the results.

The PI problem can be fixed by replacing each occurrence of 22/7 by 3.141592654

I don't know enough about FIR filters to help you with the specifics of your application.But, why are you using a high-pass filter and how do you know that what you are getting is wrong?The data shown in Capture.JPG looks like the filtered output is a sawtooth waveform.

I don't know actually if it is wrong as I said I'm new to filters. But, I'm using High_pass filter to cancel accelerometer drift so that i can integerate data twice getting both velocity and Displacement of Quad Chopter. looking at the data if the data is inegrated the result will give displacement while sensor is stable as it is thats why I think it is wrong.

As I say, I have only played with FIR filters but there are a couple of things that seem to be wrong.

You have specified a cutoff frequency of 7kHz which means that your sampling rate must be considerably more than double that. For an FIR to work, the samples must all be collected at a fixed sampling rate. I can't find anything in your code which does this.

In my (limited) experience, when an FIR is run, it is done continuously on every input sample. This requires some form of circular buffer. That is, when you input a new sample, the FIR is run on that sample and the previous M samples which then produces a new output value. On the next sample, you throw out the oldest sample and then run the FIR again. Your code generates a block of samples at some varying rate, does an FIR on them and then throws those away and starts on a new block.