Electronic – How to improve the digital filter to extract DC from noises

digital filterdspfiriirpid controller

Digital filter description:

  1. The filter's input are sensor data and output will be provided to a PID controller.

  2. Sampling rate: 64kHz

  3. Noises spectrum: from DC to 10kHz

  4. Filter target: to get DC component only and reduce noises as much as possible.

  5. Characteristic of DC: it varies very slowly, say at 0.000001Hz.

More about the system

  1. The system input (ref or reference is zero). And actually the goal of the controller is to maintain the output of the system at zero.

  2. In this system, there are also disturbance and noises. The disturbance has the shape of roughly a ramp, however by nature more like random events at very low frequency

  3. The controller is a simple PI controller. It strives to compensate the influence from disturbance while get rid of noises.

  4. The noises are from sensors and the filter between controller and sensor is what I am looking for help about here.

enter image description here

My current way of filter design:

  1. The data will go into a decimator for decimation firstly. The decimator is an 320 tap average filter, which average every 320 data and exports one averaged result. The results will be at 200Hz.

  2. The averaged data will then further go into a 20 tap averaging decimator. The results will be at 10Hz.

  3. At last, the data at 10Hz will go into an IIR or again, a moving average filter. The final result shall ranges from 1Hz to 0.2Hz.

My concerns: Insufficient desgin

The averaging decimator may not be sharp enough, since they are basically FIR with same coefficients of 1/320. Since the filters are not sharp enough, decimation(downsampling) may introduce high frequency noises mapping into the filtered results.

The following diagram is the response for 1/320 averaging filter
enter image description here

May not be bad

Since the several stages of decimation is basically averaging the signals. The results shall be DC component, since that is how DC is defined.

Advice needed

How to improve my current design?

Best Answer

Your first problem is not insufficient design, but insufficient specification. Please note that 'as much as possible' is not a specification!

Rather than wondering whether any particular filter is sharp enough, and may introduce high frequency noises onto the results, it would be more constructive to specify how much attenuation is required at what frequencies, and then design a filter that gives this attenuation.

One of the first specification points is what the output sample rate should be. The lowest rate you mention is 10Hz, but then it is filtered after that. Is that the output rate, or does it come down? If your DC is varying at 1uHz, then even 10Hz could be considered to be rather over-sampled!

I'm not sure how you arrived at using a first stage filter of 320 taps?

Anyhow, deep decimation like you're doing here will typically involve two stages.

First stage - get a large reduction in sample rate down to a few times your final rate, using a crude low pass filter, to have deep rejection nulls around your final sampling rate, nulls wide enough to accommodate your final bandwidth. This filter runs frequently, so will need to be short. This could be a CIC filter, though that requires very high precision, can need bignums for a large rate change. A low order decimating FIR is perhaps a better choice for a software implementation.

Second stage - design a final filter that eliminates the noise that has been aliased by the crude first stage filter, and drops the rate to the final desired one. This filter runs rarely, so can be very long.

Where the output rate does oversample your required bandwidth by a large factor, you can afford to be very inefficient with your filter design. In these cases, it looks like the case you describe, an iterated first order IIR filter is a reasonable choice.

The beauty of a first order IIR filter is that the effective length is adjusted merely by setting the value of k in the recurrence relation. You can either iterate it to improve the steepness slightly, or simply oversample a lot to allow the poor stopband not to influence your results. There is the very real problem that a small k and/or large decimation ratio can run you into numeric precision problems if you are not careful.

This may not be the easiest filter to design by forum. I am happy to help you firm up your spec and help you design it offline, just for the lols.