# How can I calculate the period of this signal?

Status
Not open for further replies.

#### m_eh_62

##### Member level 2
I want to calculate the peiod of this signal

the sampling frequency is 369hz?
how can i calculate it's period?

#### salam2000

##### Member level 3
get FFT from this signal, Then the maximum amplitude is period, also you can use from pwelch in Matlab and set your sampling frequency in it to find max of it.

#### scintillatingstuffs

##### Junior Member level 3
It is best if u can form an appropriate idea by taking the data tip marker from matlab, find the separation between 2 points tat are similar and divide it by 369 Hz!!!

#### m_eh_62

##### Member level 2
what is the relation between getting FFT from a signal and obtain the period of the signal???? 8O 8O 8O
are you sure?
and how can pwelch canhelp me?could you explain it?
thanks.

#### rakesh_vnit

##### Member level 3
hey...
the period of the signal is just the inverse of the freq of the signal. so, by takin the fft u would get the freq domain description of the signal from which u can find the freq of ur signal. now by takin the inverse of it u will come out wid the period of u signal...
why were u so amazed abt that idea?????

#### m_eh_62

##### Member level 2
rakesh_vnit said:
hey...
the period of the signal is just the inverse of the freq of the signal. so, by takin the fft u would get the freq domain description of the signal from which u can find the freq of ur signal. now by takin the inverse of it u will come out wid the period of u signal...
why were u so amazed abt that idea?????

you say :" by takin the inverse of it u will come out wid the period of u signal..."

you can examine your idea:

>> t=linspace(-pi,pi,1000);
>> x=cos(2*pi*t);
>> X=fft(x);t1=ifft(X);max(abs(t1))

ans =

1.0000

that's right because it's period is: 2π/2π=1

but it dose not work for this :

x=cos(2*pi*10*t);
>> X=fft(x);t1=ifft(X);max(abs(t1))

ans =

1.0000

the period of cos(2*π*10*t) is :
2π/20π =0.1

and it's wrong!!!!!

on the other hand by taking ifft we only go from frequency domain of signal to the time domain not any thing.
it does'nt get the period of the signal
the above example is a breaking example.isn't it?

#### rakesh_vnit

##### Member level 3
hey ...
u got me wrong....

wat u have to find is not fft and ifft of that again....
wat u have to do is the find fft...wat will be the o/p, the freq domain of the signal...now find the point at which this signal is havin the max value....
now here u will have that value to be some interger as u take discrete signal. so, convert it into the analog freq with samplin freq that u might have taken for the signal...
now...the freq that u have got now is the freq of the signal u want(analog).....so the inverse of this would give u the period of this...
i think i am clear now....in case of further doubt i welcome it....try this one and check it...
n chill out...this is just a discussion

#### Sal

##### Full Member level 4
Hi

first of all, I am not sure if your signal is periodic, is it?

Assuming that it is the noisy version of a periodic signal whose period is limited by the high amplitude spikes in your signal, you just need to find the difference between two adjacent spikes, from your figure, it is about 300 samples, each sample is ts = 1/369 sec.

Therefore, the sought period 300/369 is about 0.8 sec

good luck

Sal

#### m_eh_62

##### Member level 2
rakesh_vnit said:
hey ...
u got me wrong....

wat u have to find is not fft and ifft of that again....
wat u have to do is the find fft...wat will be the o/p, the freq domain of the signal...now find the point at which this signal is havin the max value....
now here u will have that value to be some interger as u take discrete signal. so, convert it into the analog freq with samplin freq that u might have taken for the signal...
now...the freq that u have got now is the freq of the signal u want(analog).....so the inverse of this would give u the period of this...
i think i am clear now....in case of further doubt i welcome it....try this one and check it...
n chill out...this is just a discussion

i don't mean you in "wat will be the o/p, the freq domain of the signal... "
please dont use brief marks.

you say I should find the max value in my signal and i get the corresponding index
with this index and i have a discrete signal.then you said :
"convert it into the analog freq with samplin freq that U might have taken for the signal..."
but how?is ther any function in Matlab for this?
the continuance of the subject is clear.
I think you want reconxtruct a new version of signal and by using the max value U want to calculate the period of the signal.
is it right?

Added after 5 minutes:

Sal said:
Hi

first of all, I am not sure if your signal is periodic, is it?

Assuming that it is the noisy version of a periodic signal whose period is limited by the high amplitude spikes in your signal, you just need to find the difference between two adjacent spikes, from your figure, it is about 300 samples, each sample is ts = 1/369 sec.

Therefore, the sought period 300/369 is about 0.8 sec

good luck

Sal

yea
that's right I calculate the period by this method and the period ti be obtain 0.86
but i want to write a m file to calculate it.therfore i need an algorithm.

