How can I generate the energy vector?

14 ビュー (過去 30 日間)
studentmatlaber
studentmatlaber 2022 年 2 月 16 日
コメント済み: Star Strider 2022 年 3 月 1 日
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 件のコメント
Star Strider
Star Strider 2022 年 2 月 16 日
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.
studentmatlaber
studentmatlaber 2022 年 2 月 16 日
What you say is true, but for example, can't I write the total energy of the first 20 samples of VV into E(1,20)?
And it has to be from the first element to the last element of this VV.

サインインしてコメントする。

回答 (2 件)

Star Strider
Star Strider 2022 年 2 月 16 日
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)
VVb = 20×42
0.6555 0.9509 0.4425 1.5261 0.8570 0.4337 0.1354 0.8509 1.5680 1.9135 1.4660 1.2856 1.7060 0.8149 2.6074 0.8722 1.2421 0.8121 1.4216 1.4334 0.0806 0.5801 0.6994 1.6816 0.5263 0.1068 0.2995 0.3259 0.1571 0.9925 0.7998 0.1091 0.8207 1.8143 0.4299 0.3757 0.6845 0.2788 0.1505 0.7325 0.0885 0.0397 0.6606 0.0251 0.2271 0.1866 0.5631 0.8779 0.9050 0.4546 0.3947 0.0607 0.4054 2.3426 0.0675 0.4211 0.6056 0.5120 0.8576 0.5402 0.9862 0.5208 0.5849 0.2088 1.1449 0.6271 0.3973 0.1796 0.9575 0.1933 1.0913 0.7691 0.5944 0.8461 0.8969 0.2503 0.4719 1.6791 0.1011 0.9790 0.7487 0.7878 0.3972 1.4898 0.0298 0.4327 0.0651 1.0241 0.3943 1.7348 0.8249 1.2269 1.7597 0.3783 0.8410 0.3280 1.0920 0.5184 0.3727 0.6534 0.0452 0.0946 0.1394 0.1585 1.5594 1.9008 1.9156 0.1042 0.2177 0.9012 0.0144 0.1616 1.4221 0.9964 0.1393 0.3806 0.6362 0.6134 1.5227 0.5092 0.7190 0.3984 1.1024 2.1420 0.6386 0.0634 2.1546 0.3888 1.2523 2.5554 0.5131 0.0590 1.3656 0.4989 1.2966 0.7103 0.2949 0.3735 0.4534 0.9555 0.4149 0.4265 0.2962 0.9574 0.4059 1.2714 1.0694 1.2888 2.0118 0.1668 0.6582 2.0470 1.4657 0.7118 0.0935 2.0783 0.2149 1.4352 0.4833 0.2970 0.8146 0.5527 1.8759 0.7333 1.3803 1.0076 0.7323 2.0376 1.5531 0.8117 0.4601 0.6461 0.7065 0.3590 0.2318 1.5338 1.3234 1.4344 0.1830 0.8566 0.2083 0.4385 0.8930 0.8640 0.6316 0.2280 0.5295 0.7150 1.2514 0.0696 0.2029 0.7202 0.9554 1.5181 0.8208 0.0094 0.7512 0.1444 1.4755 0.3242 0.3472 0.3119 1.9793 1.0460 0.6323 0.1689 0.5303 0.7469 2.4266 0.7864 0.0262 0.1013 0.5394 0.2634 1.3929 0.8095 0.3830 0.3525 1.2344 1.1071 0.1659 1.6851 0.9381 1.6743 0.7074 0.5425 1.0504 0.1573 0.0388 1.7860 2.2042 1.4590 1.2051 1.2444 0.9307 0.2570 1.0591 0.3371 0.2287 0.3619 0.3726 1.5672 0.3896 0.1089 0.1763 0.1879 0.1922 1.2935 0.4317 1.9864 0.7073 1.2830 0.9685 0.5654 0.5862 0.5829 0.5458 0.4659 1.4504 0.5857 1.0021 0.3146 1.4514 0.9228 0.3460 0.5462 0.6511 0.1106 1.1399 0.8478 0.4099 1.1894 0.2730 1.7490 0.5475 0.2266 0.2811 1.3034 0.4163 0.1646 1.9598 0.0127 0.3728 0.6066 1.4627 0.8748 1.2304 0.3950 0.9396 1.2951 0.0118 0.7002 0.0046 0.8530 1.3879 1.9420 1.0740 1.4698 0.4064 0.1901
VV20 = sum(VVb)
VV20 = 1×42
14.1697 17.1708 16.0032 16.7372 11.9107 13.7842 11.2519 14.2476 20.6191 16.0476 14.7392 19.1015 16.0660 13.9551 21.5262 15.9162 16.3604 12.1483 16.0138 18.5784 14.8146 10.5621 16.0582 17.9301 14.4284 13.8236 16.7428 14.1791 17.0341 14.5265
.
  4 件のコメント
studentmatlaber
studentmatlaber 2022 年 3 月 1 日
Thank you for help. But i solve it. I wrote this code and its work succesfully.
buffer = abs(VV);
buffer1 = buffer.^2;
Enerji = cumsum(buffer1);
Star Strider
Star Strider 2022 年 3 月 1 日
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
Paul 2022 年 2 月 16 日
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)
eqnE = 
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
eqnP = 
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)
s(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)
E = 385
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)
ans = 385
Or with zero padding if one wants to do that for some reason
sum(abs(fft(svals,64)).^2)/64
ans = 385
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.
  1 件のコメント
studentmatlaber
studentmatlaber 2022 年 3 月 1 日
Thank you so much

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by