function [exp_coeff,exp_func] = DecayFit(filtered_data) %DecayFit Second Order Approximation % This program determines the goodness of fit (gof) for a second order % underdamped system for damping rations from 0-1. peak = filtered_data(1); ts = length(filtered_data); gof = zeros(1,1000); ctr = 1; for etta = 0.001:0.001:1 wn = 4/(etta*ts); A = peak; t = 1:1:ts; % second order equation decay = A*exp(-etta*wn.*t).*cos(wn*sqrt(1 - etta^2).*t); gof(ctr) = goodnessOfFit(transpose(decay), filtered_data, 'NRMSE'); ctr = ctr + 1; end [fit, idx] = max(gof); etta = idx*0.001; wn = 4/(etta*ts); exp_coeff = [etta, wn, A, fit]; exp_func = A*exp(-etta*wn.*t).*cos(wn*sqrt(1 - etta^2).*t); end