// Filter Definitions
var fs = 256; // The sampling rate
var fc = 12.5; // The cutoff frequency (Hz)
var N = 65; // The width of the averaging window
function filterTapsGenerator()
{
// Prepare an array to contain the taps of the filter's impulse response
var Taps = new Array(N);
// Calculated the normalized cutoff frequency
var ft = fc/fs;
// Loop to calculate the filter taps
for (var n=0; n<N; n++)
{
if (n == (N-1)/2)
{
// Ensure that the current tap is defined at time index n = (N-1)/2
var g_n = 2*ft;
}
else
{
// Calculate the current tap
var g_n = Math.sin(2 * Math.PI * ft * (n - (N-1)/2)) / (Math.PI * (n - (N-1)/2));
}
// Calculate the Hanning window coefficient for the current tap
var w_n = 0.5 - 0.5 * Math.cos(2 * Math.PI * n/(N-1));
// Apply the Hanning window coefficient to the current tap
g_n = g_n * w_n;
// Add the current tap to the impulse response array
Taps[n] = g_n;
}
// return the impulse response array
return Taps;
}