View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Butterworth Filters

5.0 | 2 ratings Rate this file 29 Downloads (last 30 days) File Size: 120 KB File ID: #38584 Version: 1.3
image thumbnail

Butterworth Filters


Chad Greene (view profile)


11 Oct 2012 (Updated )

Highpass, lowpass, bandpass, and bandstop Butterworth frequency filters.

| Watch this File

File Information

This set of functions is simply four built-in Matlab functions, repackaged for ease of use (Signal Processing Toolbox is required). If you don't want to go through the rigmarole of designing and implementing a filter with normalized frequencies and so forth every time you filter a signal, this package may be for you. If you are a Matlab pro and an expert in digital signal processing, you will probably not be impressed.

Each function takes the form [filtered_signal,filtb,filta] = bandstop_butterworth(inputsignal,cutoff_freqs,Fs,order)

inputsignal = input time series
cutoff_freqs = filter corner frequencies in the form [f1 f2]
Fs = data sampling frequency
order = order of Butterworth filter

filtered_signal = the filtered time series
filtb, filta = filter numerator and denominator (optional)

  load train
  t = (1:length(y))/Fs;
  y_filt = bandstop_butterworth(y,[800 1000],Fs,4); % cut off between 800 Hz and 1000 Hz

  xlabel('time in seconds')
  box off
  sound(y,Fs) % play original time series
  pause(2) % pause two seconds
  sound(y_filt,Fs) % play filtered time series

  load train
  t = (1:length(y))/Fs;
  [y_filt,filtb,filta] =bandstop_butterworth(y,[800 1000],Fs,4); % cut off between 800 Hz and 1000 Hz
  [h1,f1] = freqz(filtb,filta,256,Fs);

  xlabel('time in seconds')
  box off
  text(0,.1,' time series','units','normalized')

  AX = plotyy(f1,10*log10(abs(h1)),f1,angle(h1),'semilogx');
  set(get(AX(1),'ylabel'),'string','gain (dB)')
  set(get(AX(2),'ylabel'),'string','phase (rad)')
  xlim(AX(1),[min(f1) max(f1)])
  xlim(AX(2),[min(f1) max(f1)])
  text(0,.1,' filter response','units','normalized')
  box off

  [Pxx,f] = pwelch(y,512,256,[],Fs,'onesided');
  [Pxxf,f_f]= pwelch(y_filt,512,256,[],Fs,'onesided');
  hold on
  xlabel('frequency (Hz)')
  ylabel('PSD (dB)')
  xlim([min(f1) max(f1)])
  box off
  legend boxoff


This file inspired Filter1 and Plotpsd.

Required Products Signal Processing Toolbox
MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
29 Apr 2016 sam zhpour

13 Mar 2016 Vinayak Hebbar

I downloaded that file and I don't know where to paste those files..

Comment only
14 Oct 2015 Chad Greene

Chad Greene (view profile)

I have rewritten these filters as a better single function called filter1. The new filter1 function has better error checking and is a bit more user friendly. I recommend using filter1 instead of the filters on this page. Get filter1 here:

Comment only
31 Oct 2013 Paul

Paul (view profile)

12 Oct 2012 Chad Greene

Chad Greene (view profile)

Oh shoot! I forgot about that! Thanks for letting us know, Jan.

Comment only
12 Oct 2012 Jan Simon

Jan Simon (view profile)

You need the Signal Processing Toolbox for the BUTTER command.

Comment only
12 Oct 2012 1.2

Clarified that the signal processing toolbox is required.

12 Oct 2012 1.1

fixed typo in description text.

15 Oct 2012 1.3

Clarified in the text that the Signal Processing Toolbox is required.

Contact us