# curve fitting to step and impulse response

조회 수: 22 (최근 30일)
Huichen Zhang 2017년 4월 4일
답변: Sanjay Manohar 2019년 9월 4일
I am trying to curve fit a step response and an impulse response curve of a second order system. While the step response I know that its hard to fit due to external noises, I dont understand why for the impulse response, Matlab curve fitting toolbox is unable to fit the curve.
I have attached the original data here. 278800:324000 is the data corresponds to impulse response.
% how to use this code?
% 1. type in .xlsx file path in line 10
% 2. modify the first entry in line 16 and 17 to select valid data
% 3. run the code. A, B, and C are stored in the array newparams
% Sample sheet is used in this data.
% Define curve model functions
expsin = @(A, B, C, t)A * sin(C * t) .* exp(-B * t);
lsqexpsin = @(p, t)expsin(p(1), p(2), p(3), t);
% read data from file
filename = 'C:\Users\huich\Dropbox\EG4301\Testing\Heavydampedfiring\firing1.xlsx';
% Store data in arrays
x = data(278800:324000,2);
t = data(278800:324000,1);
x = x - 0.5;
t = t - t(1);
dt = 10;
close all; figure; hold on;
plot(t, x, 'k-', 'LineWidth', 2);
% Count zero crossings to find frequency
zCross = find(x(1:end-1) .* x(2:end) < 0);
T = mean(diff(zCross) * dt) * 2;
fEstimate = 1 / T;
C = 2 * pi * fEstimate;
% Fit model to data
init = [0.5, .5, C];
[newparams, err] = lsqcurvefit(lsqexpsin, init, t, x);
plot(t, lsqexpsin(newparams, t))
I dont know whats wrong with the code either as it doesnt give a decaying oscillation function. Original file can be downloaded from, https://www.dropbox.com/s/9o7ip4490kavt4l/firing1.xlsx?dl=0

댓글을 달려면 로그인하십시오.

### 답변 (2개)

prabha verma 2019년 4월 25일
Probably you are taking wrong equation.
For finding correct equation, find out the time response signal relation ship of the second order system. Since your data belongs to the underdamped condition, So considere the respactive equation.
in this pdf please got to page 10, the very first equation on this page may be your curve fitting wquation. You need to define the damping factor and natural frequency using some initial guess.
It would be even more easier if you use the "cftool" of matlab.
Hope it will help
##### 댓글 수: 0이전 댓글 -2개 표시이전 댓글 -2개 숨기기

댓글을 달려면 로그인하십시오.

Sanjay Manohar 2019년 9월 4일
The data and the fit start 90 degrees out of phase!
You probably need a phase term.
sin(dx+c)
If you know the curve is constrained to start at +1, then just use cos(dx) instead of sin(dx+c).

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by