Most fft tutorials use sinusoidal signals for demonstration, which makes the user already know what the fft is supposed to give as an output, but what about real time signals where we don't have any previous knowledge except the sampled data with the following problems:
- No previous knowledge
- Variable sampling time
- Unknown Noise
I have a signal which has the previous characteristics, so I used the following Matlab code to interpolate and select a proper period (visually):
clear all load('ExperimentData.mat') close all % Because the sampling period is not constant, I have first to interpolate the data Ts=min(diff(t));Fs=1/Ts; t_new=t(1):Ts:t(end); x_new=interp1(t,x,t_new); %% Extracting one period and Applying ZERO PADDING tStart=0.7086;[~,idxStart]=min(abs(t_new-tStart)); tEnd=0.7686;[~,idxEnd]=min(abs(t_new-tEnd)); x1p=x_new(idxStart:idxEnd); t1p=t_new(idxStart:idxEnd); F=figure;plot(t,x,'b');hold on plot(t_new,x_new,'r:') plot(t1p,x1p,'.-g'); ylabel('x');xlabel('time[sec]');legend('Original signal','Interpolated Signal','One Period')
The outcome is the following:
I then applied the FFT once on the complet signal an once on one period with ZERO padding using the following code:
X = fft(x_new-mean(x_new)); N = size(x_new,2); f=Fs/2 * linspace(0,1,N/2+1); figure; AX(1)=subplot(211);semilogx(f,abs(X(1:N/2+1)));ylabel('Magnitude');xlabel('Frequency(Hz)');title('Entire signal Without Zero Padding') AX(2)=subplot(212);semilogx(f,angle(X(1:N/2+1)));ylabel('Phase');xlabel('Frequency(Hz)') linkaxes(AX,'x');axis tight; %Zero Padding x_1PZP=[x1p-mean(x1p) zeros(1,100000)]; X_1PZP = fft(x_1PZP); figure; AX(1)=subplot(211);semilogx(f,abs(X_1PZP(1:N/2+1)));ylabel('Magnitude');xlabel('Frequency(Hz)');title('One Period with Zero Padding') AX(2)=subplot(212);semilogx(f,angle(X_1PZP(1:N/2+1)));ylabel('Phase');xlabel('Frequency(Hz)') linkaxes(AX,'x');axis tight
The results are:
My wonderings are:
- Does the interpolation of a signal alter the FFT ?
- From the Time Signal, the FFT on the complet signal is closer to reality. but it still doesn't show all frequencies. Why?
- I almost can't extract any information fro the phase plot. What am I missing?