FFT on non-periodic signal and signal power at each harmonic - is there a more robust approach? I have a non-periodic signal collected from a force plate, it represents the foot/ground contact of a human when running.



My aim is to calculate the signal power of each harmonic up to 50Hz. I will break down what I have done so far.


Firstly, I calculate the fundamental frequency by dividing the sampling frequency by the length of the signal. I then find the other harmonics by multiplying the fundamental frequency by 2,3...etc (not shown here, this example just includes the fundamental frequency (FF).

Fs = 1000;
FF = Fs/(length(Fz_data));

I run the FFT on my signal. 

dt = 1/Fs;
t=(0:1/Fs:(length(Fz_data)-1)/Fs)';
NFFT = length(Fz_data);
Y = fft(Fz_data,NFFT);

For each harmonic (identified in 1 - FF in this instance),I zero out frequencies above and below the harmonic and then run ifft to convert the data back to the time domain which leaves me with the data for the first harmonic only(?).

F = ((0:1/NFFT:1-1/NFFT)*Fs).';
Y(F&lt;FF-0.1) = 0;
Y(F&gt;FF+0.1) = 0; 
y = ifft(Y,NFFT,'symmetric');






I then calculate the power of this signal using pwelch.

[P,~] = pwelch(y,ones(NFFT,1),0,NFFT,Fs,'power');
pwr = sum(P)



Questions

From a programming perspective, this works, but I have reservations that this approach is not based on sound theory. I will, therefore, present some questions below, and I hope the community may be able to offer some solutions to improve the robustness of this approach.


Is it suitable to calculate the fundamental frequency from the length of the signal?
I have read that it is not suitable to use an FFT on a non-periodic signal. Is there a way to adapt the FFT method to make it more suitable e.g. some sort of windowing function?
Is there an easy way to remove drift/bias from the signal?
I would also welcome comments on any other aspects of this process if you feel it would make it more robust.


Thanks in advance.
I'll try to address your questions one at a time.


  Is it suitable to calculate the fundamental frequency from the length of the signal?


Your signal is not periodic, so speaking of "fundamental frequency" is not correct. The fundamental frequency corresponds to the lowest frequency of a periodic waveform, which is not the case here. So, regarding your question, no: you cannot define a fundamental frequency from the length of a signal - two things not related at all.


  I have read that it is not suitable to use an FFT on a non-periodic signal. Is there a way to adapt the FFT method to make it more suitable e.g. some sort of windowing function?


FFT can indeed be used for non-periodic signals. In case you are not too familiar with DFT, I'll try to explain how it works in a nutshell.

You have a discrete signal. You window it (you only take $N$ of its values). You perform the DFT on those values. What does "perform the DFT" mean? The signal whose DFT will be calculated is assumed to be $N$-periodic, and you get a discrete frequency representation of that signal (not the original non-windowed one). I believe that this is the reason why you state that FFT is not suitable on non-periodic signals. Nevertheless, you can still use it, we do it all the time. Maybe some answers in this question can help.

If you are interested in which frequencies are present at each instant of time, one can use several windows an overlap them, and take the FFTs of those signals. See STFT.


  Is there an easy way to remove drift/bias from the signal?


Do you mean DC value? In that case, you can just substract the mean value of the signal, or apply a high-pass filter with sufficiently low cutoff frequency.


  I would also welcome comments on any other aspects of this process if you feel it would make it more robust.


At some point in your script, you just set some FFT coefficients to zero. Note that this approach is generally not a good idea.