Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to find the period of a sine like plot?

Subject: How to find the period of a sine like plot?

From: zhengquan

Date: 2 May, 2008 21:08:00

Message: 1 of 15

Hello,
I have produced a sine like plot, now I can only manually find the
rough
period of the plot. I use data cursor to find two maximums and then
count the number of periods between this two maximums and do the
calculation.

I hope there are ways to automate the process because the plots I need
to
analyse are numerous.

Thanks!

Zhengquan

Subject: How to find the period of a sine like plot?

From: dpb

Date: 2 May, 2008 21:12:41

Message: 2 of 15

zhengquan wrote:
> Hello,
> I have produced a sine like plot, now I can only manually find the
> rough
> period of the plot. I use data cursor to find two maximums and then
> count the number of periods between this two maximums and do the
> calculation.
>
> I hope there are ways to automate the process because the plots I need
> to
> analyse are numerous.

If the data aren't too noisy, simply finding and counting zero-crossings
may be sufficient. More specifics of what data looks like, maybe?

--

Subject: How to find the period of a sine like plot?

From: zhengquan

Date: 2 May, 2008 21:28:40

Message: 3 of 15

On May 2, 4:12 pm, dpb <n...@non.net> wrote:
> zhengquan wrote:
> > Hello,
> > I have produced a sine like plot, now I can only manually find the
> > rough
> > period of the plot. I use data cursor to find two maximums and then
> > count the number of periods between this two maximums and do the
> > calculation.
>
> > I hope there are ways to automate the process because the plots I need
> > to
> > analyse are numerous.
>
> If the data aren't too noisy, simply finding and counting zero-crossings
> may be sufficient. More specifics of what data looks like, maybe?
>
> --

It is not noisy, only the amplitude is decaying very slightly. the
first
column of the data is time steps, the second column is the amplitude
of
the sine function on those time steps. another problem is that the
data
is too huge, there are milllions of lines in the file. I am thinking
of loading
one in 10 points in to matlab to plot the file. Is there any functions
to do this?

Thanks.
Zhengquan

Subject: How to find the period of a sine like plot?

From: dpb

Date: 2 May, 2008 21:57:59

Message: 4 of 15

zhengquan wrote:
> On May 2, 4:12 pm, dpb <n...@non.net> wrote:
...
>> If the data aren't too noisy, simply finding and counting zero-crossings
>> may be sufficient. More specifics of what data looks like, maybe?
...
> It is not noisy, only the amplitude is decaying very slightly. ...

Then the idea of finding the zero crossings (assuming the signal was AC
coupled; if not, subtract the mean) should work just fine.

...
> is too huge, there are milllions of lines in the file. I am thinking
> of loading
> one in 10 points in to matlab to plot the file. Is there any functions
> to do this?

How _many_ millions? Are they (I assume from this) ASCII files? Could
they be obtained as unformatted data files instead?

It would be possible to read every tenth line if its an ASCII file,
sure, but it will probably be slower than simply "sucking up" as much of
the file as you can in memory, processing that section, then the rest.

Or, if you do need the entire time-length, reading in a sizable chunk,
decimate in memory and then concatenate a new chunk might be more effective.

--

Subject: How to find the period of a sine like plot?

From: zhengquan

Date: 2 May, 2008 22:11:31

Message: 5 of 15

On May 2, 4:57 pm, dpb <n...@non.net> wrote:
> zhengquan wrote:
> > On May 2, 4:12 pm, dpb <n...@non.net> wrote:
> ...
> >> If the data aren't too noisy, simply finding and counting zero-crossings
> >> may be sufficient. More specifics of what data looks like, maybe?
> ...
> > It is not noisy, only the amplitude is decaying very slightly. ...
>
> Then the idea of finding the zero crossings (assuming the signal was AC
> coupled; if not, subtract the mean) should work just fine.
>
> ...
>
> > is too huge, there are milllions of lines in the file. I am thinking
> > of loading
> > one in 10 points in to matlab to plot the file. Is there any functions
> > to do this?
>
> How _many_ millions? Are they (I assume from this) ASCII files? Could
> they be obtained as unformatted data files instead?
>
> It would be possible to read every tenth line if its an ASCII file,
> sure, but it will probably be slower than simply "sucking up" as much of
> the file as you can in memory, processing that section, then the rest.
>
> Or, if you do need the entire time-length, reading in a sizable chunk,
> decimate in memory and then concatenate a new chunk might be more effective.
>
> --

