Complete the code to calculate the energy of a discrete signal x.
energy = sum(abs(x)[1] 2 )
The energy of a discrete signal is the sum of the squared magnitudes of its samples. Using ** 2 squares each element.
Complete the code to calculate the average power of a discrete signal x.
power = sum(abs(x)[1] 2) / len(x)
Average power is the sum of squared magnitudes divided by the number of samples. Squaring is done with ** 2.
Fix the error in the code to compute signal energy correctly.
energy = sum(x[1] 2 )
The energy requires squaring each sample. Using ** 2 correctly squares the values.
Fill both blanks to create a dictionary of energies for signals longer than 3 samples.
energies = {name: sum(abs(signal)[1] 2) for name, signal in signals.items() if len(signal) [2] 3}We square each sample with ** and filter signals longer than 3 using >.
Fill all three blanks to create a dictionary of average powers for signals with power less than 5.
powers = {name: sum(abs(signal)[1] 2) / len(signal) for name, signal in signals.items() if sum(abs(signal)[2] 2) / len(signal) [3] 5}Use ** to square samples and < to filter powers less than 5.
