Python Forum
Convert signal/curve to steps
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert signal/curve to steps
#1
Question 
Hello everyone,

I searched long time on this matter I couldn't figure out a reliable way to proceed.
I have a signal for example attached file.

The black curve is the original signal, I want to convert it to something similar to the red signal ?
Then I would add a parameter to define the minimum "averaging length" i believe.

I am surprise that there is no such function already defined. If you have any suggestion there are welcome.

Thanks in advance.

Attached Files

Thumbnail(s)
   
Reply
#2
Have a look at scipy.stats.binned_statistic() and related functions perhaps.
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
@Gribouillis : thank you for your response, but I couldn't figure out how this function could do what I need.
Reply
#4
Can you describe what the image is supposed to mean? Why are the red lines drawn where they are? Why aren't there a series of steps in the big peak? Why is the red line drawn where it is in the peak? Why are there 2 read lines right of the peak instead of 1?

Gribouillis might be onto something. Bin the data and then use some heuristic to combine bins until all bins are wider than some minimum width. May be as simple as:
while minimum width bin < minimum allowable bin:
   combine two most similar adjacent bins
Reply
#5
@deanhystad thanks for your contribution.
The red lines are supposed to represent the "average" level of the signal for different phases.
A phase should last a minimum dx (the minimum allowable bin), then I believe I should add a parameter to define the min dy from bin to bin to consider a new phase.

For example in attached figure, for the time being I used np.digitize to get the orange curve, then 2 loops to get the number of phases and then filter number of phases not long enough (in green). Still I believe I need to add a temporary variable to create a new phase if several sucessive bins are smaller than the minimum bin (so the last part should be counted as a separate phase). Then once I have all phases, I will take the average of it.

This is a bit DIY, I expected to have such function ready in python libraries...

Attached Files

Thumbnail(s)
   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Gaussian Curve Fit using Scipy ODR 83dons 1 4,937 Feb-19-2021, 10:24 PM
Last Post: Tuxedo
  curve fitting matlotlib scipy Cjstarling 2 3,273 Sep-15-2020, 02:56 PM
Last Post: Cjstarling
  Pipelines for different processing steps dervast 3 3,024 Jun-06-2020, 11:01 PM
Last Post: scidam
  Stretching a curve and modifying it IlikePi 0 2,474 Feb-01-2020, 03:41 PM
Last Post: IlikePi
  Reading time steps from nc file ankurk017 1 3,298 Jul-16-2018, 07:06 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020