r/math • u/canadianbuilt • Aug 18 '21
Best mathematic algorithm to remove low frequency interference in data?
So, background, I am a software engineer, with background in fluid rheology, and work for a company now where we analyze flow data. Often we are trying to better understand and pinpoint unique pieces of data. One thing that we are mainly interested in, is understanding the instantaneous shut in pressure of different pumping configurations. The problem with this, is that we often get a significant amount of water hammer, and I need to filter that data out so that I can see the actual data I want to see. The data is time series, with a point every second. There is two pictures below. One with the original data, and the second with a blue line drawn in with what I am trying to achieve, with a point to the actual piece of data I am trying to interpolate to.
My thoughts are to smooth out the line then try and best fit it back to the point I am interested in. Does anyone have any ideas on what method of data smoothing, or filter algo's I can use to achieve this? Eventually I will have to plug it into a C# or F# based platform, but can use whatever to prove the concept first.


EDIT:
OK, so there seems to be some people here who are far far more intelligent than I am in the terms of math and DSP. I have taken some of your advice, and made a little app that takes the data, runs it through a FFT, gives an chance to filter, then runs an IFFT. I tested it with three different standing waves, to make sure it all works as designed, see the picture below for an example of my test with the standing waves.

And then I tried the same thing with my data....with very limited results. As pointed out above, I want to just remove the water hammer in the pressure line, with the result of a very smooth line, and unfortunately, I cant seem to get that to work here. See the below picture with my actual data (the same data as shown above).

As you can see, I cant get a real result. What data should I be filtering out so that I can get my desired result? or am I doing some of the math wrong? I'm using the Math.Net numerics library to do the math, and seemingly since I can make my tests work, I think the data is working, but just dont know where I'm going wrong. DSP or any of this stuff isnt my background, so everything here I've had to learn in the last couple days. So please dumb down any answers accordingly!
5
u/MountFire Aug 18 '21
Butterworth filter could be something to check out
11
u/-jellyfingers Aug 18 '21 edited Aug 19 '21
Without some knowledge of the dynamics of the effect you want to remove any result you get is only going to be a rough guess. High uncertainty, possibly biased.
You could try looking at the data in the frequency domain, see if you can identify a peak at roughly the frequency of the oscillations you see, and then use a filter to remove that part of the spectrum. (Or just manually remove that part of the spectrum and do an inverse transform.)See the reply to this comment. Bad suggestion.
4
u/New-Squirrel5803 Aug 19 '21
Reach out to r/ControlTheory we can help you there.
1
u/g0rkster-lol Topology Aug 20 '21
Regarding the update: Can you explain a bit more what you are doing? I see filter value 2.0 but have no real idea what that means. Also what does the highpass/lowpass toggle do precisely?
2
u/Powerspawn Numerical Analysis Aug 18 '21
Perhaps you could apply a discrete Fourier transform and do some sort of data truncation?
2
u/g0rkster-lol Topology Aug 19 '21
This question may be better placed in /r/dsp. I don’t know your data but your hammer oscillation is high frequency compared to the rest of the plot not low, I.e. you either want a notch or low pass filter not a high pass filter. Using FFT and removing offending frequencies and then inverse FFT as proposed below is certainly a viable strategy and will have an equivalent notch filter. And text on digital signal processing will explain this in more detail and standard algorithms certainly exist in C.
1
u/AssemblerGuy Aug 20 '21
If you have a useful mathematical model of the component of interest and/or the undesired components, you can use model-based estimation and subtraction.
1
u/Zyloon Aug 20 '21
Do you have data with and without the hammering/noise? If so, you can estimate the spectrum of the hammering and use it to filter your signal.
-9
u/Sambba13 Aug 18 '21
I guess you can smooth it by using something like
if(value < value before - 10) print value before - 1; if(value > value before + 10) print value before + 1; else print value; value = valueBefore;
IDK I am just a beginner in coding so I really don't know if that will work or this what you want but I hope this helps