ar1st0crat / NWaves

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

Low pass filter returning 0 #28

Closed emepetres closed 4 years ago

emepetres commented 4 years ago

Hi, first of all great work! The code is very clean and understandable.

I'm testing a low pass filter (I tried with BiQuad and Bessel for now), but the output is always 0. I'm trying with frequencies between 1000 and 22000, but no luck. I've changed also q=1 to q=1/sqrt(2), but still the same.

@ar1st0crat could you shed some light on what is happening?

Thanks!

Update: With OnePole, it is the high pass filter the one that always return 0 (frequencies between 0 and 1000).

ar1st0crat commented 4 years ago

Hi!

Thank you for the kind words ).

Could you provide the code? Does it look something like this?


DiscreteSignal signal;
int samplingRate;

// load signal from file
using (var stream = new FileStream("example.wav", FileMode.Open))
{
    var waveFile = new WaveFile(stream);
    samplingRate = waveFile.WaveFmt.SamplingRate;
    signal = waveFile[Channels.Left];
}

var freq = 1000f;              // 1000 Hz, for example

var f = freq / samplingRate;   // normalize frequency onto [0, 0.5] range
var q = 1;

var filter = new Filters.BiQuad.HighPassFilter(f, q);

var filtered = filter.ApplyTo(signal);

// or online:
// foreach (sample)
//    filteredSample = filter.Process(sample)

Also, you can run DemoForms.exe app and try filtering your data there

emepetres commented 4 years ago

Thanks @ar1st0crat , the problem was that I wasn't dividing the frequency by the sampling rate :)

As a suggestion, it would be nice to document a little bit the inputs of each algorithm.

Thanks again!