ar1st0crat / NWaves

.NET DSP library with a lot of audio processing functions
MIT License
453 stars 71 forks source link

Butterworth filter constructor have no parameter for sample rate #25

Closed FounderSG closed 4 years ago

FounderSG commented 4 years ago

All other filter design tool take sample rate as a parameter, why NWaves not care about sample rate?

ar1st0crat commented 4 years ago

Similar to MATLAB/sciPy, this library expects normalized frequencies for input. You don't specify sample rate explicitly, but it's there:

double freq_in_Hz = 500;
double sample_rate = 8000;

double freq = freq_in_Hz / sample_rate;

var filter = new Filters.Butterworth.LowPassFilter(freq, order);

// i.e.:
// var filter = new Filters.Butterworth.LowPassFilter(500.0 / 8000, order);

In MATLAB, though, normalized frequencies are mapped onto range [0, 1] (in NWaves it's [0, 0.5]). Hence, the code above would be written as:

[b, a] = butter(order, 2*500/8000, 'low');
FounderSG commented 4 years ago

Thanks for the clear explanation.