Method for finding period of complex periodic wave?

Anyone have any good ideas for how to find the period of any arbitrary, complex, periodic wave?
My first idea was to find the highest points in the sample, then find the distances between them, average --and get an approximate period. This actually works quite well --except you must manually adjust the number of these “highest points” to be equal to the number of cycles in the sample… which sort of defeats the purpose… and for very dense, or complex waves may be impossible. Its also vulnerable to false readings in rare instances where a wave returns to the same “high point” multiple times in a cycle… (See attached GH file)

It would seem that a better method would maybe involve translating the entire sample along the X axis and somehow comparing the original wave to this translated wave… looking for the point where they match up again?

But surely there’s a simpler way I’m just not thinking of? Thoughts?

WD

Wave Period Finder.gh (208.1 KB)

Here is how I would find the maximum and minimum in the wave.


Wave Period Finder.gh (215.8 KB)
I haven’t written anything to find the period, but it should involve taking the x values of the deconstructed point and calculate the distance between each point and sum if it isn’t repeating.

Thanks for replying Christoper --but what I’m really after here is a way to find period. Also unless I’m missing something, the method you outlined for finding max and min points is less accurate than the one I used in my original GH definition… as you can see in the attached screen shot (your pts in green, mine in red). Because your method relies on finding the intersection of the interpolated curve with a line that is below the bounding box of the entire curve --it will always give two points below the actual top of the curve --and will not deliver the actual maximal point.

But again, my question is how to find period… And I suspect that there is a better way than using maximal points (as I noted before the wave could return to the exact same “maximal” point multiple time in one period). I strongly suspect that the solution will involve comparing all points (not just looking at maximals).

Thanks again for looking at this!

WD

The reason for looking at points just below the maximum is because the points plotted by the interpolated curve don’t quite have a uniform maximum value.
I might have another look in about 10 hours if there isn’t another answer.

Here’s another approach I came up with --using Galapagos to brute force it…
Basically the approach is as follows:
I have the original set of points along the complex wave --and I have the curve interpolated between those points to make my wave. I’m using a slider to move the entire set of points horizontally along the X axis. Then I’m using “curve closest point” to find the distance from these translated points to the original wave-curve… average the distance values… and then use Galapagos to wiggle the slider controlling the X axis translation, while the “fitness” target for Galapagos tries to minimize that average distance. The result is that Galapagos tries to hone in on the best fit for the points to line up again on the wave.

It works…

But downside is you have to make sure Galapagos doesn’t just hone in on 0 (where you started)… or the second, third… or nth cycle… (which would not tell you the period distance if you dont know what nth) so you have to set the slider limits to book end your target period zone… if that makes sense…

Its actually easier and faster to just manually adjust the slider and look at the average to find the minimal number…

So still not really an automated solution for finding period for any arbitrary wave… but maybe thats just too much to ask :wink:

WD


Galapagos Period Solver.gh (209.7 KB)

1 Like

Finding Period is Signal processing. So you’ll just have to use a Fourrier Transform.


4 Likes

Thanks Laurent, yes I have been looking at the Fourier Transform… but I’m not quite sure how to implement it in this case. In fact part of why I’m looking to find period here is I want to use Grasshopper to play with FT and understand it better…

I already built a simple definition that allows me to add up multiple sine and cosine waves to create complex waves. Next I want to use Fourier analysis to break down complex waves, filter, etc

But as far as I understand it, while the Fourier transform can break down a complex wave into its constituent sine and cosine components --you need to know the period. I don’t see how the FT could be used to derive the period from a data set like I’m starting with here --namely a collection of points along an arbitrary, complex periodic wave. What is required is an algorithmic approach for deriving an approximate period value from this point-data set (essentially pattern recognition).

Please someone chime in if there is a way of using FT in this case that I’m not seeing/understanding here.

A search for “algorithm for finding period of a wave” yields several papers dealing with this problem (mostly in astronomical data sets). For example see:

