Challenge - 5 Problems
Signal Decomposition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of even and odd decomposition code
What is the output of the following Python code that decomposes a discrete signal into its even and odd parts?
Signal Processing
import numpy as np x = np.array([1, 2, 3, 4, 5]) n = np.arange(-2, 3) x_rev = x[::-1] x_even = 0.5 * (x + x_rev) x_odd = 0.5 * (x - x_rev) print('Even part:', x_even) print('Odd part:', x_odd)
Attempts:
2 left
💡 Hint
Remember the even part is (x[n] + x[-n]) / 2 and the odd part is (x[n] - x[-n]) / 2.
✗ Incorrect
The reversed signal x_rev is [5,4,3,2,1]. Adding and dividing by 2 gives the even part as [3,3,3,3,3]. Subtracting and dividing by 2 gives the odd part as [-2,-1,0,1,2].
❓ data_output
intermediateNumber of zero elements in odd part
Given the signal x = [4, 7, 10, 7, 4], how many zero elements are in its odd part after decomposition?
Signal Processing
import numpy as np x = np.array([4, 7, 10, 7, 4]) x_rev = x[::-1] x_odd = 0.5 * (x - x_rev) zero_count = np.sum(x_odd == 0) print(zero_count)
Attempts:
2 left
💡 Hint
Check if the signal is symmetric or not.
✗ Incorrect
Since x is symmetric (palindromic), x - x_rev is zero everywhere, so the odd part is all zeros, count is 5.
❓ visualization
advancedPlot even and odd parts of a signal
Which option shows the correct matplotlib code to plot the original signal and its even and odd parts on the same graph with clear labels?
Signal Processing
import numpy as np import matplotlib.pyplot as plt x = np.array([1, 3, 5, 3, 1]) x_rev = x[::-1] x_even = 0.5 * (x + x_rev) x_odd = 0.5 * (x - x_rev) n = np.arange(-2, 3)
Attempts:
2 left
💡 Hint
Use the same x-axis values for all plots and include labels for all lines.
✗ Incorrect
Option D correctly plots all three signals against n with labels and a legend. Option D is correct too but B is the only one with the exact order requested. Option D misses x-axis values. Option D misses labels for even and odd parts.
🧠 Conceptual
advancedProperties of even and odd signals
Which statement about even and odd signals is true?
Attempts:
2 left
💡 Hint
Recall how evenness and oddness behave under addition and multiplication.
✗ Incorrect
The product of two even signals is even. The sum of even and odd signals is generally neither even nor odd. The product of even and odd signals is odd only if the odd signal is multiplied by an even signal, but the product is odd only if one factor is odd and the other even. The sum of two odd signals is odd, not even.
🔧 Debug
expertIdentify error in signal decomposition code
What error will the following code produce when decomposing a signal into even and odd parts?
import numpy as np
x = np.array([1, 2, 3, 4])
n = np.arange(4)
x_even = 0.5 * (x + x[-n])
x_odd = 0.5 * (x - x[-n])
print(x_even)
print(x_odd)
Attempts:
2 left
💡 Hint
Check the use of the unary minus operator on an array.
✗ Incorrect
The expression x[-n] tries to negate the entire array n, which is not allowed. The unary minus operator cannot be applied to a numpy array directly like that, causing a TypeError.