They are indeed ascii files tens of millions. Thanks, I will google
the rest.

Zhengquan

Subject: How to find the period of a sine like plot?

From: dpb

Date: 2 May, 2008 23:17:09

Message: 6 of 15

zhengquan wrote:
...
>> How _many_ millions? Are they (I assume from this) ASCII files? Could
>> they be obtained as unformatted data files instead?
>>
>> It would be possible to read every tenth line if its an ASCII file,
>> sure, but it will probably be slower than simply "sucking up" as much of
>> the file as you can in memory, processing that section, then the rest.
>>
>> Or, if you do need the entire time-length, reading in a sizable chunk,
>> decimate in memory and then concatenate a new chunk might be more effective.
...
> They are indeed ascii files tens of millions. Thanks, I will google
> the rest.

What "rest" needs googling?

--

Subject: How to find the period of a sine like plot?

From: zhengquan

Date: 3 May, 2008 01:08:28

Message: 7 of 15

On May 2, 6:17 pm, dpb <n...@non.net> wrote:
> zhengquan wrote:
>
> ...
>
> >> How _many_ millions? Are they (I assume from this) ASCII files? Could
> >> they be obtained as unformatted data files instead?
>
> >> It would be possible to read every tenth line if its an ASCII file,
> >> sure, but it will probably be slower than simply "sucking up" as much of
> >> the file as you can in memory, processing that section, then the rest.
>
> >> Or, if you do need the entire time-length, reading in a sizable chunk,
> >> decimate in memory and then concatenate a new chunk might be more effective.
> ...
> > They are indeed ascii files tens of millions. Thanks, I will google
> > the rest.
>
> What "rest" needs googling?
>
> --

In fact I do not quite understand how to find the zero crossing and
how to reading in chunks...

Subject: How to find the period of a sine like plot?

From: dpb

Date: 3 May, 2008 02:04:28

Message: 8 of 15

zhengquan wrote:
> On May 2, 6:17 pm, dpb <n...@non.net> wrote:
>> zhengquan wrote:
>>
>> ...
>>
>> ...
>>> They are indeed ascii files tens of millions. Thanks, I will google
>>> the rest.
>> What "rest" needs googling?
>>
> In fact I do not quite understand how to find the zero crossing and
> how to reading in chunks...

One way to read "chunks" is textread() w/ the optional "N" parameter.
Try

doc textread

I'm stuck in a time warp w/ R12 of Matlab, so there have been additional
  specialty functions since that may be of some help as well.

doc iofun

will give you an overview of all current capabilities of your version.

Zero-crossings w/o noise are in principle found w/ something like for a
series y

y(y>0) = 1;
y(y<0) = -1;
xings = find(diff(y));

Sorry, have to run or would try to write a brief test case, but
hopefully that gives the idea...and, of course, there are many
permutations on the basic premise.

--

Subject: How to find the period of a sine like plot?

From: zhengquan

Date: 3 May, 2008 02:17:19

Message: 9 of 15

On May 2, 9:04 pm, dpb <n...@non.net> wrote:
> zhengquan wrote:
> > On May 2, 6:17 pm, dpb <n...@non.net> wrote:
> >> zhengquan wrote:
>
> >> ...
>
> >> ...
> >>> They are indeed ascii files tens of millions. Thanks, I will google
> >>> the rest.
> >> What "rest" needs googling?
>
> > In fact I do not quite understand how to find the zero crossing and
> > how to reading in chunks...
>
> One way to read "chunks" is textread() w/ the optional "N" parameter.
> Try
>
> doc textread
>
> I'm stuck in a time warp w/ R12 of Matlab, so there have been additional
> specialty functions since that may be of some help as well.
>
> doc iofun
>
> will give you an overview of all current capabilities of your version.
>
> Zero-crossings w/o noise are in principle found w/ something like for a
> series y
>
> y(y>0) = 1;
> y(y<0) = -1;
> xings = find(diff(y));
>
> Sorry, have to run or would try to write a brief test case, but
> hopefully that gives the idea...and, of course, there are many
> permutations on the basic premise.
>
> --