I’m afraid this paper goes a bit over my head… as my programming skills are very much beginner. But it looks like finding period is perhaps not a trivial problem…?

Let me know if anyone out there has any thoughts on this.

Thanks!

WD

It sounds like you have been looking at Fourier series, not Fouier transforms. A Fourier seties is a summation based on a fundamental frequentcy and harmonics which are integer multiples of the frequency. A Fourier transform is an integral and does not have a fundamental frequency, though it might be thought of as the limiting case of a Fourier series as the fundamental frequency approaches zero. If the input to a Fourier transfrom has a fundamental frequency or frequencies they will show up in the results as a spikes. Remeber that the period is 1/frequency when the frequency is in cycles per time unit.

Then there is the Fast Fourier transform (FFT) which is the efficient application of the Fourier transform to a set of discrete data. Several algorithms are available for the calculation of a FFT.

Similar algos are first developed for the SETI initiative.

Indeed (general case: large amount of data) is a very challenging issue IF relialistic results (i.e. real-time) are required. Is rather impossible to deal with it without code. I have a C# that yields quite decent results (// programming etc ) but I’m far from base and is unclear when I reopen the practice (anyway not this year).

BTW: A classic FT (very slow, mind) article

CFT_12A.pdf (936.3 KB)

1 Like

Hi @PeterFotiadis , I’d be interested and Fourier stuff would be a nice topic for working more with C#. Let me know when you are back. Good journey, where ever you are!

If i understand

Wave Period Finder_test.gh (218.5 KB)

Thanks Seghier,
It’s always interesting to see how others accomplish the same basic result in a definition. I had not thought about using the “group” component along with “box corners” get the bounding box for the points. But this does not address the question --which is more about signal processing and pattern recognition. Your solution, just like mine, requires you to adjust the definition to list the correct number of indexes for a particular wave. And just like mine, it will be thrown off by instances where there are multiple peaks matching the max amplitude in a single cycle… in other words its a very narrow solution that will easily break when tried against a large number of arbitrary waves.

As others had noted some kind of signal processing is required --and it sounds like the Fourier Transform is the most likely bet.

Thanks again for taking the time to think about this!

WD

This is a different way , it find two different periods.

Wave Period Finder_test.gh (218.5 KB)

Maybe you need something like sound analysis

https://www.mq.edu.au/about/about-the-university/faculties-and-departments/medicine-and-health-sciences/departments-and-centres/department-of-linguistics/our-research/phonetics-and-phonology/speech/acoustics/speech-waveforms/the-waveforms-of-speech

David,
Thanks for setting me straight --you are right that I was indeed confusing Fourier series with the Fourier Transform (FT). I’m reading up on the FFT now --and that seems like what I’m looking for.

WD

BTW: The general case (SETI etc etc) is: in a given signal (zillions of data etc) consisting mostly from noise, find possible periodic repetitions meaning “non natural/intelligent” signs blah, blah.

Meaning that for whatever solution you should first make a demo signal generator that has mostly random noise and in some time intervals includes some sort of “pattern” (or many patterns).

Lucky you: today is a no wind day (windsurfing impossible). So for a start get the attached (FFT + some light shed on Complex Pow, Exp and Abs matters)

FFT_EntryLevel_AndComplexThings.gh (185.1 KB)

Some other day we’ll see how to do this (oversimplified for clarity):

3 Likes

Thanks @PeterFotiadis ,
This is really a great and well commented entry to that matter! I really appreciate it and now I’m curious about Roswell! Looks like today is wind again so hang loose and enjoy windsurfing… I’ll have to slack away sails to make a coffee break (26MB).
Jess

BTW: https://stackoverflow.com/questions/10304532/why-does-fft-produce-complex-numbers-instead-of-real-numbers

I find this video very good with the animations:

1 Like

Good aesthetics … but little (almost, that is) else. This is rather more spot on (meaning way harder to get - but no pain == no gain):

1 Like