create butterworth hpf in matlab

To create a Butterworth High Pass Filter in Matlab, first we need to define the filter specifications, such as cutoff frequency and order. Then we can apply the butter function to design the filter and obtain the filter coefficients. Finally, we can use the filter function to apply the filter to our signal.

Here's the code to create a Butterworth High Pass Filter with a cutoff frequency of 100 Hz and a filter order of 4, assuming a sampling frequency of 1000 Hz:

main.m
% define filter specifications
fc = 100;  % cutoff frequency
fs = 1000;  % sampling frequency
order = 4;  % filter order

% design filter
[b,a] = butter(order, fc/(fs/2), 'high');

% apply filter to signal
filtered_signal = filter(b, a, original_signal);
255 chars
11 lines

In the butter function, the second argument is the normalized cutoff frequency (between 0 and 1, where 1 corresponds to the Nyquist frequency), and the third argument specifies the filter type ('high' for a high pass filter).

Note that the filter coefficients b and a represent the numerator and denominator coefficients of the transfer function for the filter. In the last line of the code, the filter function applies these coefficients to our original signal to obtain the filtered signal.

gistlibby LogSnag