#### rakesh_vnit

##### Member level 3
so, u want to know how to calculate the analog freq from the digatal freq.
here it is ...when u have the index,say k,(i.e, the x-axis value of the fft at which u get the max value...write an algo of how to find the max of the given value n its correspondin value on x-axis).
now, k/N is the digital freq of it, where N is the total samples of the signal u have taken. use the below formula to get the analog freq.

k/N = F/Fs....
where F=the analog freq of the signal u want to find.
Fs= samplin freq of the signal.

so, wid this u would get the analog freq. n the (1/F) would give u the period of the signal...

i think this explanation is good enough for u to write ur own algo...

#### echo47

##### Advanced Member level 5
Your ECG signal has very low amplitude at the fundamental frequency, so a plain FFT would give you poor info.

It would be better to apply some sort of non-linear filter to it first, such as computing fft(ECG_1 > 0.5) instead of fft(ECG_1).

This example shows the first strong spectral peak at about 1.23 Hz. Zoom in to see it:
Code:
clear;
load -mat ecg1.mat;
N = size(ECG_1,1);          % number of samples
fs = 369.0;                 % sample rate
t = (0 : N-1) / fs;         % sample times
subplot(2,1,1); plot(t,ECG_1); xlabel('Seconds');
h = fft(ECG_1 > 0.5);       % tricky threshold value
% Discard duplicate upper half. Scale frequency and amplitude.
freq = fs * (0 : N/2) / N;
subplot(2,1,2); plot(freq, 2 / N * abs(h(1 : N / 2 + 1))); xlabel('Hertz');
Or use a time-domain approach as Sal suggested.

Both methods are probably sensitive to changes in the waveform, so you should try many different waveforms and design some sort of adaptive algorithm.

#### m_eh_62

##### Member level 2
rakesh_vnit said:
so, u want to know how to calculate the analog freq from the digatal freq.
here it is ...when u have the index,say k,(i.e, the x-axis value of the fft at which u get the max value...write an algo of how to find the max of the given value n its correspondin value on x-axis).
now, k/N is the digital freq of it, where N is the total samples of the signal u have taken. use the below formula to get the analog freq.

k/N = F/Fs....
where F=the analog freq of the signal u want to find.
Fs= samplin freq of the signal.

so, wid this u would get the analog freq. n the (1/F) would give u the period of the signal...

i think this explanation is good enough for u to write ur own algo...

dear rakesh_vint

suppose this is my signal and forget the main ECG signal

>> t=linspace(-1,1,1000);x=cos(20*pi*t);plot(abs((fft(x))))

the sampling frequency is:1000/2=500hz
maximum FFT value index is:981
by using your formula:

981/1000=F/500
then F equal 490.5 and the period is 1/490.5=0.002
it is not true.
I want to calculte the period of this signal
what is my wrong?
the period of this signal is 2π/20π=0.1
isn't it?

#### salam2000

##### Member level 3
the sampling frequency is:1000/2=500hz
maximum FFT value index is:981
by using your formula:

981/1000=F/500
then F equal 490.5 and the period is 1/490.5=0.002
it is not true.
I want to calculte the period of this signal
what is my wrong?

your wrong is hear:
the left peak is that you should consider, it is on 21. then 2/(21-1)=0.1.
the right peak is concluded from the discrete version of you signal. because it isn't continues this part is created symmetry and increase its frequency with increase the number of points. also you can get 2/(1000-981)=0.1. also you can use fftshift in Matlab.

that's right I calculate the period by this method and the period ti be obtain 0.86
but i want to write a m file to calculate it.therfore i need an algorithm.

you can set a threshold and separate the peaks.

#### echo47

##### Advanced Member level 5
Remember that the right half of an FFT contains the signal's negative frequency components. Your ECG signal is real, not complex, so the right-half is simply a mirror image of the left-half. You can ignore the right-half.

The FFT's frequency points are spaced fs/N, where fs is the sample rate and N is the number of samples. Your N is 7200, so the FFT's left-half points 1 through 3600 represent frequencies 0*fs/N through 3599*fs/N. You can ignore the right-half points 3601 through 7200.

By the way, you may get better frequency accuracy by using Sal's method. Even better, measure the time from the first cardiac pulse to the last pulse, and divide by the number of pulses.

#### m_eh_62

##### Member level 2
salam2000 said:
the sampling frequency is:1000/2=500hz
maximum FFT value index is:981
by using your formula:

981/1000=F/500
then F equal 490.5 and the period is 1/490.5=0.002
it is not true.
I want to calculte the period of this signal
what is my wrong?

