matlabsignal-processingdigital-filter

How to make a multiple notch filter in MATLAB?


I'm designing a filter to remove the noise from a piece of audio. I found the noise frequencies are located at 745 and 1965 Hz in the spectrum but I don't know how to make a multiple notch filter to remove these two specific frequencies

This is my code. I can only remove one frequency in the audio. Is there any way to make convolution of two filters in MATLAB?

%Reading first sample file
[x1,fs1] = audioread('sample.wav');

%Creating the time span for the file
t1=(0:length(x1)-1)/fs1;

%Creating the frequency span for the file
k1 = 0:length(x1)-1;
f1=k1*fs1/length(x1);
wg=[744.5*2/fs1 745.5*2/fs1 ];

%Creating  filter
[b1,a1] = butter(2,wg,'stop'); 

%Performing filtering on file
x1f = filter(b1,a1,x1);

Solution

  • As you already mention, you have to convolve the two filters to combine them. This can be done using the conv function.

    % Design first filter
    wg1 = [744.5*2/fs1, 745.5*2/fs1];
    [b1,a1] = butter(2,wg1,'stop');
    
    % Design second filter
    wg2 = [1964.5*2/fs1, 1965.5*2/fs1];
    [b2,a2] = butter(2,wg2,'stop');
    
    % Convolve filters
    a0 = conv(a1, a2);
    b0 = conv(b1, b2);
    
    % Plot filter
    freqz(b0, a0, 4096, fs1);
    

    bode plot of designed filter