Here we will consider filtering time series in the frequency domain.
To do this we need first apply discrete Fourier transform (DFT) to the input signal, then multiply the signal by filter coefficients
and then compute the inverse DFT to get back to time domain. Perl has module Math::FFT that does Fourier Transform and inverse Fourier Transform using fast Fourier transform algorithm.
We will use this module which can be found on the CPAN.
We will implement 3 types of filters:
low-pass filter, high-pass filter, band-pass filter.
A low-pass filter passes low frequency components in the signal and blocks the high frequency signal compomnents.
A high-pass filter passes high frequency components in the signal and blocks the low frequency signal components.
And a band-pass filter passes only the specified frequency.
The input to our filter function is the frequency that divides the signal components in two parts - the one that go through the filter and the one that
does not go through. This frequency is called cutoff frequency.
Another input to the filter function is the width of the filter.
The link to perl source code is provided below.
The filtering functions will be very useful for preparing data for input to neural net. For example in stock data forecasting we can divide
signal to low-pass and high-pass signal components and then input to neural net.