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 Kommentare

Image Analyst
Image Analyst am 16 Feb. 2022
What is your other/expected definition of energy? How do you get it from a list ov 832 VV values? What does VV represent? Any physical measurement?
studentmatlaber
studentmatlaber am 16 Feb. 2022
What I want to do here is to write the energy of the element (1,1) of the VV vector, namely sum(abs(VV(1,1).^2), into E(1,1).
Write sum(abs(VV(1,1:2).^2) in E(1,2).
Write sum(abs(VV(1,1:3).^2) in E(1,3).
Star Strider
Star Strider am 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.
studentmatlaber
studentmatlaber am 16 Feb. 2022
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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Star Strider
Star Strider am 16 Feb. 2022

0 Stimmen

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 Kommentare

studentmatlaber
studentmatlaber am 16 Feb. 2022
I want to do that.
If the vector elements are squared, the vector no longer represents energy, it represents power.
VV = randn(1,832) % Original Complex(?) Vector
VV = 1×832
0.0393 -0.1567 -0.3540 -0.4719 0.9290 0.2550 0.5581 0.2188 0.0403 -0.0473 -0.1033 -0.0208 -0.4879 2.4955 -0.9415 0.9778 -0.4092 0.3947 -0.4212 -0.1280 -0.0135 0.6113 1.1347 -0.3719 -0.5013 -1.5812 -0.2347 -0.9435 0.2418 0.1652
E = abs(VV) % Energy
E = 1×832
0.0393 0.1567 0.3540 0.4719 0.9290 0.2550 0.5581 0.2188 0.0403 0.0473 0.1033 0.0208 0.4879 2.4955 0.9415 0.9778 0.4092 0.3947 0.4212 0.1280 0.0135 0.6113 1.1347 0.3719 0.5013 1.5812 0.2347 0.9435 0.2418 0.1652
P = E.^2 % Power
P = 1×832
0.0015 0.0245 0.1253 0.2227 0.8630 0.0650 0.3114 0.0479 0.0016 0.0022 0.0107 0.0004 0.2380 6.2275 0.8864 0.9560 0.1675 0.1558 0.1774 0.0164 0.0002 0.3737 1.2875 0.1383 0.2513 2.5002 0.0551 0.8903 0.0585 0.0273
Pb = buffer(P, 20) % Segment Into Columns Of 20 Elements
Pb = 20×42
0.0015 0.0002 0.8233 1.4533 0.5295 0.0004 0.5178 0.6127 3.1479 0.6620 0.6489 5.1629 1.1472 0.0710 0.8318 0.0300 2.5353 1.8389 0.3202 0.3055 0.2894 0.2459 0.0573 0.0269 0.2598 1.0589 0.0426 0.5434 0.4281 2.1234 0.0245 0.3737 1.2859 0.0769 0.0828 0.9531 0.1628 0.1372 0.2904 3.7214 0.0001 0.4756 0.0683 1.3750 0.0028 0.0039 1.2860 0.1567 0.5486 0.0114 0.1591 0.6806 0.0443 0.0044 0.0874 0.8182 0.7110 2.1749 0.0691 0.2851 0.1253 1.2875 0.7058 0.0233 0.2908 0.0066 1.4846 0.0689 0.0795 1.5110 2.2141 3.3345 0.0011 0.0489 0.0278 0.0003 1.6026 0.8255 1.0862 1.5974 0.7120 0.1131 0.0001 0.3578 1.1876 0.2399 0.0348 0.2137 0.0233 0.0178 0.2227 0.1383 0.0857 3.6285 0.0010 7.2782 2.2609 0.0005 0.0452 0.6584 0.0942 1.8540 0.1916 0.1937 0.0165 1.0758 0.0492 0.1306 0.4723 2.1931 4.4408 1.4691 1.3899 0.0267 5.3891 0.8878 0.6369 0.3893 0.1849 1.2337 0.8630 0.2513 0.4856 0.6961 0.2531 0.0204 0.6068 1.0507 3.6604 1.9169 0.1007 0.0218 0.0000 0.8015 0.3804 0.3687 0.1911 0.9398 3.2561 1.2364 3.4095 0.1423 0.0068 1.9085 3.6373 0.0048 0.4923 0.0351 3.1336 0.9131 0.0650 2.5002 0.1362 4.0940 0.1594 0.4215 0.9728 0.0257 0.4609 0.3223 0.0001 0.2928 0.5677 0.5061 0.4357 0.0068 1.4577 0.5210 0.4620 0.1204 1.3489 0.0062 0.1850 0.5675 0.2571 0.0929 1.7450 1.7125 0.4821 0.0003 0.3114 0.0551 0.1218 0.2619 0.0050 0.6948 0.1117 0.0862 0.3153 0.1253 0.4899 2.4592 0.1294 0.4789 1.0601 1.0502 0.6796 0.0501 0.0280 0.1139 3.3413 3.8695 0.0085 0.1684 0.6259 0.2806 0.2266 0.0244 0.0589 0.0069 0.0479 0.8903 0.0747 0.0003 0.0719 0.0136 0.0030 0.0452 0.1217 1.3048 0.1748 0.5515 0.6693 0.4719 0.0493 0.2884 0.1676 0.0010 1.0704 0.0692 0.1677 0.0195 0.2014 0.1155 1.8604 0.3693 0.2495 1.7791 1.0723 0.0035 0.0016 0.0585 0.0086 0.0326 0.0573 0.3427 0.5865 0.3132 0.9973 0.0015 0.5774 0.8244 0.0048 1.1348 2.8968 1.1799 0.0308 0.8409 0.4785 0.0088 0.0048 0.0753 4.4590 0.0361 0.1322 0.0462 2.6239 1.0545 0.0298 0.0917 0.0022 0.0273 0.0809 2.8011 0.7205 2.3791 0.1362 1.0260 0.0460 1.1392 1.7071 0.9101 2.2248 0.1868 0.2441 0.9837 0.1315 0.2741 0.0721 3.6134 0.0038 0.4469 1.1995 0.0010 0.1206 0.6031 0.0003 0.6116 1.1356 0.0019
Pb20 = sum(Pb) % Sum Columns
Pb20 = 1×42
10.5014 27.2231 18.7963 29.3051 11.2077 19.3330 10.0805 10.4379 24.7398 19.9177 20.2184 21.8270 13.7756 17.8599 16.8038 17.2959 11.1670 20.2513 10.6387 18.7714 18.0535 21.3492 15.8290 8.5765 23.3121 17.4419 17.3876 13.5084 12.8174 12.1971
.
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 am 1 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Paul
Paul am 16 Feb. 2022

0 Stimmen

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.

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 16 Feb. 2022

Kommentiert:

am 1 Mär. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by