design a highpass filter in matlab

To design a highpass filter in MATLAB, you can use the designfilt() function. This function allows you to design various types of filters, including highpass filters.

Here is an example code to design a highpass filter with a cutoff frequency of 100 Hz:

main.m
% Define filter specifications
Fs = 1000;           % Sampling frequency
Fpass = 100;         % Passband frequency
Fstop = 50;          % Stopband frequency
Apass = 0.5;         % Passband ripple (dB)
Astop = 50;          % Stopband attenuation (dB)

% Design highpass filter
highpass_filter = designfilt('highpassfir', 'FilterOrder', 50, 'PassbandFrequency', Fpass, ...
    'StopbandFrequency', Fstop, 'PassbandRipple', Apass, 'StopbandAttenuation', Astop, ...
    'SampleRate', Fs);

% Visualize filter response
fvtool(highpass_filter);    % interactive filter visualization tool
582 chars
15 lines

The code above first defines the filter specifications including the sampling frequency, passband frequency, stopband frequency, passband ripple, and stopband attenuation.

Then designfilt() function is used to design a highpass FIR filter with a filter order of 50, a passband frequency of 100 Hz, a stopband frequency of 50 Hz, a passband ripple of 0.5 dB, and a stopband attenuation of 50 dB.

Finally, the frequency response of the filter is visualized using the fvtool() function.

You can modify the specifications in the code to design a highpass filter according to your specific requirements.

gistlibby LogSnag