Digital filter design:
The cardiac signal has a bandwidth of 200Hz, we want to design a filter to remove band reject of 60Hz power line induced around us:
1. Calculation:
BW = bandwidth of the input signal.
Fs: Sampling frequency.
FNyquist: Nyquist frequency.
Fn = frequency standard for Matlab.
Fs=2*BW=2*200Hz=400Hz Fnyquist=BW=200Hz |
2. Selection of frequency:
N = Order of the digital filter.
AB = Bandwidth.
fir1 - Window-based FIR filter design This MATLAB function uses a Hamming window to design an nth-order lowpass , bandpass, or multiband FIR filter with linear phase.
b = fir1(N, AB) b = fir1(N, AB, ftype)
ftype= ‘LOW’,’HIGH’. |
Note: For the correct choice of filter order must use values close to 90, for behold where an FIR filter has the same response as an IIR filter optimally.
The bandwidth must be separated over 20 Hz or integral multiples of this so that the filter has a high attenuation (dB).
Demonstration:
First case- poor selection of bandwidth:
Select a width of less than 10 Hz band.
Finferior = 55Hz
Fsuperior = 65Hz
h = fir1(90,[55/200 65/200],'stop') freqz(h,1,512) |
---|
coefficients generated |
---|
Conclusion: The maximum drop is 20dB, attenuation is very low for such a high order filter.
Second case-bandwidth Excellent Selection:
Finferior = 55Hz
Fsuperior = 75Hz
Selected width greater than 20Hz band and the result was good, with a 72dB care.
General code in Matlab: |
---|
h = fir1(90,[50/200 75/200],'stop') freqz(h,1,512) h=fliplr(h); fid=fopen('archivo.txt','w'); fprintf(fid,'const float32_t firCoeffs32[NUM_TAPS] = {\n'); fprintf(fid,'%0.10ff, \n',h); fprintf(fid,'};'); |
This code creates a text file with the output coefficients RMx to add to Hercules.
https://www.keil.com/pack/doc/CMSIS/DSP/html/arm_fir_example_f32_8c-example.html
Main code file (Hercules RM57x): |
---|
#include "HL_sys_common.h" /* USER CODE BEGIN (1) */ #include "HL_adc.h" #include "arm_math.h" #include "type_defs.h" /* USER CODE END */ #define TEST_LENGTH_SAMPLES 512 #define BLOCK_SIZE 16 #define NUM_TAPS 91 /* ------------------------------------------------------------------- * The input signal and reference output (computed with MATLAB) * are defined externally in arm_fir_lpf_data.c. * ------------------------------------------------------------------- */ float32_t testInput_f32_1kHz_15kHz[TEST_LENGTH_SAMPLES]; //extern float32_t refOutput[TEST_LENGTH_SAMPLES]; /* ------------------------------------------------------------------- * Declare Test output buffer * ------------------------------------------------------------------- */ static float32_t testOutput[TEST_LENGTH_SAMPLES]; /* ------------------------------------------------------------------- * Declare State buffer of size (numTaps + blockSize - 1) * ------------------------------------------------------------------- */ static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1]; /* ---------------------------------------------------------------------- ** FIR Coefficients buffer generated using fir1() MATLAB function. ** ------------------------------------------------------------------- */ /*Filtro para una frecuencia de 1kHz*/ const float32_t firCoeffs32[NUM_TAPS] = ADD HERE COEFF OF MATLAB |
Schematic diagram of the cardiac signal amplifier circuit |
---|
Hercules RM57 Launchpad Texas Instruments |
---|
Application:
Input signal:
Signal sampled by the ADC (Hercules RM57x) |
---|
The resolution of the digital analog converter of Hercules is 12 bits, so this can sample much more faithfully the analog signal of the heart.
Filtered signal
The heart signal was properly filtered, you can clearly notice the PQRST wave |
---|
Video |
---|
Tips and Conclusions:
• The application of digital filters Microcontroller is a great option at the time of reducing the elements within a circuit.
• Consideration should be given the capacity version of Hercules you are using, the Rm57 version has an excellent RAM,
allowing you to work without problems in the implementation of digital filters, the RM46 version is also an excellent choice for its large capacity FLASH and RAM.
• The RM42x version is not recommended for the implementation of digital filters for not having large RAM memory.
• The digital filters were designed in MATLAB, for his great accuracy in delivering the coefficients for digital filters.
• We recommend using a high order filters to obtain the desired results.
My best reference Jan Cumps
https://e2e.ti.com/group/launchyourdesign/m/boosterpackcontest/666127
Top Comments