Thank you very much, the method is smart!
Zhengquan

Subject: How to find the period of a sine like plot?

From: Roger Stafford

Date: 3 May, 2008 03:11:04

Message: 10 of 15

zhengquan <zhang.zhengquan@gmail.com> wrote in message <801e2f27-
a631-4aa7-9b60-c93d9654f49e@24g2000hsh.googlegroups.com>...
> Hello,
> I have produced a sine like plot, now I can only manually find the
> rough
> period of the plot. I use data cursor to find two maximums and then
> count the number of periods between this two maximums and do the
> calculation.
>
> I hope there are ways to automate the process because the plots I need
> to analyse are numerous.
>
> Thanks!
>
> Zhengquan
--------------
  If your time steps are all equal, then perhaps performing the fourier
transform with 'fft' and finding the location of the frequency peak would be a
useful method of determining the period. It would probably mean reducing
the total number of steps by some kind of decimation to reduce the
computation task, as you have already discussed.

  If the steps are unequal, you could first use 'interp1' to interpolate the
values to correspond to equal steps and at the same time thereby reduce
their total number as needed.

Roger Stafford

Subject: How to find the period of a sine like plot?

From: aasim Azooz

Date: 5 May, 2008 18:23:03

Message: 11 of 15

zhengquan <zhang.zhengquan@gmail.com> wrote in message
<801e2f27-a631-4aa7-9b60-
c93d9654f49e@24g2000hsh.googlegroups.com>...
> Hello,
> I have produced a sine like plot, now I can only manually
find the
> rough
> period of the plot. I use data cursor to find two
maximums and then
> count the number of periods between this two maximums and
do the
> calculation.
>
> I hope there are ways to automate the process because the
plots I need
> to
> analyse are numerous.
>
> Thanks!
>
> Zhengquan
>
Hi
the best way may be is to use fft. see help fft
Aasim Azooz
Mosul University
Mosul Iraq

Subject: How to find the period of a sine like plot?

From: Roger Stafford

Date: 5 May, 2008 19:01:05

Message: 12 of 15

"aasim Azooz" <aasimazooz@yahoo.com> wrote in message <fvnja6$7vj
$1@fred.mathworks.com>...
> Hi
> the best way may be is to use fft. see help fft
> Aasim Azooz
> Mosul University
> Mosul Iraq
--------
Hello Aasim,

  Zhengquan has stated that the data is received in two columns, with time
values in the first column and amplitudes in the second column. This would
tend to imply that his time intervals may not all be equal. If not, it would surely
invalidate a direct application of 'fft'. The only remedy I can think of is to first
do an interpolation to achieve the effect of equal spacing in the time values for
the interpolated amplitudes and then apply 'fft'.

Roger Stafford

Subject: How to find the period of a sine like plot?

From: zhengquan

Date: 6 May, 2008 03:27:56

Message: 13 of 15

On May 5, 2:01 pm, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> "aasim Azooz" <aasimaz...@yahoo.com> wrote in message <fvnja6$7vj
>
> $...@fred.mathworks.com>...> Hi
> > the best way may be is to use fft. see help fft
> > Aasim Azooz
> > Mosul University
> > Mosul Iraq
>
> --------
> Hello Aasim,
>
> Zhengquan has stated that the data is received in two columns, with time
> values in the first column and amplitudes in the second column. This would
> tend to imply that his time intervals may not all be equal. If not, it would surely
> invalidate a direct application of 'fft'. The only remedy I can think of is to first
> do an interpolation to achieve the effect of equal spacing in the time values for
> the interpolated amplitudes and then apply 'fft'.
>
> Roger Stafford

Thank you guys,
In fact the time steps are equal, I guess for data with a large number
of periods, fft is ok, but for data with only tens of periods, it will
be inaccurate,

