# Combining two filters (audio processing)

I'm trying to combine two filters into a single filter command for a homework problem and was looking for advice. I don't necessarily need an explicit answer as long as someone can point me in the right direction.

In the following code, assume that 'y' is a sound file that has been pre-loaded (10kHz). Also, both the hlpf and hnotch filters work together separately to produce an audio signal with noise and a beeping tone removed. However, when I try to combine the two into a single filter, I do not achieve this result. Here is my code:

Fs = 10000;
f0 = 1000;                %#notch frequency
fn = Fs/2;              %#Nyquist frequency
freqRatio = f0/fn;      %#ratio of notch freq. to Nyquist freq.
notchWidth = 0.1;       %#width of the notch

%Compute zeros
zeros = [exp( sqrt(-1)*pi*freqRatio ), exp( -sqrt(-1)*pi*freqRatio )];

%Compute poles
poles = (1-notchWidth) * zeros;
b = poly( zeros ); %# Get moving average filter coefficients
a = poly( poles ); %# Get autoregressive filter coefficients

hnotch = [poly(poles)];
alpha = 0.42;
hlpf = fir1(100, alpha);
hcombo = conv(hlpf,hnotch);
s2 = filter(hcombo,1,y);
soundsc(s2,Fs)


Any help would be greatly appreciated.

In order to combine two filters, you need to convolve their impulse responses, and you haven't done that in this case.

In fact, according to this code snippet, the notch filter is incorrectly built.

I'm sure once you review it you'll figure out your errors. Good luck!

• It looks like he is doing the convolution in the line "hcombo = conv(hlpf,hnotch);" – Hilmar Nov 11 '13 at 11:34
• Can you point me to what is incorrect with the notch filter? – Andrew Corsini Nov 11 '13 at 11:51
• I see that there is a convolution being performed, but the hnotch is not the impulse response of the notch filter that you have designed. hnotch is the polynomial resulting from two poles. Instead, hnotch should probably be: hnotch = impz(b,a). – Kenneide Nov 11 '13 at 13:22
• I am unable to work on the problem at the moment, but do you believe fixing the notch filter will fix the combo filter? – Andrew Corsini Nov 11 '13 at 14:16

Hint: build, test and verify the two filters individually first. If that all checks out, stare at the code and figure out what's the same and what's different between the filters and the filter operation.

• They both work individually – Andrew Corsini Nov 11 '13 at 11:52