# FFT of signal with starting value zeros

I have a signal,

fs = 100;                                % Sample frequency (Hz)
t = 0:1/fs:10-1/fs;                      % 10 sec sample
x = (1.3)*sin(2*pi*15*t)                 % 15 Hz component
+ (1.7)*sin(2*pi*40*(t-2)) ;             % 40 Hz component


when I take fft of x then its amplitude and phase spectrum are:

And now if deliberately I will put the leading 10 values to zeros

x(1:10) = 0;

then as per my understanding the frequency of the complete data set is not changed so the fft would not be changed. Which is supported by the amplitude fft response.

But the phase plot is showing some strange result.

Can some help me why the response is changed. Although they both are following the same equation. Also If I have a equation cos(2*pift) and my t is from 3:Tp and before time =3sec the response is zero, then will it not have the same response as t:0:Tp.

• Why do you think frequency of signal was not changed? You change signal -> spectrum is changed too. Hint - plot signal in time domain before and after. Think. If it will not be any idea -> change signal with x(1:49)=0 or x(1:98)=0. – SergV May 4 '15 at 16:00
• As per my understanding the FFT try to map the sinosoidal signal in the provided data range by following the data variations. So in the case I have mentioned, I thought The data set is now shrinked so it will only effect the frequency resolution but the frequency specturm amplitude will remain the same. I also tried x(1:49)=0 or x(1:98)=0 and the spectrum (max location is same). Thats why I was thinking that the frequency response should remain same (with some distortion in resolution) – Mr. Khan May 4 '15 at 16:23
• Try x(1:500)=0, x(1:990)=0. See not only spectrum, but plot(t,x). Your signal is not 2-sinusoidal now. – SergV May 4 '15 at 17:14
• Dear I have tried x(1:500) and also till x(1:900) to zeros. But again the amplitude response of FFT is same (meaning peaks at the same frequency) but with distortions due to the less number of samples. Also this shows that the main frequency contents are the same as the original one. Your comment on this behavior is highly appreciated. – Mr. Khan May 6 '15 at 9:34

I expand and modify your code:

N = 100;  %number of sample
fs = 100; % Sample frequency (Hz)
t = 0:1/fs:(N-1)/fs;
x = sin(2*pi*10*t);  % 10 Hz component
%x(:)=1;
f = 0:fs/N:(N-1)*fs/N;

subplot(2,2,1);
plot(t,x);
title('full signal'); grid on;
subplot(2,2,3);
plot(f(1:N/2),abs(fft(x)(1:N/2)));
title('spectrum'); grid on;

x1=x;     %x1 - zero pad signal
x1(1:ceil(N/3))=0;
x1(ceil(2*N/3):N)=0;

subplot(2,2,2);
plot(t,x1,'b',t,x1,'*');
title('zero pad signal'); grid on;
subplot(2,2,4);
plot(f(1:ceil(N/2)),abs(fft(x1)(1:ceil(N/2))));
title('spectrum'); grid on;


You can see signals before and after zero padding are quite different. And the spectrums are quite different too. There is strong part of signal x1 with frequency 10 Hz, and you can see strong peak on spectrum.

You can uncomment line with x(:)=1; First full signal will be DC (constant), second (zero padding) - rectangle. Quite different signals and quite different spectrum.

UPDATE
About phase spectrum. Update to code:

F=fft(x);
angle(F(11))  % phase = -1.5708
F1=fft(x1);
angle(F1(11)) % phase =  -1.6018


Phase for x makes sense only for bin with non zero amplitude. Non zero amplitude numbers are 11 and 91. Phase for any other index are results of calculations errors of FFT function.
As x1 has big part of x the phase spectrum for this bins has approximately the same value (as you can see).

Hint. You can present x1 as product of $sin$ function and rectangle function. So spectrum of x1 is a convolution of spectrum $sin$ and rectangle.

• I think your answer elaborate the concept efficiently. I am accepting the answer for your elaboration. But My other small part of question is why the spectrum (phase also) changes by tampering the data set at the first positions. – Mr. Khan May 7 '15 at 9:43
• @Mr.Khan, I update my answer – SergV May 7 '15 at 10:26
• Thanks alot , Now I understood that the phase of the frequency spectrum remains approx unchanged. I was also guessing that but once again it was a nice ellaboration. – Mr. Khan May 7 '15 at 11:26