Necesito diseñar un filtro de promedio móvil que tenga una frecuencia de corte de 7.8 Hz. He usado filtros de promedio móvil antes, pero que yo sepa, el único parámetro que puede introducirse es el número de puntos a promediar ... ¿Cómo puede esto relacionarse con una frecuencia de corte?
El inverso de 7.8 Hz es ~ 130 ms, y estoy trabajando con datos que se muestrean a 1000 Hz. ¿Esto implica que debería estar usando un tamaño de ventana de filtro de promedio móvil de 130 muestras, o hay algo más que me falta aquí?
moving-average
CaptainProg
fuente
fuente
Respuestas:
El filtro de media móvil (a veces conocido coloquialmente como filtro de vagón ) tiene una respuesta de impulso rectangular:
O, dicho de otra manera:
Recordando que la respuesta de frecuencia de un sistema de tiempo discreto es igual a la transformada de Fourier de tiempo discreto de su respuesta de impulso, podemos calcularla de la siguiente manera:
Para simplificar esto, podemos usar la fórmula conocida para la suma de los primeros términos de una serie geométricaN :
Lo que más nos interesa para su caso es la respuesta de magnitud del filtro, . Usando un par de manipulaciones simples, podemos obtener eso en una forma más fácil de comprender:El | H( ω ) |
Esto puede no parecer más fácil de entender. Sin embargo, debido a la identidad de Euler , recuerde que:
Por lo tanto, podemos escribir lo anterior como:
As I stated before, what you're really concerned about is the magnitude of the frequency response. So, we can take the magnitude of the above to simplify it further:
The resulting function inside the magnitude brackets is a form of a Dirichlet kernel. It is sometimes called a periodic sinc function, because it resembles the sinc function somewhat in appearance, but is periodic instead.
Anyway, since the definition of cutoff frequency is somewhat underspecified (-3 dB point? -6 dB point? first sidelobe null?), you can use the above equation to solve for whatever you need. Specifically, you can do the following:
Set|H(ω)| to the value corresponding to the filter response that you want at the cutoff frequency.
Setω equal to the cutoff frequency. To map a continuous-time frequency to the discrete-time domain, remember that ω=2πffs , where fs is your sample rate.
Find the value ofN that gives you the best agreement between the left and right hand sides of the equation. That should be the length of your moving average.
fuente
IfN is the length of the moving average, then an approximate cut-off frequency Fco (valid for N>=2 ) in normalized frequency F=f/fs is:
The inverse of this is
This formula is asymptotically correct for large N, and has about 2% error for N=2, and less than 0.5% for N>=4.
P.S.: After two years, here finally what was the approach followed. The result was based on approximating the MA amplitude spectrum aroundf=0 as a parabola (2nd order Series) according to
which can be made more exact near the zero crossing ofMA(Ω)−2√2 by multiplying Ω by a coefficient
obtainingMA(Ω)≈1+0.907523(124−N224)Ω2
The solution ofMA(Ω)−2√2=0 gives the results above, where 2πFco=Ωco .
All of the above relates to the -3dB cut off frequency, the subject of this post.
Sometimes though it is interesting to obtain an attenuation profile in stop-band which is comparable with that of a 1st order IIR Low Pass Filter (single pole LPF) with a given -3dB cut off frequency (such a LPF is also called leaky integrator, having a pole not exactly at DC but near to it).
In fact both the MA and the 1st order IIR LPF have -20dB/decade slope in the stop band (one needs a larger N than the one used in the figure, N=32, to see this), but whereas MA has spectral nulls atF=k/N and a 1/f evelope, the IIR filter only has a 1/f profile.
If one wants to obtain an MA filter with similar noise filtering capabilities as this IIR filter, and matches the 3dB cut off frequencies to be the same, upon comparing the two spectra, he would realize that the stop band ripple of the MA filter ends up ~3dB below that of the IIR filter.
In order to get the same stop-band ripple (i.e. same noise power attenuation) as the IIR filter the formulas can be modified as follows:
fuente