Lo que tienes es la ecuación de un filtro pasa bajos unipolar. Este es el equivalente discreto del filtro analógico R-C. Mientras que su ecuación es correcta, me gusta escribirlo como
FILT <-- FILT + FF(NUEVO - FILT)
porque esto es un poco más conveniente de realizar en un microcontrolador en la mayoría de los casos.
Por lo general, la vista del filtro en el dominio del tiempo es más directamente utilizable cuando se implementa uno de estos en un microcontrolador. La mayoría de las veces te preocupas más por la frecuencia de muestreo y el tiempo de respuesta que por el rolloff de frecuencia. Sin embargo, este último sí aparece, por lo que he incorporado algunas facilidades para manipularlo en mi preprocesador PIC. El fragmento de documentación de las dos funciones en línea relevantes es:
FFTC2 tcfilt sfreq
Computes the filter fraction of a single pole low pass filter.
TCFILT is the 1/2 decay time of the filter, and SFREQ is the sample
frequency. The filter fraction is the weighting fraction of the
incoming signal each filter iteration. The result data type is
floating point.
FFFREQ ffreq sfreq
Computes the filter fraction of a single pole low pass filter.
FFREQ is the desired -3dB rolloff frequency of the filter, and
SFREQ is the sample frequency.
Hice los cálculos cuando escribí el código de esas funciones, así que me limitaré a remitirte a él en lugar de repetirlo ahora:
\* FFTC2 tcfilt sfreq
}
4: begin
if not term\_get (fstr, p, val) then goto arg\_missing;
a1 := val\_fp (val); {get power of 2 time constant}
if not term\_get (fstr, p, val) then goto arg\_missing;
a2 := val\_fp (val); {get sampling frequency}
r := 1.0 - 0.5 \*\* (1.0 / (a1 \* a2)); {make the filter fraction}
ret\_r: {common code to return FP value in R}
str\_from\_fp (r, tk); {make floating point string in TK}
string\_append (lot, tk); {append floating point string to the output}
end;
{
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*
\* FFFREQ ffreq sfreq
}
5: begin
if not term\_get (fstr, p, val) then goto arg\_missing;
a1 := val\_fp (val); {get filter rolloff frequency}
if not term\_get (fstr, p, val) then goto arg\_missing;
a2 := val\_fp (val); {get sampling frequency}
r := pi2nv / a1; {make standard power of E time constant}
r := 1.0 - env \*\* (1.0 / (r \* a2)); {make the filter fraction}
goto ret\_r; {return the value in R}
end;
La matemática real de la función FFFREQ es de sólo dos líneas de código, por lo que se puede averiguar. Parece que esto depende de algunas definiciones en la parte superior del archivo:
{
\* Physical constants. Don't mess with these.
}
pi = 3.14159265358979323846; {what it sounds like, don't touch}
e = 2.718281828; {ditto}
pi2 = 2.0 \* pi; {2 Pi}
pi2nv = 1.0 / pi2; {1 / 2Pi}
env = 1.0 / e; {1 / e}
ln2 = ln(2.0); {natural log of 2}
Si estás haciendo esto en un PIC, es posible que desees utilizar el preprocesador. Está incluido en el Herramientas de desarrollo PIC liberar en http://www.embedinc.com/pic/dload.htm . El código fuente del preprocesador se incluye en el archivo Código fuente del host y todo liberación.