High pass filter in Julia

Viewed 207

I'm recording live audio in 5 second clips with Julia and want to cut out all sounds below a certain frequency. This is my record script so far:

using PortAudio, SampledSignals, LibSndFile, FileIO, Dates

stream = PortAudioStream("HDA Intel PCH: ALC285 Analog (hw:0,0)")

buf = read(stream, 5s)

while true
    save(string("recording_", Dates.format(now(), "yyyymmdd_HHMMSS"), ".wav"), buf, Fs = 48000)

How do I filter out all sound below e.g. 10kHz? I've been looking at the Highpass function from the DSP package but I don't quite understand how to apply it correctly.

1 Answers
using DSP

"""
    highpassfilter(signals, fs, cutoff, order=4)
Apply high pass filter to signals, return filtered data
"""
function highpassfilter(signals, fs, cutoff, order=4)
    wdo = 2.0 * cutoff / fs
    filth = digitalfilter(Highpass(wdo), Butterworth(order))
    filtfilt(filth, signals)
end
Related