Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numerical differentiation and noise filtering #6

Open
BystrickyK opened this issue Apr 2, 2021 · 2 comments
Open

Numerical differentiation and noise filtering #6

BystrickyK opened this issue Apr 2, 2021 · 2 comments

Comments

@BystrickyK
Copy link
Owner

Numerical differentiation decreases the Signal/Noise Ratio (SNR), and the measured data (position of the cart and the angle of the endulum) must be differentiated twice (to obtain velocity and acceleration). This means there's a need for robust pre-processing filtering step. Normal kernel-based filters probably aren't good enough and I'd like to use FFT, so I'll do part of the filtering by cutting off higher frequencies. The cutoff frequency will be based off of the PSD of each signal. Coincidentally, I found a paper ( https://arxiv.org/abs/2009.01911 ) again from UW, which finds the cutoff frequency similarly and has the same co-author (prof. Kutz) as the SINDy paper.

PSD of the state signals, the 'Filtered' signal is filtered with a non-causal flattop kernel with the size 60. Real measurements will contain only measurements x1 and x2, x3 and x4 must be gotten through differentiating them.
image

@BystrickyK
Copy link
Owner Author

BystrickyK commented Apr 2, 2021

To get the cutoff frequency, I first calculate the PSD of each signal using Welch's method (calculates periodogram, robust against noise but lower frequency resolution). Then I calculate the mean log value of PSD for each signal and multiply it by some number smaller than 1 ( 0.8 in this case). This mean is visualized in the plots as a horizontal dotted line, it's supposed to be above the higher frequency PSD values. The base cutoff frequency is calculated as the highest frequency where the log-mean and the PSD intersects. This base cutoff frequency is then multiplied by some number ( 1.7 in this case), to increase the bandwidth, since the base cutoff results in bad signal reconstruction when the signal's transformed back into time domain. The new cutoff frequency is then used in the filtering phase.
The filtering is done by first transforming the signals to the Fourier domain using FFT and then setting all frequencies higher than the cutoff to 0 and transforming back into time domain.

Finding cutoff frequencies:
welch

Magnitudes of the Fourier coefficients (sqrt of PSD?), kept frequencies are green:
psd

State signals after iFFT:
sig

Zoomed:
sigzoom

Signal reconstruction is pretty good, the noise in this example is pretty heavy, especially for some signals.

@BystrickyK
Copy link
Owner Author

Filtering a signal with 3x weaker noise, zoomed:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant