0
$\begingroup$

I am only mechanic engineering and I need to filter my acceleration from MEMS mobile phone which has a noise and drifts. Here is my data. Acceleration vs time from an app mobile phone ACCELERATION_VS_TIME.csv. Here is my working program BUTTER_FILTRATION.py. My results (displacement) are on the bottom (the last one curve, drawing).

Meanwhile I took a working example (the Butterworth bandpass filter 1 curve, drawing from the top) and some example data from the Internet referring to this example (2 from the top) which filtering 600 Hz. It works well. Then I load my acceleration vs time (3 from the top). I should make base line correction but I don't know how (4 from the top). In my program there is some trial of base line correction but it not helps. Then I use the Butterworth bandpass filter (5 from the top) which should filtering everything apart from 1.8 Hz. It is enough to pass everything between 1 and 2 Hz. It is my mass spring system which is moving up and down.

enter image description here

I tried many option and one of them is the best but not enough and I don't understand how to set up my filter especially fs - sampling frequency. I put 300 Hz because it gives the best results. My signal lasts 60 s and is sampled every 0.02 s what gives 500 Hz but the results after that I even worst. The 6 from the top is filtered acceleration, 7 from the top is first integration of the acceleration which gives velocity and the last one is the second integration of the velocity which gives displacement but still wrong and drifting - I don't know why.

I tried many filters and many options - nothing gave good results. I tried to set up the same like when I used SeismoSignal - commercial program which filtered my (the same data) very well!

enter image description here

enter image description here

enter image description here

SeismoSignal gaves me velocity and displacement which no drifts...I can't repeat the same in Python. It seems that using filters is not hard thing ....but there must be something I do in wrong way and I don't know what it can be. I am only mechanic engineering. I am not signals specialist. I try to use available resources for my own purposes like ordinary calculator...but it seems that I don't understand some things that for a signals specialist can be obvious and it makes that I have wrong results.

Can I ask for any help?

Regards,

Leszek

P.S I want to say thank you many of you because the talks started and you are trying to help me. Because of my English (I am not a native English speaker) it is hard to explain my problem clearly. That I am going to comment it more.

Please don't lock at the 1 i 2 drawings.....

enter image description here

I put it only to SHOW !!! that Butterworth filter WORKS for specific example and to prove that I can use it inside the Python and programming filters is not big deal. The problem is to understand how to set up ones data and proper use the Butterworth bandpass filter.

That example problem (blue curve signal) is filtered 600 Hz to obtain green one. And that is all !!! The example is available in the Internet

My problem starts from 3. Here is acceleration from MEMS from mobile phone with "g". The (5) should be done base line correction like in SeiSmoSignal. I tried but without success that why I put the same acceleration vs time without changes. The I projected my FILTER. It looks like in SeiSmoSignal but is very sensitive for fs. I put 300 Hz in other cases results are not to accept at all. (6) it is acceleration after filtration. It is peaty quite well but not so accurate like in SeiSmoSignal. (7) first integration of the acceleration which gives velocity and then next integration of velocity giving displacement but still DRIFTING...like included still some noise. Proper result shouls be sinusoidal displacement with max amplitude at the beginning about +/- 3.5 cm. At all! Problem is that I can't repeat it in Python what I obtained in SeiSmoSignal.

I hope it will more clear.

Regards,

...filter has range between 0 to 1 because of course how we know the signal has to be normalised before it is being filtered...

I corrected it. My fault to fast.....I showed yy not yyy (filtered one) but first - in SeismoSignal it gives max. ~ +/- 3.5 - in my case the value is to low....and it doesn't change the displacement drifting. It is like some noise is still present in my filtered signal and then drifting is still active. I think that very important can be "base line correction" which I have in my program but it seems not to change anything or give even worst result (I put the last one picture with "my base line correction") and I think it is not quite good procedure. (You can try yourself uncoment yy = yy - rubberband(xx, yy)). Then second could be some other setting the filter like fs=300 Hz. This is the problem that I don't understand to much .... something works but it is not the same like in SeismoSignal.

enter image description here

...and SeismoSignal doesn't behave like that. Without "base line correction" result are bad. It must have "base line correction. Here in my program without "base line correction" acceleration is reaching +/- 2.5 when in SeismoSignal not. SeismoSignal needs "baseline correction then filter gives +/- 3.5. Here with or without "base line correction" filter gives +/- 2.5 and "base line correction" only makes displacement worse.

$\endgroup$
14
  • $\begingroup$ oh dear. i am looking at this, but right now i don't understand where acceleration and such is endemic to the butterworth BPF. i think i understand the first two figures. $\endgroup$ – robert bristow-johnson Oct 5 '20 at 23:47
  • $\begingroup$ okay, are you using the 600 Hz BPF as a prototype and you mapped it to an identical Butterworth BPF at 1.8 Hz? is that correct? then you're passing an acceleration curve that appears to be a damped sinusoid at about 1.8 Hz through this. i am still unsure of the rest of the problem but i am reading it again. $\endgroup$ – robert bristow-johnson Oct 6 '20 at 0:01
  • $\begingroup$ i wonder if it has anything to do with the difference between the 1.8 Hz sinusoid and the most resonant frequency of the 4th-order BPF. And how does the DC component of the acceleration signal (about 10) get passed through this bandpass filter? or should the output of the filter be graphed around zero? because integrating that constant 10 will result in a linear ramp (or baseline) in the velocity curve and i don't see that. $\endgroup$ – robert bristow-johnson Oct 6 '20 at 0:17
  • $\begingroup$ and there is something suspect with the first half-second of the velocity curve that was integrated from the acceleration curve. for the input it's a flat line with no detectable sinusoid and the output shows a ramping-up sinusoid during that time. that seems odd to me. $\endgroup$ – robert bristow-johnson Oct 6 '20 at 0:30
  • $\begingroup$ I put some more explanations. Maybe it will help. $\endgroup$ – Leszek Flis Oct 6 '20 at 14:18
0
$\begingroup$

The problem has been solved (with help prof. Grzegorz Szwoch greg@sound.eti.pg.gda.pl), in brief:

1. 

    # constant
    dt = 0.002
    fs = 1 / dt
    # read acc vs time
    acc_orig

2.  

    # detrending (baseline correction)
    acc = detrend(acc_orig)

3. 

    # filer

    sos = iirdesign([1, 2], [0.5, 2.5], 1, 20, ftype='butter', output='sos',fs=fs)
    w, h = sosfreqz(sos, 2000, fs=fs)

4.

    # filtration

    acc_filt = sosfiltfilt(sos, acc)

5. 

    # double integration of the filtered signal

    velocity    = integrate.cumtrapz(acc_filt, dx=dt)
    displacement = integrate.cumtrapz(velocity, dx=dt)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.