0
$\begingroup$

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:

enter image description here

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:

enter image description here

which is not equivalent to the original signal:

plt.plot(xe+xo)

enter image description here

what's wrong in my signal decomposition?

$\endgroup$

1 Answer 1

1
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ 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)? $\endgroup$
    – Curious
    Apr 1, 2022 at 15:42
  • $\begingroup$ 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. $\endgroup$
    – TimWescott
    Apr 1, 2022 at 19:46
  • $\begingroup$ 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? $\endgroup$
    – Curious
    Apr 1, 2022 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.