1
$\begingroup$

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.

$\endgroup$

2 Answers 2

2
$\begingroup$

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!

$\endgroup$
4
  • $\begingroup$ It looks like he is doing the convolution in the line "hcombo = conv(hlpf,hnotch);" $\endgroup$
    – Hilmar
    Commented Nov 11, 2013 at 11:34
  • $\begingroup$ Can you point me to what is incorrect with the notch filter? $\endgroup$ Commented Nov 11, 2013 at 11:51
  • 2
    $\begingroup$ 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). $\endgroup$
    – Kenneide
    Commented Nov 11, 2013 at 13:22
  • $\begingroup$ I am unable to work on the problem at the moment, but do you believe fixing the notch filter will fix the combo filter? $\endgroup$ Commented Nov 11, 2013 at 14:16
1
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ They both work individually $\endgroup$ Commented Nov 11, 2013 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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