your wrong is hear:
the left peak is that you should consider, it is on 21. then 2/(21-1)=0.1.
the right peak is concluded from the discrete version of you signal. because it isn't continues this part is created symmetry and increase its frequency with increase the number of points. also you can get 2/(1000-981)=0.1. also you can use fftshift in Matlab.

that's right I calculate the period by this method and the period ti be obtain 0.86
but i want to write a m file to calculate it.therfore i need an algorithm.

you can set a threshold and separate the peaks.

let's do step by step:
you use this formula:
K/N=F/Fs
N=1000 and Fs=500 we want to find F and then the period is 1/F.
OK?
but i dont undestand for K why U use 21-1
or 1000-981

my left point index is not 21?
so why you subtract 1 by it. (21-1)?
you say i should use the left point indext because the right half of an FFT contains the signal's negative frequency components.

but why you subtract it?
i'm confused please help me? 8O
and you mentioned i can set a threshold to seprate it
the value of the threshold is important if it change the maximum value indext will be change.Rigth?i think using threshold is not need the maximum indext value is
clear
for example for this signal from the above Pic it's value is 3 and the other indext value is 999.
thus using threshold is not nedd.Right?

Added after 17 minutes:

the last plot is for cos(2πt) not for cos(20πt) but it dose'nt important I dont know for cos(20πt) FFT plot why you (21-1)?

#### m_eh_62

##### Member level 2
Finally i see the subject
i use this command:
t=linspace(-1,1,1000);x=cos(2*pi*t);

by using linspace(-1,1,1000) i divide the x-axis to 1000 point and the intreval of each two point is 0.002 then if i want to find each indext's time I should do:
t_1=-1
t_2=-1+0.002
t_3=-1+2*(0.002)
t_4=-1+3*(0.002)
.
.
.
t_n=-1+(n-1)*(0.002)

similar this if i want find any indext correspondinf frequency :
i will get thjis relation:

f_n=((n-1)/N)*Fs

thats right
thanks every body to guidence me.

but there is an other question we know that the signal energy is concentrate at a frequency by using the energy of the signal how can i find the period?

>> t=linspace(-1,1,1000);x=cos(20*pi*t);
subplot(211);plot(abs((fft(x))));subplot(212);plot(abs(fft(x.^2)))

by Energy plot how can i find the period?

#### rakesh_vnit

##### Member level 3
hey..
i think already ppl have ans. the question that u put to me. so, i am not takin the pain i=of ans it again...the neg. freq part comin on the right hand side on the plot for the fft unction in matlab.

n as i see u have lot of questions....
abt the question why use (k-1) i.e, 21-1 in ur case, thts 'coz matlab stores it values in an array from 1 to N n not from 0 to N-1...which is actually the way it shold be accordin to the formula....refer opphenham n schafer, it will give u a good ref to the formula n its derivation.....

i think that this will ans ur question....
n abt the threshold i didnt understand the statement that u made....even i am waitin for a reply by somebody....!!!

#### salam2000

##### Member level 3
Drar active sudent,
why you are in hurry....
-1 is beacase you plot your curve from 1:1000 instead plot from 0:999
I think it's better you have a glance to Oppenheim book before ask question and become hopeless

#### m_eh_62

##### Member level 2
salam2000 said:
Drar active sudent,
why you are in hurry....
-1 is beacase you plot your curve from 1:1000 instead plot from 0:999
I think it's better you have a glance to Oppenheim book before ask question and become hopeless

I 'm in hurry because i have less time to finished my project
I know i can read oppenheim and get my reply buti haven't any time
thus i create this topic
I get my reply but
a question is still contiue if anyone help me this will finished
please see this plot

x(t)=cos(20πt)
the firat plot is FFT of cos(20πt) and the other one is the Energy of it(FFT(x²))
by using FFT plot i get the period :
2/(21-1)=0.1 and it's right
in FFT the axis(x-axis)is from 0-1000
0 ≈ 0 HZ
1000 ≈ fs
21 ≈ 10Hz
by this realation I find period equal 0.1

but in FFT energy( the second plot) how can I find the period? :roll:
more accurate:
in FFT energy plot; what dose the axis correspond?

0 ≈ 0Hz
1000 ≈ ?fs

i think 1000 ≈2fs becuse when x(t) multiply by x(t) the bandwidth of signal is twice
but this realation is wrong.

if 1000 ≈ fs/2 then indext 41 will be (41-1) ≈10Hz and this will be true

is it right?why?i think 1000 should be equivalent 2fs not fs/2. (in FFT plot energy)

do you understand me?

#### echo47

##### Advanced Member level 5
If you square a sinewave, you get a DC-offset sinewave at twice the frequency.

Power and energy calculations should be done after calculating the FFT, not before.

Status
Not open for further replies.