There are a few different ways to apply a Butterworth filter to data using MATLAB. Here's a method I often use:
sampleRate = #; % Hz cutOffFreq = #; % Hz filterOrder = #; % Filter order (e.g., 2 for a second-order Butterworth filter) [b, a] = butter(filterOrder, cutOffFreq/(sampleRate/2)); % Generate filter coefficients filteredData = filtfilt(b, a, inputData); % Apply filter to data using zero-phase filtering
For this code above to work, the Signal Processing Toolbox is required.
Note that the cut-off frequency is divided by half the sample rate (according to the Nyquist sampling theorem, half the sample rate is the maximum frequency that can be represented in discrete data and thus it is this value that the cut-off frequency is normalized relative to). Also note that using filtfilt (rather than the filter function) doubles the effective order of the filter because filtfilt applies it to the data twice (in opposite directions) to remove phase distortion.