2

I'm trying to design a bandstop filter and it's failing to give me a valid (wav file) output due to nan values in the filter output.

The input is a simple speech clip a few seconds long.

def bandstop(x, f1, f2):
    fs, samples = wavfile.read(x)
    N = 6  # filter order
    rs = 60  # stop band minimum attenuation
    b, a = signal.cheby2(N, rs, [2 * f1 / fs, 2 * f2 / fs], btype='bandstop')  
    xfiltered = signal.filtfilt(b, a, samples)  # applying filter
    wavfile.write("xfiltered.wav", fs, xfiltered)  # returns unreadable file?

I'm testing this with a simple

print xfiltered

to find nan values. Any solutions?

Octavious
  • 21
  • 1
  • 3
  • what *is* it returning? – n1c9 Mar 24 '16 at 17:24
  • A .wav file which refuses to open / contains 0 values when forced, and when "xfiltered" is printed pre wav conversion I just have "[ nan nan nan ..., nan nan nan]" – Octavious Mar 24 '16 at 17:54
  • What is the value of `f1`, `f2`, `fs`? – unutbu Mar 24 '16 at 17:59
  • f1 = 500 f2 = 5000 though I plan to play with those once this is working. fs is 48000 – Octavious Mar 24 '16 at 18:08
  • If you are using Python2, [`/` performs integer division](http://stackoverflow.com/q/183853/190597) on ints. So if `f1, f2, fs = 500, 5000, 48000` then `[2 * f1 / fs, 2 * f2 / fs]` would equal `[0, 0]`. Make sure to convert the inputs to floats (e.g. `fs = 48000.0` suffices) before performing the division. – unutbu Mar 24 '16 at 18:19
  • Thankyou! Ridiculous I hadn't noticed that one, simple – Octavious Mar 24 '16 at 18:32

0 Answers0