Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply a low-pass or high-pass filter to an array in Matlab?

Is there an easy way to apply a low-pass or high-pass filter to an array in MATLAB? I'm a bit overwhelmed by MATLAB's power (or the complexity of mathematics?) and need an easy function or some guidance as I couldn't figure it out from the documentation or searching the web.

like image 331
Christian Avatar asked Nov 23 '09 14:11

Christian


People also ask

What is high pass filter in Matlab?

Design high-pass filters using MATLAB A high-pass filter attenuates signals below a cutoff frequency (the stopband) and allows signals above the cutoff frequency (the passband). The amount of attenuation depends on the design of the filter.

How do you filter a signal in the frequency domain in Matlab?

The frequency-domain filtering is efficient when the impulse response is very long. You can specify the filter coefficients directly in the frequency domain by setting NumeratorDomain to 'Frequency' . This object uses the overlap-save and overlap-add methods to perform the frequency-domain filtering.


2 Answers

Look at the filter function.

If you just need a 1-pole low-pass filter, it's

xfilt = filter(a, [1 a-1], x); 

where a = T/τ, T = the time between samples, and τ (tau) is the filter time constant.

Here's the corresponding high-pass filter:

xfilt = filter([1-a a-1],[1 a-1], x); 

If you need to design a filter, and have a license for the Signal Processing Toolbox, there's a bunch of functions, look at fvtool and fdatool.

like image 151
Jason S Avatar answered Sep 20 '22 01:09

Jason S


You can design a lowpass Butterworth filter in runtime, using butter() function, and then apply that to the signal.

fc = 300; % Cut off frequency fs = 1000; % Sampling rate  [b,a] = butter(6,fc/(fs/2)); % Butterworth filter of order 6 x = filter(b,a,signal); % Will be the filtered signal 

Highpass and bandpass filters are also possible with this method. See https://www.mathworks.com/help/signal/ref/butter.html

like image 36
Ahmad Avatar answered Sep 21 '22 01:09

Ahmad