be.buch
be.buch

Reputation: 41

Apply bandpass filter to float array in swift

I struggle with this for quite some time now. For an iOS App I am recording some Audio using the device's microphone. I later try to evaluate the recording. I got everything done in Python using SciPy and it works very nice. I used SciPy's butterworth filter implementation.

But when I tried to translate my code into Swift I couldn't find a good way to apply a bandpass filter to my float array.

Could anyone guide me into the right direction or do you have finished code samples? I need a bandpass filter with frequency range from 1100 to 2100 Hz.

Upvotes: 1

Views: 2241

Answers (1)

be.buch
be.buch

Reputation: 41

For any future visitors here is the solution:

https://github.com/bartolsthoorn/NVDSP
Thanks to the answer, this library solved it.
I had to create a bridging header for Swift, but that was no big problem. Final code looks like this.

let bandpass: NVBandpassFilter = NVBandpassFilter(samplingRate: fs)
bandpass.centerFrequency = 1600.0
bandpass.q = 1.6
bandpass.filterData(&DATA, numFrames: nsamples, numChannels: 1)

The Q-Value can be calculated like that:

Q = center_frequency / (top_frequency - bottom_frequency)

Upvotes: 3

Related Questions