Question: Now repeat the process on a different data set that potentially has different system parameters ( n 1 , d 3 d 2 and d

Now repeat the process on a different data set that potentially has different system
parameters (n1, d3 d2 and d1). Read the SEA_speed.csv data and repeat Tasks 4.3 and 4.4 for this
data. Record your estimated parameter values.
i need help doing this. % Define a function to compute the step response error for given parameters
function err = cost_function(params, SEA_time, SEA_speed)
N1= params(1);
D3= params(2);
D2= params(3);
D1= params(4);
% Define the transfer function based on these parameters
s = tf('s');
TF_speed =(N1* s)/(s^4+ D3* s^3+ D2* s^2+ D1* s);
% Simulate the response to a 2V step input
[y, ~]= step(2* TF_speed, SEA_time);
% Compute the error (sum of squared differences between simulated and actual)
err = sum((y - SEA_speed).^2);
end
% Initial guess for the parameters (based on "near" values)
initial_guess =[4600,150,900,40000];
% Load the experimental speed response data
load('SEA_speed.mat'); % Loads SEA_speed and SEA_time
% Perform parameter estimation using fminsearch
opt_params = fminsearch(@(params) cost_function(params, SEA_time, SEA_speed), initial_guess);
% Display the optimized parameters
disp('Estimated Parameters:');
disp(['N1=', num2str(opt_params(1))]);
disp(['D3=', num2str(opt_params(2))]);
disp(['D2=', num2str(opt_params(3))]);
disp(['D1=', num2str(opt_params(4))]);
% Now simulate the response using the optimized parameters and plot the result
N1_opt = opt_params(1);
D3_opt = opt_params(2);
D2_opt = opt_params(3);
D1_opt = opt_params(4);
% Define the optimized transfer function
s = tf('s');
TF_speed_opt =(N1_opt * s)/(s^4+ D3_opt * s^3+ D2_opt * s^2+ D1_opt * s);
% Simulate the system's response with optimized parameters
[y%% Task 4.4: Comparing Step Responses
s = tf('s');
TF_speed_opt =(N1_opt * s)/(s^4+ D3_opt * s^3+ D2_opt * s^2+ D1_opt * s);
% Simulate the system's response with optimized parameters
[y_opt, t_opt]= step(2* TF_speed_opt, SEA_time);
% Plot the optimized response and experimental data
figure;
plot(t_opt, y_opt, 'r', 'LineWidth', 1); % Optimized response in red
hold on;
plot(SEA_time, SEA_speed, 'b', 'LineWidth', 1); % Experimental data in blue dashed line
legend('Optimized Simulated Response', 'Experimental Data');
xlabel('Time (s)');
ylabel('Speed (rad/s)');
title('Comparison of Optimized Simulated Response and Experimental Data');
grid on;
% Plot the response from Task 4.2 for comparison
% Redefine the near system transfer function
TF_speed_near =(N1* s)/(s^4+ D3* s^3+ D2* s^2+ D1* s);
% Simulate the response for the near system
[y_near, t_near]= step(2* TF_speed_near, SEA_time);
% Plot the near system response
figure;
plot(t_near, y_near, 'g', 'LineWidth', 1); % Near system response in green
hold on;
plot(SEA_time, SEA_speed, 'b', 'LineWidth', 1); % Experimental data in blue dashed line
plot(t_opt, y_opt, 'r', 'LineWidth', 1); % Optimized response in red
legend('Near System Response', 'Experimental Data', 'Optimized Simulated Response');
xlabel('Time (s)');
ylabel('Speed (rad/s)');
title('Comparison of Near System, Optimized Simulated Response, and Experimental Data');
grid on;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!