FFT doesn't give desired frequency response
Show older comments
Hi there,
I am currently trying to evaluate the frequency response of a system, defined as: TargetForce --> System --> ActualForce. I have a timetable (TimetableData.txt) containing both channels, evenly resampled. My function [FFT_struct] = FFT_from_tt(tt) is supposed to give the single-sided and padded fft of both channels. I have to problems/misunderstandings with the result:
- The amplitudes don't match up with the time-domain amplitudes (see "timedomain.png" vs. "targetforce_frequencydomain_amplitude.png"). I've tried the function with one of Matlab's code examples and it does work there, which gives me a hint that something is wrong with my data - but I have no clue what that could be.
- The phase-response looks strange (see "frequencyResponse_Phase.png"). I obtained it by the code below (see end of code snippet). I would have expected it to be the "inverse" and something between 0 and -pi.
As I said, I suggest that I treat my specific data wrong - but I really need help with finding out. Thanks in advance!
function [FFT_struct] = FFT_from_tt(tt)
% FFT_FROM_TT Calculates FFT columnwise from evenly resampled timetable.
% Usage of padding
% Tolerance for fft analysis - UNUSED HERE
tol = 0;
sample_time = seconds(mean(diff(tt.Time)));
sample_rate = 1/sample_time;
L = size(tt, 1);
NFFT=2^nextpow2(L);
chns = size(tt, 2);
freq = sample_rate/2*linspace(0,1,NFFT/2+1);
%% FFT
for ch = 1:chns
Y = fft(fillmissing(table2array(tt(:, ch)), 'linear'), NFFT)/L; % Double-sided transformation
Y = 2*Y(1:NFFT/2+1); % Single-sided transformation
Y(abs(Y)<tol) = 0; % Tolerance for frequency response analysis
FFT_struct.(tt.Properties.VariableNames{ch}).freq = freq;
FFT_struct.(tt.Properties.VariableNames{ch}).Y = Y;
FFT_struct.(tt.Properties.VariableNames{ch}).ampl = abs(Y);
FFT_struct.(tt.Properties.VariableNames{ch}).phase = unwrap(angle(Y)); % [rad]
end
end
%% NOT IN THIS FUNCTION - Calculation of phase response
YTF = YActual./YTarget;
plot(freq, unwrap(angle(YTF)))
Accepted Answer
More Answers (0)
Categories
Find more on Spectral Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
