Calculate energy of time domain data
Asked Answered
S

3

5

I am new to digital signal processing. I have the following sensor sample data

Time(milliseconds)            data
------------------    -------------------
0                     0.30865225195884705   
60                    0.14355185627937317   
100                  -0.16846869885921478   
156                  -0.2458019256591797    
198                  -0.19664153456687927
258                   0.27148059010505676   
305                  -0.16949564218521118   
350                  -0.227480947971344 
397                   0.23532353341579437   
458                   0.20740140974521637

Which means at time 0 I have the value 0.30865225195884705 and at time 60 I have the value 0.14355185627937317 and so on.

Data is taken from the sensor at each 10 milliseconds. So, I assume sampling rate should be set to 100 Hz.

I want to calculate the total energy of the time domain signal.

I read that it can be calculated using Parseval's theorem as following:

enter image description here

where X[k] is the DFT of x[n], both of length N.

Any suggestion, how can I calculate the total energy using MATLAB?

Sartorial answered 7/12, 2015 at 12:34 Comment(0)
D
8

Parseval's theorem is useful in linking the time domain energy to the frequency domain. However, if you do not need to perform other computations in the frequency domain, you can compute the energy directly in the time domain with:

Energy = sum(abs(x).^2)

If on the other hand, you need to convert the signal to the frequency domain for other reasons, you may also compute the energy with (as per Parseval's theorem):

Xf = fft(x); % compute the DFT (using the Fast Fourier Transform)
Energy = sum(abs(Xf).^2) / length(Xf); % Get the energy using Parseval's theorem
Dispassion answered 7/12, 2015 at 12:38 Comment(4)
I need to convert it to frequency domainSartorial
Thank you. do I need the Time column of the sensor data?Sartorial
Other than to confirm that you are getting regularly sampled data, and to get the sampling rate (which is required to make the correspondence between DFT bins and the frequency in Hz), not really.Dispassion
This answer does not apply to data with non periodic time stamps, as per the question.Fabriane
F
3

Parseval's theorem and DFT analysis only apply to band-limited data sampled with regular equal spacings (constant sample rate above Fmax*2). Since your time stamps are not regularly spaced, you will need to use them to interpolate a vector of new evenly spaced samples before you can calculate the energy using Parseval's equation. Or you will have to do a numerical integration instead of a simple summation.

Fabriane answered 8/12, 2015 at 1:51 Comment(1)
I realized the problem. Thank you. Is there any method or implementation so that I can create equally spaced data from my sensor data?Sartorial
G
0

Your second question: If you want to interpolate, then find the minimum delta T (in your case 40ms) of your data set, then create a new data set using linear interpolation at each new time sample:

0.000 s

0.040 s => is 2/3 the way in time between the values .3087 and 0.1436

0.080 s ...etc...

0.120 s

0.160 s

0.200 s

0.240 s

0.280 s

0.320 s

0.360 s

0.400 s

0.440 s

But because the data set is so small, linear interpolation is crude at best. Let's say you are bold and spline fit to make it more smooth and higher resolution samples, ... well you'll just corrupt the data.

Gleet answered 20/8, 2021 at 17:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.