Even/odd signals and their FFT

complex numberseven-and-odd-functionsfast fourier transformfourier transform

I want to use the following property of the Fourier transform:

Even functions have even transforms; odd functions have odd transforms.

in mathematical terms:

if $f(t)$ is a function that has an even and odd part:
$f(t) = e(t) + o(t)$

then its Fourier transform yields

$F(\omega) = \int_{-\infty}^{\infty} f(t) e^{-i \omega t} dt$

$= \int_{-\infty}^{\infty} e(t) e^{-i \omega t} dt + \int_{-\infty}^{\infty} o(t) e^{-i \omega t} dt$

$ = \int_{-\infty}^{\infty} e(t)cos(\omega t) dt + i\int_{-\infty}^{\infty} e(t)sin(\omega t) dt + \int_{-\infty}^{\infty} o(t)cos(\omega t) dt + i\int_{-\infty}^{\infty} o(t)sin(\omega t) dt$

The second and last term drop, because they integrate over an odd signal ad infinitum (and therefore equate to 0). Thus,

$F(\omega) = 2\int_{0}^{\infty} e(t)cos(\omega t) dt + 2i\int_{0}^{\infty} o(t)sin(\omega t) dt$

(thus the aforementioned premise holds, credits to website ).

Now if I take a signal that is seemingly odd to me, its FFT still contains Real numbers (which it should not have, because it is odd.). What am I doing wrong, or not taking into account, here?

timetrace

EDIT: In response to Botond: Could this be a numerical error? The real part is quite big troughout (I only show the first 5 frequencies here). If I pad the signal with a lot of more zeroes, to increase the frequency window, I get similar results.

w [rad/s]        fft OUTPUT (*1e3)
     0           0.0000 + 0.0000i
0.3068           0.6663 - 9.0327i
0.6136          -0.0645 + 0.4347i
0.9204          -0.7029 + 3.1302i
1.2272           0.0086 - 0.0283i

My Matlab code:

% create timevector
dt = 0.01;
Tsim = 20;
d = 5;
t = -10:dt:10;
A = 5;

% create a funciton with two pulses
ft_TwoPulse = zeros(1,length(t));
pulse_begin1 = round((Tsim/4-d/2)/dt);
pulse_end1 = round((Tsim/4 +d/2)/dt);

ft_TwoPulse(pulse_begin1:pulse_end1) = A;
pulse_begin2 = round((Tsim*3/4-d/2)/dt)+2; % the +2 is required to make it symmetrical wrt. 0;
pulse_end2 = round((Tsim*3/4 +d/2)/dt)+2;  % such that -t(pulse_end1) = t(pulse_begine);
ft_TwoPulse(pulse_begin2:pulse_end2) = -A;

N = length(t);
N2 = 2^(nextpow2(N));
Npadding = N2 - N;
ft2                    = [ft; zeros(Npadding,1)];

% Spectral analysis method
% Define frequency vector
fs = 1/dt;
w = 2*pi*fs/N2*(0:1:N2/2);

% FFT
ft_fft = fft(ft2);
ft_fft = ft_fft(1:N2/2+1);
ft_fft(2:end-1) = 2*ft_fft(2:end-1);

Best Answer

My code, as a response to your comment:

from numpy.fft import *
import numpy as np

t = np.linspace(-10, 10, 2**11) #2^11 points on [-10, 10]

#making the signal: 5 on (-7.5, -2.5), -5 on (2.5, 7.5) and 0 otherwise
x = np.zeros(len(t))
x[((t < -2.5) & (t > -7.5))] = 5
x[((t > 2.5) & (t < 7.5))] = -5

f = rfft(x) #the rfft
freal = f.real #real part
fimag = f.imag #imaginary part

fq = rfftfreq(len(t), t[1]-t[0]) #the frequencies 
Related Question