The transfer function of a small position Sensor
3 views (last 30 days)
Show older comments
GHADAH AL-OBAIDI
on 28 Sep 2021
Commented: Star Strider
on 4 Oct 2021
I have the below matlab code and I would like to find :
- First Order Fit: try (polyfit), Find the Matlab function for fitting: P = WHAT_FUNCTION(WHAT TO FIT as what is x, WHAT TO FIT as what is y, ORDER); Force_Nm_Linear = P(1) * Displacement_d_mm + P(2);
- Second Order Fit, same as above: what is x, y, ORDER P = WHAT_FUNCTION(WHAT TO FIT, WHAT TO FIT, ORDER); Force_Nm_2nd_Order = P(3) + P(2)*Displacement_d_mm + P(1)*Displacement_d_mm.*Displacement_d_mm;
Note: we have to set some of the coefficients to = 0 to check if it can be ignored:
P(3) = 0;
Force_Nm_2nd_two_Terms = P(3) + P(2)*Displacement_d_mm + P(1)*Displacement_d_mm.*Displacement_d_mm;
My Matlab code is::::::::::::::::
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
close all;
clc;
Displacement_d_mm = [0, 0.08, 0.16, 0.24, 0.32, 0.4, 0.48, 0.52];
Force_Nm = [0, 0.578, 1.147, 1.677, 2.187, 2.648, 3.089, 3.295];
% Part A: First Order Fit:
% In this case, x is the displacement and y is the force.
% where d is the displacement and F the force
P = polyfit(Displacement_d_mm, Force_Nm, 1);
Force_Nm_Linear = P(1) * Displacement_d_mm + P(2); % F = 6.3221d + 0.089
% Part B:
Displacement_d_mm_b = [0, 0.32, 0.52];
Force_Nm_b = [0, 2.187, 3.295];
% Second Order Fit:
P = polyfit(Displacement_d_mm, Force_Nm, 2);
Force_Nm_2nd_Order = P(3) + P(2)*Displacement_d_mm + P(1)*Displacement_d_mm.*Displacement_d_mm;
0 Comments
Accepted Answer
Star Strider
on 28 Sep 2021
If you actually want the transfer function, use the System Identification Toolbox functions —
Displacement_d_mm = [0, 0.08, 0.16, 0.24, 0.32, 0.4, 0.48, 0.52] % Output 'y(t)'
Force_Nm = [0, 0.578, 1.147, 1.677, 2.187, 2.648, 3.089, 3.295] % Input 'u(t)'
Ts = 1; % Sampling Interval (Replace With Actual Value)
idd = iddata(Displacement_d_mm(:), Force_Nm(:), Ts)
ff_sys = tfest(idd,1)
figure
compare(idd, ff_sys)
Experiment to get different results.
.
2 Comments
More Answers (0)
See Also
Categories
Find more on Linear Model Identification 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!