¿Cuál es la frecuencia de corte de un filtro de media móvil?

18

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í?

CaptainProg
fuente
Primero debe definir su comprensión del "corte". Si es la última frecuencia arriba (abajo) que la respuesta de un filtro es cero, entonces la respuesta sería "ninguna", ya que el núcleo de un filtro de promedio móvil tiene un soporte finito, y las wavelets finitas se transforman en imágenes infinitas de Fourier.
mbaitoff
El filtro de promedio móvil es el filtro utilizado en el dominio del tiempo para eliminar el ruido agregado y también para suavizar, pero si usa el mismo filtro de promedio móvil en el dominio de frecuencia para la separación de frecuencia, el rendimiento será peor ... entonces en ese caso use filtros de dominio de frecuencia

Respuestas:

27

El filtro de media móvil (a veces conocido coloquialmente como filtro de vagón ) tiene una respuesta de impulso rectangular:

h[norte]=1nortek=0 0norte-1δ[norte-k]

O, dicho de otra manera:

h[norte]={1norte,0 0norte<norte0 0,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:

H(ω)=n=x[n]ejωn=1Nn=0N1ejωn

Para simplificar esto, podemos usar la fórmula conocida para la suma de los primeros términos de una serie geométricaN :

norte=0 0norte-1mi-jωnorte=1-mi-jωnorte1-mi-jω

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(ω)El |

H(ω)=1Nn=0N1ejωn=1N1ejωN1ejω=1NejωN/2ejω/2ejωN/2ejωN/2ejω/2ejω/2

Esto puede no parecer más fácil de entender. Sin embargo, debido a la identidad de Euler , recuerde que:

sin(ω)=ejωejωj2

Por lo tanto, podemos escribir lo anterior como:

H(ω)=1NejωN/2ejω/2j2sin(ωN2)j2sin(ω2)=1NejωN/2ejω/2sin(ωN2)sin(ω2)

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:

|H(ω)|=1N|sin(ωN2)sin(ω2)|

|ejω|=1ω|xy|=|x||y| for any two finite complex numbers x and y, we can conclude that the presence of the exponential terms don't affect the overall magnitude response (instead, they affect the system's phase response).

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:

  1. Set |H(ω)| to the value corresponding to the filter response that you want at the cutoff frequency.

  2. 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.

  3. Find the value of N 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.

Jason R
fuente
By my reckoning, that's a 'yes'? As far as I can tell, 130 samples seems to fit N with ω = 7.8, but I'm no mathematician.
CaptainProg
@CaptainProg: Only you can say for sure; I'm not sure what you wanted the magnitude response to be at the cutoff frequency.
Jason R
1
Could you define what n and N are? An example with a given sampling frequency would also be very helpful. This may sound simple, but this question is the top result for "moving average cutoff frequency", so I am sure there will be many other viewers who have fallen out of touch with the math behind filters.
FvD
@FvD n is the sample index for the signal x[n], as is typically used for discrete-time signals. N is defined in the first equation above. If I get a chance I can add an example, but I suspect that anyone who is choosing to design a filter to meet a particular cutoff frequency can follow the math.
Jason R
10

If N 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:

Fco=0.442947N21

The inverse of this is

N=0.196202+Fco2Fco

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 around f=0 as a parabola (2nd order Series) according to

MA(Ω)=Sin(ΩN/2)Sin(Ω/2)

MA(Ω)1+(124N224)Ω2

which can be made more exact near the zero crossing of MA(Ω)22 by multiplying Ω by a coefficient

α=0.95264

obtaining MA(Ω)1+0.907523(124N224)Ω2

The solution of MA(Ω)22=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).

relations between a MA filter (FIR, N-1 zeros) and a 1-pole IIR LPF

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 at F=k/N and a 1/f evelope, the IIR filter only has a 1/f profile.

HIIR=1Exp(Ωco)1Exp(Ωco)Exp(jΩ)

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:

Fco,IIR=0.32N21

N=0.1024+Fco,IIR2Fco,IIR

Massimo
fuente
I changed your formula to the latex format. Please double check and confirm both of them are correct. Thanks.
lennon310
I added a derivation of this approximation here dsp.stackexchange.com/a/28186/15347
Olli Niemitalo
2
As far as i remember i derived this formula with pragmatic concerns in mind, by means of numerical methods (either NSolve in Mathematica or something similar in Matlab), which should be asymptotically correct for large N. The number you gave is about 3% off, so i am not sure what to say.
Massimo
1
@Massimo we did a lot of work on this and other approximations in the other question. If you ever need more decimal places this is your magic number: 0.442946470689452340308369
Olli Niemitalo
1
I found back the Mathematica script where i calculated the cut off for several filters, including the MA one. The result was based on approximating the MA spectrum around f=0 as a parabola according to MA(Ω)=Sin(ΩN/2)/Sin(Ω/2) ; Omega=2πF; MA(F)N+1/6F2(NN3)π2 . And deriving the crossing with 1/2 from there.
Massimo