# Signal decomposition to even and odd components

I'm trying to decompose some signal to even and odd components, here's the Python code of it:

import numpy as np

t = np.linspace(0,1,64)
f = 2e6

test_signal = []
for i in range(len(t)):
test_signal.append(np.sin(2*np.pi*f*t)[i]+i*0.05)

plt.plot(t, test_signal)

which outputs the original signal:

but if I try to decompose it to even and odd components:

xe = []
xo = []
N = len(t)-1

for i in range(len(t)):
if i==0:
xe.append(test_signal[0])
xo.append(0)
else:
xe.append(0.5*(test_signal[i]+test_signal[N-i]))
xo.append(0.5*(test_signal[i]-test_signal[N-i]))

plt.plot(xe, label='even part')
plt.plot(xo, label='odd part')
plt.legend();

I get the following:

which is not equivalent to the original signal:

plt.plot(xe+xo)

what's wrong in my signal decomposition?

Your 'real' problem is that you define xe and xo as lists, not as numpy arrays. So the operation xe + xo concatenates the list, it doesn't add them element by element. Try converting them to numpy arrays right after your 'for' loop (better yet, figure out how to do the math in one step).

Your second problem is that this part of your if statement:

if i==0:
xe.append(test_signal[0])
xo.append(0)

is appropriate for functions that have even and odd symmetry around zero, but this part:

else:
xe.append(0.5*(test_signal[i]+test_signal[N-i]))
xo.append(0.5*(test_signal[i]-test_signal[N-i]))

is imposing even and odd symmetry around N / 2.

• thank you! it helped!) just a little question: what is the method for decomposition arbitrary signals (which don't have symmetry around zero and don't have even or odd symmetry around zero)? Apr 1, 2022 at 15:42
• Decompose into what? There's all sorts of signal decompositions out there, useful for various different things. Even/odd is one, the Fourier series (for periodic signals) is another, the Walsh-Hadamard transform is slightly esoteric but has been used in cell phone standards, there's wavelet decomposition -- the et ceteras go on into infinity. Apr 1, 2022 at 19:46
• no, I'm just wondering about the second problem, as you mentioned in your answer; I used the definition of the first point for odd and even curves from the book, is it wrong? Apr 1, 2022 at 21:04