MATLAB Answers

double peaks in FFT matlab

11 views (last 30 days)
hamzah khan
hamzah khan on 16 Oct 2020
Answered: David Goodmanson on 19 Oct 2020
I am trying to generate FFT with matlab code for the time based forces acting on a machine tool. The difference I am using is that I am not taking the absolute value of forces but I am normalizing them and I am not doubling the values of the FFT.
here is my code
spindle_speed = 960; % speed is in rpm
N = 3; %Number of teeth in cutter
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = (inv((spindle_speed/60))*1000)*50; % Length of signal 62.5 for one machine tool cycle
delta_T = 0;
t = (0+delta_T:(L-1))*T; % Time vector
f = Fs*(0:(L/2))/L; % frequency vector
% FFT in Y
Analytical_Fourier_Y = fft(Fy_Total_Teeth,[],1);
P2 = Analytical_Fourier_Y/L;
P1 = P2(1:L/2+1);
P1(2:end-1) = 1*P1(2:end-1);
% FFT in X
Analytical_Fourier_X = fft(Fx_Total_Teeth,[],1);
P2_x = Analytical_Fourier_X/L;
P1_x = P2_x(1:L/2+1);
P1_x(2:end-1) =1*P1_x(2:end-1);
The problem I am facing is that when my delta_T = 0, then my fft is correct as shown below:
delta_T influences the Fy_Total_Teeth and Fx_Total_Teeth
but when my delta_T = 50 or any other integer, then my FFT gives double peaks, as shown below:
Does anyone know, how to improve the FFT results when delta_T is not zero.

  1 Comment

Star Strider
Star Strider on 16 Oct 2020
The problem could be that you have irregularly-sampled data, and that you are imposing a sampling frequency (sampling interval) on it that may not exist. It is not possible to impose something on the data that are not part of its inherent characteristics and get acceptable results.
I would first use (with ‘t’ as your time vector of sampling instants, that should be part of your data):
Ts = mean(diff(t))
TsSd = std(diff(t))
and see how they compare. If ‘TsSd’ is vanishingly small, or is at least about times ‘Ts’, you can assume regular sampling. If that is not the situation, use the Signal Processing Toolbox resample function to resample it to an acceptable uniform sampling frequency, and use the time vector it produces as the new time vector for the resampled signal. Then you can process your data successfully, using the correct sampling interval. The sampling frequency, ‘Fs’, is 1/Ts.

Sign in to comment.

Answers (1)

David Goodmanson
David Goodmanson on 19 Oct 2020
Hello hamzah
the fft is a complex function. Are you plotting only the real part?
This problem is occurring because your delta_T operation is not delaying the entire signal. It is merely chopping off the first part of the signal, and changing the total number of points.
Let's say the signal contains an exact integral number of oscillations in the time window at some frequency. (By the look of your data there are several such frequencies). The result is a sharp spike in the fft at that frequency (two spikes if you plot all the frequencies, positive and negative). Once you chop off part of the time window you don't have an exact integral number of oscillations any more, which means that you don't get the sharp spike and some of the energy content spills into adjacent frequencies. That causes the behavior in your lower plots.
The example below shows the result for a single frequency. I didn't bother with scaling the frequency grid or scalilng the fft output or cutting out half the frequencies for the plot, since the effect doesn't depend on any of that.
The first plot shows real spikes, appropriate for the cosine function. The second plot shows the problem with truncation.
Time delay leads to phase shifts in the frequency domain. The third plot with true delay shows complex spikes due to the phase shift. But unlilke with truncation, they are still spikes.
n = 1000;
t = 0:n-1;
y = cos(2*pi*t/25); % exactly 40 cycles
yf = fft(y);
grid on
% truncated
t7 = 7:n-1;
y = cos(2*pi*t7/25); % not an exact number of cycles
yf = fft(y);
grid on
% true delay
td = t + 7;
y = cos(2*pi*td/25);
yf = fft(y);
grid on


Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!