📜 ⬆️ ⬇️

The practice of using digital filters

I am doing a project here and there is this problem. I get data from the ADC (delta-sigma) chip in which the controller and the filter are built in, but this filter has a rather poor frequency response, as a result there is a dam on HF from 60Hz and beyond. It looks like this:
image

Those. This uneven frequency response clearly does not suit us (does not pass on technical requirements), although it is possible to increase the sampling rate from 250Hz to 500Hz to even out the frequency response, but then the amount of data that still needs to be averaged increases, which will affect the performance (project on STM32F103VE) systems in general and on total energy consumption (battery power). But there is another way.

You can align the frequency response using a parametric digital filter, in this case, the RF. That is, this is the same as the equalizer, we raise some frequencies, while others do not touch (or fill up). This method is certainly good, but because we are trying to recover information, part of which was destroyed by another input filter (the one on the chip), will inevitably increase the level of interference at high frequencies, because together with the signal we will strengthen them too, but how much?

So, the idea of ​​solving the problem is, there is implementation. What do we remember about digital filters (for those who did not have any practice with them) from the university course? Is that such words as convolution, Z-transform, impulse response, etc. In general, it’s not clear from which end to even come up, it’s necessary to count some factors, but what’s not clear and why, you’ll have to raise the course and sit with books on DSP (there is one 800 pages), the project is worth it and you need to do something , and fast.
')
Therefore, a little googling find such a resource on the Internet. This is a site for calculating digital filters (and not only!) Online, but it was made by a certain Dr Anthony J. Fisher.

So we ask the requirements that we need and enter on the site. Firstly, we need a smooth characteristic, so the first-order Butterworth is clearly a highpass. Secondly, sample rate, i.e. the number of ADC conversions per second, or sampling rate, we have is 250 Hz. We enter. And finally, thirdly, the cut-off frequency (-3dB) is 50 Hz, because The inlet filter cuts around here. Click send and get this characteristic of our future filter:
image
The red graph shows the amplitude versus Nyquist frequency, the blue phase change. 0.5 corresponds to half the sampling rate.

We also get a C code with calculated coefficients:
#define NZEROS 1 #define NPOLES 1 #define GAIN 1.726542528e+00 static float xv[NZEROS+1], yv[NPOLES+1]; static void filterloop() { for (;;) { xv[0] = xv[1]; xv[1] = next input value / GAIN; yv[0] = yv[1]; yv[1] = (xv[1] - xv[0]) + ( 0.1583844403 * yv[0]); next output value = yv[1]; } } 

But this is only a filter, remember that we need to increase the frequencies from 50Hz and higher to straighten the frequency response, and this function in this form does not help us, therefore, by simple manipulations, we bring the function to this form:
 #define NZEROS 1 #define NPOLES 1 #define GAIN 1.726542528e+00F #define OUR_GAIN 2.1F //  .   float xv[NZEROS+1], yv[NPOLES+1]; int void filterloop( int data ) { xv[0] = xv[1]; xv[1] = (float)data / GAIN; yv[0] = yv[1]; yv[1] = ( xv[1] - xv[0] ) + ( 0.1583844403F * yv[0] ); return (int)(( yv0[1] * OUR_GAIN ) + (float)data ); } 


Everything. To use the filter, we throw data into the function parameters, and it returns the filtered data. Gain OUR_GAIN select empirically, taking readings from the ADC and measuring the frequency response.

Thus, I managed to raise the frequency response with almost no additional load on the controller and my project went through technical requirements (in the medical field, they are not quite frail). I was afraid that the level of interference would increase greatly, but it increased from 4-5µV to about 6-8µV, which suits us. In conclusion, I can recommend another free program for calculating digital filters - WinFilter, you can download it here . I don’t know how efficient it is, I didn’t check it, but it can issue a code in VHDL (and in C naturally), which is probably useful for FPGAs. There is also a program from Texas Instuments, according to the calculation of the coefficients of digital filters, it is called TIBQ . Everything. Good luck in designing digital filters.

Source: https://habr.com/ru/post/148326/


All Articles