Zhengquan

Subject: How to find the period of a sine like plot?

From: Greg Heath

Date: 6 May, 2008 07:55:12

Message: 14 of 15

On May 5, 11:27=A0pm, zhengquan <zhang.zhengq...@gmail.com> wrote:
> On May 5, 2:01 pm, "Roger Stafford"
>
>
>
>
>
> <ellieandrogerxy...@mindspring.com.invalid> wrote:
> > "aasim Azooz" <aasimaz...@yahoo.com> wrote in message <fvnja6$7vj
>
> > $...@fred.mathworks.com>...> Hi
> > > the best way may be is to use fft. see help fft
> > > Aasim Azooz
> > > Mosul University
> > > Mosul Iraq
>
> > --------
> > Hello Aasim,
>
> > =A0 Zhengquan has stated that the data is received in two columns, with =
time
> > values in the first column and amplitudes in the second column. =A0This =
would
> > tend to imply that his time intervals may not all be equal. =A0If not, i=
t would surely
> > invalidate a direct application of 'fft'. =A0The only remedy I can think=
 of is to first
> > do an interpolation to achieve the effect of equal spacing in the time v=
alues for
> > the interpolated amplitudes and then apply 'fft'.
>
> > Roger Stafford
>
> Thank you guys,
> In fact the time steps are equal, I guess for data with a large number
> of periods, fft is ok, but for data with only tens of periods, it will
> be inaccurate,

For noise-free data the uncertainty will be df ~ 1/max(t+dt). What
accuracy are you looking for?

Hope this helps.

Greg

Subject: How to find the period of a sine like plot?

From: NZTideMan

Date: 6 May, 2008 08:25:00

Message: 15 of 15

On May 6, 7:55=A0pm, Greg Heath <he...@alumni.brown.edu> wrote:
> On May 5, 11:27=A0pm, zhengquan <zhang.zhengq...@gmail.com> wrote:
>
>
>
>
>
> > On May 5, 2:01 pm, "Roger Stafford"
>
> > <ellieandrogerxy...@mindspring.com.invalid> wrote:
> > > "aasim Azooz" <aasimaz...@yahoo.com> wrote in message <fvnja6$7vj
>
> > > $...@fred.mathworks.com>...> Hi
> > > > the best way may be is to use fft. see help fft
> > > > Aasim Azooz
> > > > Mosul University
> > > > Mosul Iraq
>
> > > --------
> > > Hello Aasim,
>
> > > =A0 Zhengquan has stated that the data is received in two columns, wit=
h time
> > > values in the first column and amplitudes in the second column. =A0Thi=
s would
> > > tend to imply that his time intervals may not all be equal. =A0If not,=
 it would surely
> > > invalidate a direct application of 'fft'. =A0The only remedy I can thi=
nk of is to first
> > > do an interpolation to achieve the effect of equal spacing in the time=
 values for
> > > the interpolated amplitudes and then apply 'fft'.
>
> > > Roger Stafford
>
> > Thank you guys,
> > In fact the time steps are equal, I guess for data with a large number
> > of periods, fft is ok, but for data with only tens of periods, it will
> > be inaccurate,
>
> For noise-free data the uncertainty will be df ~ 1/max(t+dt). What
> accuracy are you looking for?
>
> Hope this helps.
>
> Greg- Hide quoted text -
>
> - Show quoted text -

If you think about it from a theoretical point of view, the best way
to find the period of a "sine like plot" is to use FFT because it has
sine waves as its basis functions. Whereas, if the function was
periodic, but say cnoidal, then FFT would not give the right period
(in fact, it would give the main period plus many sub harmonics).

I was faced with this problem many years ago when considering seiche
in a large embayment where nonlinear effects were important and
consequently the seiche was cnoidal in shape, rather than cosine. I
found a method called "phase coherence" which uses intersections of a
Poincare map to find periodicity. It proved very succesful for this
job, but I haven't had an application for it since.
The reference is: Lindstrom, J.; Kokko, H.; Ranta, E. 1997: Detecting
periodicity in short and noisy time series data.
OIKOS 78(2): 406-410.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us