Sorry for my English, I'm french...
I've got a data file which represent a "many-periodic" signal (voltage on Y-axis and time on X-axis) composed of nearly 10 "peaks". I mean it's a waveform signal where the period evolves in time. Moreover, my signal is not symetric and not "zero-centered".
I would like to display the frequency for each moment of my signal, a kind of "instanteous frequency".
Until now, I detect all the peaks and calculate the time between two consecutive peaks in order to estimate only 9 periods, then 9 frequencies...
I'm looking for a better solution which can give me more frequencies in order to plot it as a fonction of the time.
Frequency is the number of occurrences of a repeating event per unit time. It is also referred to as temporal frequency. The period is the duration of one cycle in a repeating event, so the period is the reciprocal of the frequency
So, from this point of view.......you do not have a frequency, so how do you want to get any information about this?
I think, what you want to see is the time difference between the peaks.....and your approach seems to solve that already.
Ok, It wasn't clear...
First, here is my data chart, voltage as a fonction of time:
the period (then the frequency) looks like constant but it doesn't!! i would like to estimate the variation of the frequency, ploting it as a fonction of time.
For example, we can fit the signal with a function as A(x) + B(x)sin(C(x)) where A(x), B(x) and C(x) may be polynomials.
C(x) should represent the frequency as a fonction of time (Known up to a 2pi factor of proportionality). But I'm not sure, and I don't know how to do...
Is it clearer?
The problem in your task is that you have not really sufficient periods for a single frequency analysis. You could try to simplify it like you are more or less already doing: Determine the time it takes from one maximum to the next (or minimum, regarding your task) and take this is "one period(s)". So the frequency is 1/period(s).
I think the biggest issue occurs in the clear identification of those maxima/minima. Given your screenshot, you have to either introduce "deadbands" or appropriate hysteresis for the determination of those points......
Please note, that this approach is a guess of the frequency at best because without proper continuity, the determination of a frequency is (mathematically spoken) not possible.
As Norbert pointed out "frequency" is not well defined for signals which vary non-periodically. You can define "instantaneous frequency" any way you chose for your signal, but you should be very clear about what assumptions you make in doing so.
Since your signal appears to be fairly clean (high signal to noise ratio), finding successive maxima and minima and the spacing between them is probably the best way.
The Lev-Mar curve fitting routines work well to fit the frequency of a sine wave if you use less than one complete cycle of the wave. It works poorly for three or more cycles. Fourier transform techniques work best when you have about 10 or more cycles at the same frequency. Fitting to your equation "
If you wish to use a zero crossing technique, find the maxima and minima as above. Then locate the midpoint (amplitude) between each maximum, minimum and minimum, maximum pair. Use the timing of those midpoints as the "zero-crossings." There will be some error, but due to the nature of your signal any frequency estimate will contain some error. For the image you posted the first midpoint would be at about 1.65 (y-axis) and 450 (x-axis). The second one would be at about 1.2 and 800. The estimate for the period of the half cycle containing the first minimum would be 800-450 = 350. The estimated frequency for a full period based on that half period is 1/(2*350) = 0.00143.
Is there some reason you are not taking the Fourier Transform (FFT) of the data and using the outputs as the coefficients? There will be some DC term...for the average offset, there will be some harmonics off the step changes in the DC term ... and there will be a very large peak (or two depending on how the frequencies fall between samples) for the sinusodial looking part of the signal...
The original poster indicated that the frequency is changing over the duration of the signal and that a cycle by cycle measurement is desired. At least that is the way I read it. Fourier transform methods do not work well with rapidly changing frequencies. The FFT need about 10 cycles at constant frequency for good results.
I would have thought that you could take the FFT of the signal every 500 samples or so and that would give you good enough resolution for one cycle of the sinusoid.
That would divide the frequency domain up into 1/250 of the sample frequency as an increment in frequency. Then, move the window...
The signal can be windowed as well....
Guess I don't understand the problem.
Mathematically the Fourier transform is defined by an integral over all time. This has the effect of taking a long term average over the component at a particular frequency. If the signal only has a component at that frequency for a very short time, the magnitude of that component in the output of the transform is small. If the signal segment is not exactly an integral number of cycles, the truncation introduces additional components which look like harmonics and may also contribute a DC component.
The joys of using sampled and truncated data to represent a signal which is modeled as infinitely continuous!