How can I generate the energy vector?
6 views (last 30 days)
Show older comments
The signal information is contained in the VV vector. I am writing this code to find the energy of the signal.
E=sum(abs(VV).^2);
But I want to create an energy vector. The VV vector is 1x832 in size. However, when I write this code, the energy of the signal becomes 1x1. What I want to do here is to create an energy vector. So I want to see the total energy of the 832 long signal in column 832 of the E vector. I would be very grateful if you could help me how to do this.
4 Comments
Star Strider
on 16 Feb 2022
The result is a scalar because of the sum call. It quite appropriately sums a vector to create a scalar.
Also, energy is the result of the abs call (assuming that ‘VV’ is complex). Squaring it creates a power vector.
So I would just use abs and use that result.
Answers (2)
Star Strider
on 16 Feb 2022
If you want to segment it into 20-sample subvectors and then get the sum of each subvector, use the buffer function —
VV = abs(randn(1,832));
VVb = buffer(VV, 20)
VV20 = sum(VVb)
.
4 Comments
Star Strider
on 1 Mar 2022
My pleasure!
If ‘VV’ is complex, that appears to be correct. Note that if ‘buffer’ is energy, ‘buffer1’ is power.
Consider that if you want the simple sum for ‘Enerji’ the cumsum function is appropriate, however if you want the numerical integral, cumtrapz is more likely to be correct.
Paul
on 16 Feb 2022
I believe that you are correct that in discrete time the energy of a signal is given by
syms s(n) E
assume(n,'integer')
eqnE = E == symsum(abs(s(n))^2,n,-inf,inf)
I don't know why the Symbolic Math Toolbox breaks up the sum into two subsums for display. At any particular value of n, the instantaneous power is
syms P(n)
eqnP = P(n) == abs(s(n))^2
We see that energy is an accumulation of instananeous power, which is consistent with the typical physical notions of energy and power.
Not all signals have finite energy. However, the signal of interest in this question is of finite duration, and so as long as each element of the signal is bounded, the infinite sum that defines the energy will also be finite.
The accumulation of energy with each successive element of the sequence can be computed with cumsum(). For example, define s(n) as follows
s(n) = piecewise(n<0, 0, n > 9, 0, 10-n)
The values of s(n) that we care about are:
nvals = 0:9;
svals = 10 - nvals;
The energy and its accumulation is then
E = sum(abs(svals).^2)
Ecum = cumsum(abs(svals).^2);
figure
stem(nvals,Ecum)
hold('on')
yline(E)
xlim([-1 10])
xlabel('n')
ylabel('Energy')
For a finite duration signal, its energy can also be computed from its DFT
sum(abs(fft(svals)).^2)/numel(svals)
Or with zero padding if one wants to do that for some reason
sum(abs(fft(svals,64)).^2)/64
For any signal of finite energy (either of finite duration or infinite duration), its energy can also be computed via integration of the amplitude squared of its DTFT.
Another quantity of interest is the average power, which is also sometimes just called power. For bounded, finite duration signals the average power is zero.
See Also
Categories
Find more on Parametric Spectral Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!