-
Notifications
You must be signed in to change notification settings - Fork 1
/
expoFit.m
30 lines (27 loc) · 881 Bytes
/
expoFit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function [zeta] = expoFit(y,t,wn,optionPlot)
% [zeta] = expoFit(y,t,wn) returns the damping ratio calcualted by fitting
% an exponential decay to the envelop of the free-decay response.
%
% Input:
% y: envelop of the free-decay response: vector of size [1 x N]
% t: time vector [ 1 x N]
% wn: target eigen frequencies (rad/Hz) : [1 x 1]
% optionPlot: 1 to plot the fitted function, and 0 not to plot it.
%
% Output
% zeta: modal damping ratio: [1 x 1]
%
% author: E. Cheynet - UiB - last updated: 14-05-2020
%
%%
% Initialisation
guess = [1,1e-2];
% simple exponentiald ecay function
myFun = @(a,x) a(1).*exp(-a(2).*x);
% application of nlinfit function
coeff = nlinfit(t,y,myFun,guess);
% modal damping ratio:
zeta = abs(coeff(2)./wn);
% alternatively: plot the fitted function
if optionPlot== 1, plot(t,myFun(coeff,t),'r'); end
end