# Why does this reconstruction produce a phase shift from the original signal?

After an FFT of a signal is done, it is plotted as in the image below, with the original signal is on the first subplot.

Using the magnitude and phase data of each frequency, it's reconstructed, and the produced signal is as the image below.

The reconstructed is signal is good except it's shifted 4 milliseconds earlier from the the original signal. I also has done this with another signal, but this 4 milliseconds shift is there too. Why does this happen?

Additional question: I used this for harmonic analysis of 50 Hz fundamental frequency (electric power system frequency). I had a slightly hard time determining which frequency of each harmonic (50*n Hz) frequency to use because, from the FFT result, the phase angle is θ at (50*n∓0.001) Hz but suddenly becomes θ±180° at (50*n±0.001) Hz. For example, at 149.999Hz the phase angle is 223.3° but at 150.001Hz the phase angle is suddenly 403.3°. Is this hard time determining which angle of each frequency to use for reconstruction, normal?

By the way, this is the Matlab code I use to do the FFT and the plotting.

Fs = 1/(8e-6);                % Sampling frequency
T = 1/Fs;                     % Sample time
L = 2^21;                     % Length of signal
t = (0:L-1)*T;                % Time vector

SampleNoBallast;              % The original signal

NFFT = 2^nextpow2(L);         % Next power of 2 from length of y
Y = fft(y,NFFT)/L;            % The Fast Fourier Transform producing FFT complex
f = Fs/2*linspace(0,1,NFFT/2+1);     % Frequencies to plot
P = rad2deg(unwrap(angle(Y)));       % Phase degrees from FFT complex

% Plotting the original signal
subplot(3,1,1); plot(t(1:12500),y(1:12500))
title('Arus Masukan LED T8 Opple 18 W tanpa Ballast')
ylabel('arus (mA)')
xlabel('waktu (s)')
grid on
set(gca,'ButtonDownFcn','selectmoveresize');
% Plot single-sided amplitude spectrum.

% Plotting the magnitude of each frequency
subplot(3,1,2); plot(f(1:17000),2*abs(Y(1:17000)))
title('Hasil FFT')
xlabel('Frekuensi (Hz)')
ylabel('Amplitudo (mA)')
set(gca,'ButtonDownFcn','selectmoveresize');

% Plotting the phase of each frequency
subplot(3,1,3); plot(f(1:17000),P(1:17000))
title('Sudut Komponen Harmonik')
xlabel('Frekuensi (Hz)')
ylabel('Sudut (derajat)')
set(gca,'ButtonDownFcn','selectmoveresize');

• Welcome to DSP.SE! How did you generate the reconstructed signal? If it was just using ifft then there is something very wrong. If you're doing some modification of the original FFT data or using something other than ifft to reconstruct it, then we need to see that to be able to answer your question. – Peter K. Mar 18 '16 at 18:53
• See my answer here about why your phase angle flips at slightly different frequencies, and, thus, the proper way to measure phase of arbitrary frequency spectrum: dsp.stackexchange.com/questions/29509/… – hotpaw2 Mar 18 '16 at 19:32
• Thank you for the welcome. I reconstruct the signal using an electronic simulation program, LTSpice, by putting together 10 current sources of each frequency (50 Hz, 150 Hz, 250 Hz, ..., 950 Hz). The original FFT data consists of 12500 points, but to give more resolution to the FFT result, I duplicate it 168 times to make it slightly more than 2^21. – Qelopin Uacel Mar 19 '16 at 0:20
• I tried using ifft and the result is perfect, but if I tried to use LTSpice for the reconstruction, there's the phase shift. – Qelopin Uacel Mar 19 '16 at 2:03