Designing a simple bandpass/bandstop filter in Matlab

12,216

Solution 1

Unless I'm mistaken, it sounds like you're taking the wrong approach to this.

If your assignment is to manipulate a signal specifically by manipulating its FFT then ignore me. Otherwise.. read on.

The FFT is normally used to analyse a signal in the frequency domain. If you start fiddling with the complex coefficients that an FFT returns then you're getting into a complicated mathematical situation. This is particularly the case since your cut-off frequencies aren't going to lie nicely on FFT bin frequencies. Also, remember that the FFT is not a perfect transform of the signal you're analysing. It will always introduce artefacts of its own due to scalloping error, and convolution with your hann window.

So.. let's leave the FFT for analysis, and build a filter.

If you're doing band-pass design in your class I'm going to assume you understand what they do. There's a number of functions in Matlab to generate the coefficients for different types of filter i.e. butter, kaiser cheby1. Look up their help pages in Matlab for loads more info. The values you plug in to these functions will be dependent on your filter specification, i.e. you want "X"dB rolloff and "Y"dB passband ripple. You'll need some idea of the how these filters work, and knowledge of their transfer functions to understand how their filter order relates to your specification.

Once you have your coefficients, it's just a case of running them through the filter function (again.. check the help page if you're not sure how this works).

The mighty JOS has a great walkthrough of bandpass filter design here.

One other little niggle.. in your question you mentioned that you want your filter to "filter out" everything between 250Hz and 1000Hz. This is a bit ambiguous. If you're designing a bandpass filter you would want to "pass" everything between 250Hz and 1000Hz. If you do in fact want to "filter out" everything in this range you want a band-stop filter instead.

Solution 2

It all depends on the sampling rate you use. If you sample right according to the Nyquist-Shannon sampling theorem then you can try and interpret the samples of your fft using the definition of the DFT.

For understanding which frequencies correspond with which samples in the dft results, I think it's best to look at the inverse transformation. You multiply coefficient k with

 exp(i*2*pi*k/N*n)

which can be interpreted to be a cosine with Euler's Formula. So each coefficient gets multiplied by a sine of a certain frequency.

Good luck ;)

Share:
12,216
Derk
Author by

Derk

Updated on June 15, 2022

Comments

  • Derk
    Derk almost 2 years

    For a homework assignment I have to design a simple bandpass filter in Matlab that filters out everything between 250Hz and 1000 Hz. What I did so far: - using the 'enframe' function to create half overlapping windows with 512 samples each. On the windows I apply the hann window function. - On each window I apply an fft. After this I reconstruct the original signal with the function ifft, that all goes well.

    But the problem is how I have to interpret the result of the fft function and how to filter out a frequency band.

  • Derk
    Derk over 12 years
    The wav files have a sampling rate of 16000Hz according to the Nyquist theorem. The problem is that I don't fully understand the definition of the DFT