# A filter in IOS to eliminate a certain frequency range

I am making an application where I record sound on an IOS device using the built-in microphone. I want to process the sound in such a way that only frequencies in the 16-18 kHz range remain; the other frequencies should be eliminated. I read in some posting that I can use a band pass filter to get this result. Any help will be appreciated.

## 2 Answers

You can think of a discrete signal as an array of values, a filter as another array of values (not necessarily of the same size), and filtering as performing an operation called convolution on both the filter and input arrays.

You can get the filter array by using programs such as Matlab, scientific python or octave (the last two are free). You can implement the filtering operation by coding the convolution operation in your own program.

Be aware that convolution can be cpu-intensive. The 'better' the filter (or, the higher its order), the larger the filter array. A better filter rejects more of the signal outside the 16-18 kHz range, and distorts less the signal inside the range. However, having more elements, a convolution using it requires more operations (basically multiplications and additions). This may be a concern on a mobile device.

See this page for detailed descriptions (including source code) of scientific python commands that do what you need. Look in particular for convolve and firwin2.

Broadly speaking, you need an Audio Unit graph with a remoteIO unit doing the recording and you can then add filter audio units onto it.

Core Audio is a C api though and it takes a bit of getting the hang of, if you are prepared to support iOS8 only you can check out AVAudioEngine - https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioEngine_Class/