Lowpass/Bandpass filter design in MATLAB

31,975

Solution 1

I found this question which has so many views and still no good answer.

The following code will do what you need. Since no filter-type is specified, I used a butterworth-filter to demonstrate it. s is the input signal and x is the filtered signal. fs is the sampling rate in Hz.

% Design and apply the lowpass filter
order = 4;
fcut  = 8000;
[b,a] = butter(order,fcut/(fs/2),'low');
x     = filter(b,a,s);


% Design and apply the bandpass filter
order    = 10;
fcutlow  = 1000;
fcuthigh = 2000;
[b,a]    = butter(order,[fcutlow,fcuthigh]/(fs/2), 'bandpass');
x        = filter(b,a,s);

Solution 2

Matlab has fdatool for filter design purposes. Here is the documentation. You can do all these tasks using fdatool and the signal processing toolbox.

Share:
31,975
Çiğdem Özer
Author by

Çiğdem Özer

Hacettepe University/ Electrical and Electronics Engineering / Student

Updated on March 26, 2020

Comments

  • Çiğdem Özer
    Çiğdem Özer about 4 years

    For an analog communication system design in MATLAB firstly I need to do these two design:

    1. Design a low-pass filter [slow]=lowpassfilter(s,fcut,fs) which filters input signal s with cutoff frequency fcut and sampling frequency fs in Hertz.

    2. Design a band-pass filter [sband]=bandpassfilter(s,fcutlow,fcuthigh,fs) which filters input signal s with cutoff frequencies fcutlow and fcuthigh and sampling frequency fs in Hertz.

    Could you please help me?