1
$\begingroup$

I have a question about the implementation of digital filters in CoreAudio. I'm in big trouble because it is a few weeks I'm trying to understand how to implement them. The basic idea is this: while I talk to the iPhone's microphone, my voice is filtered by a low-pass filter or high-pass or bandpass.

Reading the book "Digital Signal Processing" and following the algorithms mentioned in the book "Digital Sound & Music" I came to write the following code (high pass filter):

float cutoff = 5000;
float rate = 44100;
int N = 1024;
float f_c = cutoff/rate;
float ω_c = 2*M_PI*f_c;
int middle = N/2;
int i = -N/2;
float fltr[N];



do {

    if (i == 0)  {
        fltr[middle] = 1 - 2*f_c;
    }
    else {
        fltr[i+middle] = -sin(ω_c*i)/(M_PI*i);
    }
    i++;

} while(i != N/2);

After writing the filter, in the book, you are instructed to run a windowing function. Here I have the problem: I do not understand what to do. Reading on Apple's official documentation, I find the function of Blackman.

int N = 1024;

float dataOut[1024];

for (int n=0; n < 1024; ++n)
{
    dataOut[n] = 0.42 - (0.5 * cos(  2 * M_PI * n / N ) ) + (0.08 * cos( 4 * M_PI * n / N) );
}

But once inserted, what should I do? How can I connect the filter carrier, the Blackman function and the audio signal? I just can not understand it.

Thank you for your attention.

UPDATE 1

I answer to users bristow robert-johnson and Matt L. (I write here because the comment was too long to be invited)

Hi, thank you for answering. There is no filtering at this time because I do not understand how to connect the filter (?) With Blackman window.

What I understand from the chapters devoted to the book “Digital Signal Processing” filters: Create a filter, a sort of kernel filter that is a kind of "mask" to be applied to the signal itself. In this state the filter is said "Impulse Response" or also is said IIR. Now I apply the mask to signal by a function convolution becoming a FIR filter. What I have written is this correct?

As for calculating coefficients, as I understand it, they should be the coefficients Nyquist angular frequency. Is right? If yes, should be variables of "f_c" and "ω_c" (this is written in the commentary of the algorithms in the book).

$\endgroup$
  • $\begingroup$ i dunno what you're trying to do. the first code is the creation of a $\operatorname{sinc}(\cdot)$ function. the second code looks like it creates a Blackman window. i don't see any filtering or any audio data. $\endgroup$ – robert bristow-johnson Feb 4 '17 at 20:46
  • $\begingroup$ Are you aware of the difference between designing a filter (i.e., computing the filter coefficients), and implementing a filter (i.e., filtering data)? What you've done so far is a first step in implementing a simple procedure for the design of a FIR filter (the windowing method). $\endgroup$ – Matt L. Feb 4 '17 at 21:39
0
$\begingroup$

Your sample code looks like it is trying to create a windowed Sinc FIR filter. A Sinc function (the transform of a "brick-wall" rectangle filter) has infinite support, thus it must be windowed to create a finite length FIR filter kernel. There is pseudo-code to generate such a filter, using a Hamming window, on my DSP web page.

You can apply such a FIR filter to audio by convolution with your audio samples (either directly convolution, or using FFT/IFFT overlap-add/save fast convolution on blocks of data).

If you are using iOS frameworks such as Core Audio, note that you can also use the vDSP_biquadm API in the iOS Accelerate framework for IIR filtering.

$\endgroup$
  • $\begingroup$ Hi, thank you for the answer. I saw your blog. I believe you refer to the post "Quick & Dirty FIR filter generation," it right? I've implemented your code but do not understand how to insert my audio signal. $\endgroup$ – Fantastico Feb 4 '17 at 23:56
  • $\begingroup$ You need to look up FIR filters and convolution. Here's a blog post on the topic: hamiltonkibbe.com/… $\endgroup$ – hotpaw2 Feb 5 '17 at 6:48
  • $\begingroup$ Hello, thank you for the link. I read the web page, but I still do not understand. I will be stupid, but do not understand who are the variables "x" and "h". I tried to do various tests, but the filter do not work. I tried to put in the variables, audio signal (x) and the filter that I have shown above (h), but nothing. So who are x and h? Thank you. $\endgroup$ – Fantastico Feb 6 '17 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.