Clear Filters
Clear Filters

How to Obtain State Space Model from Bode Plot Data

16 views (last 30 days)
Hi Everyone,
I have Experiemental Data (Bode Plot), using MATLAB I found the Transfer Function of my plant. I have attached my E7i_CSV file.
T2 = readtable('E7i_CSV.csv');
% Fill With Actual Sampling Frequency
FHz = T2.F;
Ts = 1/(2*(max(FHz)+10000))
for k = 1:size(T2,1)-1
if FHz(k+1) == FHz(k)
FHz(k+1) = FHz(k+1)+0.5; % 'Brute Force' Interpolation
end
end
Mag = T2.G;
PhDeg = T2.P;
Response = Mag.*exp(1j*deg2rad(PhDeg)); % Complex Vector
sysfr = idfrd(Response, FHz, Ts, 'FrequencyUnit','Hz')
%bode(sysfr)
%tfsys = tfest(sysfr,4,3) This is much better
tfsys = tfest(sysfr,4,3) %82.69%
%tfsys = tfest(sysfr,6,3)
figure
compare(sysfr, tfsys)
is_stable = isstable(tfsys);
disp(is_stable);
I want to convert this transfer function to statespace equations, which will be used for Model Predictive Control Design. Simple tf2ss command give me TF but it doesn't look very accrurate.
%Assuming you have a tfsys transfer function object named 'tf'
num = tfsys.Numerator; % Extract numerator coefficients
den = tfsys.Denominator; % Extract denominator coefficients
[A, B, C, D] = tf2ss(num,den)
So, I was reading a paper which i will follow (also attached), they have mentioned that they had FRF (Frequency Response Function) data and they find state space model/equations using Prediction Error Method (PEM). But I am unable to understand how I can used Bode Plot data and convert it state space using PEM. I will appreciate your help.
Secondy I verified the paper StateSpace Model by first converting it to Transfer Function and then using tf2ss command. which shows inaccurate results similiar to my results. I am looking for your help. Following is the verification code for paper i am following
%Rana Paper State Space Equations Coversion to
%Transfer Function for Validation Reason
% Define state-space matrices in the Paper
Ax = [-49.3277, -980.7648, 618.2198;
567.3557, -120.2273, 651.7342;
-45.8885, -415.4194, -115.7522];
Bx = [-1.8122; 3.901370; 4.3011];
Cx = [14.9368, 16.9208, -23.6827];
Dx = 0;
% Create a state-space model
sys = ss(Ax, Bx, Cx, Dx);
% Display the state-space model
disp('State-Space Model:');
disp(sys);
% Convert the state-space model to a transfer function
tf_sys = tf(sys);
% Display the transfer function
disp('Transfer Function:');
disp(tf_sys);
%TF to StateSpace Rana Model
num_rana = [ -62.92 3.625*10^4 -1.065*10^8];
den_rana = [ 1 285.3 8.811*10^5 1.982*10^8];
tff_rana = tf(num_rana,den_rana);
tffss_rana = tf2ss(num_rana,den_rana);
[Arana,Brana,Crana,Drana] = tf2ss(num_rana,den_rana);

Accepted Answer

Paul
Paul on 15 Oct 2023
Hi Muhammad,
Here is the first part of the code:
T2 = readtable('E7i_CSV.csv');
% Fill With Actual Sampling Frequency
FHz = T2.F;
Ts = 1/(2*(max(FHz)+10000))
Ts = 1.6667e-05
for k = 1:size(T2,1)-1
if FHz(k+1) == FHz(k)
FHz(k+1) = FHz(k+1)+0.5; % 'Brute Force' Interpolation
end
end
Mag = T2.G;
PhDeg = T2.P;
Response = Mag.*exp(1j*deg2rad(PhDeg)); % Complex Vector
sysfr = idfrd(Response, FHz, Ts, 'FrequencyUnit','Hz')
sysfr = IDFRD model. Contains Frequency Response Data for 1 output(s) and 1 input(s). Response data is available at 1001 frequency points, ranging from 100 Hz to 2e+04 Hz. Sample time: 1.6667e-05 seconds Status: Created by direct construction or transformation. Not estimated.
%bode(sysfr)
%tfsys = tfest(sysfr,4,3) This is much better
tfsys = tfest(sysfr,4,3) %82.69%
tfsys = -6.928 s^3 + 5.189e05 s^2 - 3.755e10 s + 3.039e15 ------------------------------------------------------- s^4 + 3.085e04 s^3 + 5.188e09 s^2 + 1.2e14 s + 4.462e18 Continuous-time identified transfer function. Parameterization: Number of poles: 4 Number of zeros: 3 Number of free coefficients: 8 Use "tfdata", "getpvec", "getcov" for parameters and their uncertainties. Status: Estimated using TFEST on frequency response data "sysfr". Fit to estimation data: 79.61% FPE: 1.574e-08, MSE: 1.549e-08
%tfsys = tfest(sysfr,6,3)
figure
compare(sysfr, tfsys)
is_stable = isstable(tfsys);
disp(is_stable);
1
num = tfsys.Numerator; % Extract numerator coefficients
den = tfsys.Denominator; % Extract denominator coefficients
[A, B, C, D] = tf2ss(num,den);
Here, make a new plot adding the frequency response of the state space model. As expected, it exactly (to withing numerical error) overlays the response of the transfer function model.
figure
compare(sysfr, tfsys, ss(A,B,C,D))
Before going any further, can you explain why "it doesn't look very accrurate."?
  5 Comments
Muhammad
Muhammad on 17 Oct 2023
One thing more @Paul can you further convert above state-space model of sys3 = ss(A,B,C,D); to discrete state space please.
Paul
Paul on 17 Oct 2023
See c2d for appoximating a continuous time system with a discrete time model. That function offers a few options to apply for the approximation.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!