Electronic – What’s wrong with the IIR filter

dspfiltersignal processing

I'm using C language to implepement a simple 4th order lowpass IIR filter. I used ellip on matlab to get my coefficients,more specifically ellip(4,0.25,10,0.25). This is the frequency response on matlab.enter image description here

Since my sampling rate is at 48KHz the filter should cut off frequencies above 6KHz.

Now, I know that something might be wrong with my code, which I will upload if necessary, but this is the output and input for some sounds:enter image description hereenter image description hereenter image description hereenter image description here

Low frequencies seem to pass with mild decrease while frequencies above 6 KHz are not completely cut off until about 11KHz although there is a sensible decrease above 6KHz. Is this to be expected or should I start looking at my code?

UPDATE:
I haven't heard about passband ripple and stopband attenuation before. I just had a look at this question : what's the pass band ripple and stop band attenuation of a digital filter?

So now my main focus is to understand ellip. We have 0.25 dB passband so the small decrease in frequencies below 6 KHz makes sense( if I'm connecting this right). We also have 10dB stopband attenuation which justifies the high values for high frequencies. But why does the stopband attenuation stop at very high frequencies? Do passband and stopband ripple apply for frequencies only close to the 'cut-off' frequency?

Best Answer

You should start looking at your filter. Judging from the frequency response, the outputs look like expected.

You have designed a filter with a lowly 10 dB attenuation in the stop band. I would not call that a "cutoff", more like subtle equalizing. The stop band is everything after your cutoff frequency, including the very far edge. An elliptic filter doesn't necessary keep "falling off".

You should be able to get much better than that with a 4th order elliptic filter, if you just want a 6 kHz lowpass filter. Try pumping the dB up to 11 60 or so. 10 dB attenuation is hardly anything.