How can I create a logarithmic decrement line of best fit on a signal?

22 views (last 30 days)
Hi there,
I am currently analysing the following signal:
I wish to use the logarithmic decrement method to find an estimate for the damping ratio and use 'hold on' to display this curve on top of the original signal.
So far I have used:
[pks,locs] = findpeaks(displacement_vector) %Displays the peak values and their element location
To plot the peaks on the same graph and use a best fit line to connect them, I am assuming I need to create a new vector that contains only the peak values and contains either '0' or 'Nan' elsewhere. I have experimented with a for loop which compares elements of 'displacement_vector' and 'pks' but have got quite stuck.
Any help is greatly appreciated,
Dan

Accepted Answer

Voss
Voss on 18 Feb 2022
Something along these lines may work (or I'm sure there are slightly easier alternatives using the Curve Fitting Toolbox):
% time:
time = 0.8:0.01:6;
% some approximation of your signal, including random 'noise':
displacement_vector = 150*sin(2*pi*4*time).*exp(-time/1.5)+randn(1,numel(time));
% plot the signal:
plot(time,displacement_vector);
xlim(time([1 end]));
% find the peaks and their locations:
[pks,locs] = findpeaks(displacement_vector); %Displays the peak values and their element location
% plot the peaks too:
hold on
plot(time(locs),pks,'k.');
% fit an exponential to the peaks:
% first remove any peaks <= 0:
idx = pks <= 0;
locs(idx) = [];
pks(idx) = [];
% and plot the remaining positive peaks:
plot(time(locs),pks,'ro');
% take the log of the peaks and fit a line (i.e., a degree-1 polynomial);
% a line fitting log(pks) corresponds to an exponential fitting pks
p = polyfit(time(locs),log(pks),1);
% evaluate the line at all times, and take the exponential of
% those values to get the actual values of the exponential fit curve:
curve_fit = exp(polyval(p,time));
plot(time,curve_fit,'--g','LineWidth',2);
You may want/need to change which peaks are used to find the fit, e.g., use those > 1 rather than those > 0.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!