Matlab Lowpass filter

Discussion in 'Programmer's Corner' started by audio_freq, Apr 7, 2010.

  1. audio_freq

    Thread Starter New Member

    Apr 7, 2010
    I am pulling my hair out trying to write a lowpass filter for audio.
    Being an audio engineer not a programmer this is totally alien to me, I have just about got the hang of using Matlab and now I'm being asked to write code!!

    This is what I've written so far. If any kind person can help I'd be very grateful.
    % Low Pass Filter at 1 kHz.

    cutoff = 1000 / (fs/2);
    % identifies all frequencies below 1000Hz

    below_cutoff = spectrum(1:cutoff);

    changed_spectrum = [below_cutoff;zeros];

    I know it's probably complete garbage (it certainly doesn't work) but am I anywhere near on the right track? I just don't get it.
    Last edited: Apr 7, 2010
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
  3. gizmoman0

    New Member

    Jan 21, 2010
    the easiest implementation would probably be with an finite impulse response (FIR) filter which you will need to research. There are a few things you need to choose before beginning including fsample, n sample points, etc. Basically, you take your array of data that you want to be filtered and multiply it by a set of filter coefficients designed for a low pass filter response. By multipling each data point by each filter coefficient, your output will respond accordingly. I know this is impossible to understand without knowing anything about the topic but do a little reading and you will pick a few things up. here is an example in C code which you can sorta port to matlab or help you understand better.
  4. guitarguy12387

    Active Member

    Apr 10, 2008
    I'd use FDA tool if you're not interested in learning about implementation...

    Depending on your filter, you can generate the code from FDA tool, or you can generate coefficients and use filter() or firpm() or similar... lots of easy options from FDA tool...
  5. guitarguy12387

    Active Member

    Apr 10, 2008
    FYI: generally, simply multiplying in the freq domain is not really the best approach to begin with.