Tag Archives: matlab
IK solver algorithm fminconsqp performance (2025a prerelease)
Hello everyone,
I’ve been testing 2025a prerelease matlab version’s new IK solver algorithm fminconsqp with default parameters, but BFGS with random restart enabled (while keeping other parameters default) still seems more powerful.
Am I missing something? I can’t quite figure out the advantage of this new solver.
Thanks in advance!Hello everyone,
I’ve been testing 2025a prerelease matlab version’s new IK solver algorithm fminconsqp with default parameters, but BFGS with random restart enabled (while keeping other parameters default) still seems more powerful.
Am I missing something? I can’t quite figure out the advantage of this new solver.
Thanks in advance! Hello everyone,
I’ve been testing 2025a prerelease matlab version’s new IK solver algorithm fminconsqp with default parameters, but BFGS with random restart enabled (while keeping other parameters default) still seems more powerful.
Am I missing something? I can’t quite figure out the advantage of this new solver.
Thanks in advance! matlab MATLAB Answers — New Questions
How to ensure that all values are not equal when using the ecef2enu function
I’m doing coordinate system transformation using the ecef2enu function. But for some reason, all three E, N, and U values are the same. I wonder why. How can I modify it to get the exact value?
Isn’t it normal for the 1, 2, 3 matrices to have different values? Is there something wrong with my code?
currTime = gnss.SensorModel.InitialTime;
setup(scene)
wgs84 = wgs84Ellipsoid(‘meter’);
while scene.IsRunning
[~,~,p,satPos,status] = gnss.read ();
allSatPos = gnssconstellation(currTime); % ecef
currTime = currTime + seconds(1/scene.UpdateRate);
[~,trueRecPos] = plat.read; % lla
trueRecPos_ecef = lla2ecef(trueRecPos); % uav ecef
[az,el] = lookangles(trueRecPos,satPos,gnss.SensorModel.MaskAngle);
nsat = length(satPos(:,1));
enu_sat = zeros(nsat,3);
for k = 1:1:nsat
enu_sat(k,:) = ecef2enu(satPos(k,1),satPos(k,2),satPos(k,3),trueRecPos(1),trueRecPos(2),trueRecPos(3),wgs84);
end
temp=1;
unit_sat = normalize(enu_sat,’norm’,1);
target_z = 500;
scale_factors = target_z ./ unit_sat(:,3);
unit_sat_scaled = unit_sat .* scale_factors;
endI’m doing coordinate system transformation using the ecef2enu function. But for some reason, all three E, N, and U values are the same. I wonder why. How can I modify it to get the exact value?
Isn’t it normal for the 1, 2, 3 matrices to have different values? Is there something wrong with my code?
currTime = gnss.SensorModel.InitialTime;
setup(scene)
wgs84 = wgs84Ellipsoid(‘meter’);
while scene.IsRunning
[~,~,p,satPos,status] = gnss.read ();
allSatPos = gnssconstellation(currTime); % ecef
currTime = currTime + seconds(1/scene.UpdateRate);
[~,trueRecPos] = plat.read; % lla
trueRecPos_ecef = lla2ecef(trueRecPos); % uav ecef
[az,el] = lookangles(trueRecPos,satPos,gnss.SensorModel.MaskAngle);
nsat = length(satPos(:,1));
enu_sat = zeros(nsat,3);
for k = 1:1:nsat
enu_sat(k,:) = ecef2enu(satPos(k,1),satPos(k,2),satPos(k,3),trueRecPos(1),trueRecPos(2),trueRecPos(3),wgs84);
end
temp=1;
unit_sat = normalize(enu_sat,’norm’,1);
target_z = 500;
scale_factors = target_z ./ unit_sat(:,3);
unit_sat_scaled = unit_sat .* scale_factors;
end I’m doing coordinate system transformation using the ecef2enu function. But for some reason, all three E, N, and U values are the same. I wonder why. How can I modify it to get the exact value?
Isn’t it normal for the 1, 2, 3 matrices to have different values? Is there something wrong with my code?
currTime = gnss.SensorModel.InitialTime;
setup(scene)
wgs84 = wgs84Ellipsoid(‘meter’);
while scene.IsRunning
[~,~,p,satPos,status] = gnss.read ();
allSatPos = gnssconstellation(currTime); % ecef
currTime = currTime + seconds(1/scene.UpdateRate);
[~,trueRecPos] = plat.read; % lla
trueRecPos_ecef = lla2ecef(trueRecPos); % uav ecef
[az,el] = lookangles(trueRecPos,satPos,gnss.SensorModel.MaskAngle);
nsat = length(satPos(:,1));
enu_sat = zeros(nsat,3);
for k = 1:1:nsat
enu_sat(k,:) = ecef2enu(satPos(k,1),satPos(k,2),satPos(k,3),trueRecPos(1),trueRecPos(2),trueRecPos(3),wgs84);
end
temp=1;
unit_sat = normalize(enu_sat,’norm’,1);
target_z = 500;
scale_factors = target_z ./ unit_sat(:,3);
unit_sat_scaled = unit_sat .* scale_factors;
end optimization, gnss, ecef2enu, enu, ecef MATLAB Answers — New Questions
Why is my Simulink Desktop Real-Time simulation very slow or halts in Windows when Hyper-V is enabled?
I am trying to use Simulink Desktop Real-Time (SLDRT) on my Windows machine, but when I launch the example model "sldrtex_vdp.slx", it runs very slow, halts, or may even cause a blue-screen.
The following warning message may be prompted out:
Warning: The "Real-Time Synchronization" block has timed out while
trying to synchronize to real-time kernel.
The following warning messages may be shown in Diagnostic Viewer:
Model sldrtex_vdp loaded
A disconnect message was sent to the target 10 seconds ago. Waiting for response.. [6 similar]
Never received disconnect response from target. Disconnecting…
Model sldrtex_vdp unloaded
Additionally, I may see the following error message during the kernel installation (since R2019b) or when trying to run a real-time simulation (since R2020b):
The Hyper-V hypervisor has been detected. The Simulink Desktop Real-Time kernel
cannot run in the presence of the hypervisor. Please disable the Hyper-V operating
system component before attempting to use Simulink Desktop Real-Time.I am trying to use Simulink Desktop Real-Time (SLDRT) on my Windows machine, but when I launch the example model "sldrtex_vdp.slx", it runs very slow, halts, or may even cause a blue-screen.
The following warning message may be prompted out:
Warning: The "Real-Time Synchronization" block has timed out while
trying to synchronize to real-time kernel.
The following warning messages may be shown in Diagnostic Viewer:
Model sldrtex_vdp loaded
A disconnect message was sent to the target 10 seconds ago. Waiting for response.. [6 similar]
Never received disconnect response from target. Disconnecting…
Model sldrtex_vdp unloaded
Additionally, I may see the following error message during the kernel installation (since R2019b) or when trying to run a real-time simulation (since R2020b):
The Hyper-V hypervisor has been detected. The Simulink Desktop Real-Time kernel
cannot run in the presence of the hypervisor. Please disable the Hyper-V operating
system component before attempting to use Simulink Desktop Real-Time. I am trying to use Simulink Desktop Real-Time (SLDRT) on my Windows machine, but when I launch the example model "sldrtex_vdp.slx", it runs very slow, halts, or may even cause a blue-screen.
The following warning message may be prompted out:
Warning: The "Real-Time Synchronization" block has timed out while
trying to synchronize to real-time kernel.
The following warning messages may be shown in Diagnostic Viewer:
Model sldrtex_vdp loaded
A disconnect message was sent to the target 10 seconds ago. Waiting for response.. [6 similar]
Never received disconnect response from target. Disconnecting…
Model sldrtex_vdp unloaded
Additionally, I may see the following error message during the kernel installation (since R2019b) or when trying to run a real-time simulation (since R2020b):
The Hyper-V hypervisor has been detected. The Simulink Desktop Real-Time kernel
cannot run in the presence of the hypervisor. Please disable the Hyper-V operating
system component before attempting to use Simulink Desktop Real-Time. slow, timeout, sldrt, bluescreen, bsod, hyper-v, hypervisor MATLAB Answers — New Questions
Abnormally high reaction force in Simscape Multibody
Hello,
I have a simscape model of a hexapod robot which I am trying to make traverse over a small obstacle. When walking on the regular floor object, the robot is fine. However, as soon as the first leg makes contact with the obstacle, it experiences an abnormally high normal reaction force, causing the whole robot to get sent flying into the air. I am not sure why this is happening. The settings for the spatial contact forces between the floor object and the obstacle object are identical. Here is a video from the mechanics explorer (apologies for the speed, it may have to be watched on 0.25x playback).
I have tried everything I can think of – tweaking stiffness and damping parameters (K_obs and C_obs) and trying different solver settings/tolerances. Drastically reducing the stiffness and damping coefficients does help, but results in the legs of the robot sinking several millimetres through the obstacle.
I have attached a zip file containing the full project. To run the model, open and run HexMaster.m. Then, run adeept.slx. Any help would be massively appreciated.Hello,
I have a simscape model of a hexapod robot which I am trying to make traverse over a small obstacle. When walking on the regular floor object, the robot is fine. However, as soon as the first leg makes contact with the obstacle, it experiences an abnormally high normal reaction force, causing the whole robot to get sent flying into the air. I am not sure why this is happening. The settings for the spatial contact forces between the floor object and the obstacle object are identical. Here is a video from the mechanics explorer (apologies for the speed, it may have to be watched on 0.25x playback).
I have tried everything I can think of – tweaking stiffness and damping parameters (K_obs and C_obs) and trying different solver settings/tolerances. Drastically reducing the stiffness and damping coefficients does help, but results in the legs of the robot sinking several millimetres through the obstacle.
I have attached a zip file containing the full project. To run the model, open and run HexMaster.m. Then, run adeept.slx. Any help would be massively appreciated. Hello,
I have a simscape model of a hexapod robot which I am trying to make traverse over a small obstacle. When walking on the regular floor object, the robot is fine. However, as soon as the first leg makes contact with the obstacle, it experiences an abnormally high normal reaction force, causing the whole robot to get sent flying into the air. I am not sure why this is happening. The settings for the spatial contact forces between the floor object and the obstacle object are identical. Here is a video from the mechanics explorer (apologies for the speed, it may have to be watched on 0.25x playback).
I have tried everything I can think of – tweaking stiffness and damping parameters (K_obs and C_obs) and trying different solver settings/tolerances. Drastically reducing the stiffness and damping coefficients does help, but results in the legs of the robot sinking several millimetres through the obstacle.
I have attached a zip file containing the full project. To run the model, open and run HexMaster.m. Then, run adeept.slx. Any help would be massively appreciated. simscape, multibody MATLAB Answers — New Questions
regarding to your support
I hope you well receive this messege as well.
I am happy jion for your site.
I start to do project on UAV
kindy could you please send me you tube, documets regarding to quadrotror mathlab simulink?
Please help meI hope you well receive this messege as well.
I am happy jion for your site.
I start to do project on UAV
kindy could you please send me you tube, documets regarding to quadrotror mathlab simulink?
Please help me I hope you well receive this messege as well.
I am happy jion for your site.
I start to do project on UAV
kindy could you please send me you tube, documets regarding to quadrotror mathlab simulink?
Please help me uav MATLAB Answers — New Questions
Is it possible to orient the legend’s symbols vertically instead of horizontally?
Is it possible to orient the legend’s symbols vertically instead of horizontally?
In the following example, the red and blue lines in the legend are horizontally oriented, but I would like them to be vertically oriented within the legend:
x = linspace(0, 10, 100);
y1 = sin(x);
y2 = cos(x);
plot(x, y1, ‘red’, x, y2, ‘blue’);
hold on;
h1 = plot(nan, nan, ‘red’, ‘LineWidth’, 2);
h2 = plot(nan, nan, ‘blue’, ‘LineWidth’, 2);
legend([h1, h2], ‘sin(x)’, ‘cos(x)’);Is it possible to orient the legend’s symbols vertically instead of horizontally?
In the following example, the red and blue lines in the legend are horizontally oriented, but I would like them to be vertically oriented within the legend:
x = linspace(0, 10, 100);
y1 = sin(x);
y2 = cos(x);
plot(x, y1, ‘red’, x, y2, ‘blue’);
hold on;
h1 = plot(nan, nan, ‘red’, ‘LineWidth’, 2);
h2 = plot(nan, nan, ‘blue’, ‘LineWidth’, 2);
legend([h1, h2], ‘sin(x)’, ‘cos(x)’); Is it possible to orient the legend’s symbols vertically instead of horizontally?
In the following example, the red and blue lines in the legend are horizontally oriented, but I would like them to be vertically oriented within the legend:
x = linspace(0, 10, 100);
y1 = sin(x);
y2 = cos(x);
plot(x, y1, ‘red’, x, y2, ‘blue’);
hold on;
h1 = plot(nan, nan, ‘red’, ‘LineWidth’, 2);
h2 = plot(nan, nan, ‘blue’, ‘LineWidth’, 2);
legend([h1, h2], ‘sin(x)’, ‘cos(x)’); legend, symbols, lines, plot MATLAB Answers — New Questions
Why do I receive the error: Unrecognized function or variable ‘V_o’?
Please guide me to solve the following error:
Warning: The specified buffer for ‘Convertidor_Boost/Mean/Model/Transport Delay’ was too small. During simulation, the buffer size was
temporarily increased to 106496. In order to generate code, you need to update the buffer size parameter
Unrecognized function or variable ‘V_o’.
Error in Run_Convertidor_Boost (line 62)
plot(tt1,V_o)
Thank you so much,
Edwin Rodríguez JiménezPlease guide me to solve the following error:
Warning: The specified buffer for ‘Convertidor_Boost/Mean/Model/Transport Delay’ was too small. During simulation, the buffer size was
temporarily increased to 106496. In order to generate code, you need to update the buffer size parameter
Unrecognized function or variable ‘V_o’.
Error in Run_Convertidor_Boost (line 62)
plot(tt1,V_o)
Thank you so much,
Edwin Rodríguez Jiménez Please guide me to solve the following error:
Warning: The specified buffer for ‘Convertidor_Boost/Mean/Model/Transport Delay’ was too small. During simulation, the buffer size was
temporarily increased to 106496. In order to generate code, you need to update the buffer size parameter
Unrecognized function or variable ‘V_o’.
Error in Run_Convertidor_Boost (line 62)
plot(tt1,V_o)
Thank you so much,
Edwin Rodríguez Jiménez ftt, matlab, simulink MATLAB Answers — New Questions
Managing preferences does not work for add ons explorer issue
I was trying to get the Field Trip Toolbox as an add on, and https://in.mathworks.com/matlabcentral/answers/60662-how-do-i-install-fieldtrip-toolbox tells me that installing it from https://www.fieldtriptoolbox.org/ doesn’t go well.
I tried regenerating preferences, as stated in https://www.mathworks.com/matlabcentral/answers/99625-how-do-i-regenerate-my-matlab-preferences, but to no avail. I still get the message:
Error in matab.internal.addons.launchers.showExplorer (line 134)
matlab.internal.addons.Explorer.getInstance.show(navigationData);
Is there no other way than to reinstall the whole package?I was trying to get the Field Trip Toolbox as an add on, and https://in.mathworks.com/matlabcentral/answers/60662-how-do-i-install-fieldtrip-toolbox tells me that installing it from https://www.fieldtriptoolbox.org/ doesn’t go well.
I tried regenerating preferences, as stated in https://www.mathworks.com/matlabcentral/answers/99625-how-do-i-regenerate-my-matlab-preferences, but to no avail. I still get the message:
Error in matab.internal.addons.launchers.showExplorer (line 134)
matlab.internal.addons.Explorer.getInstance.show(navigationData);
Is there no other way than to reinstall the whole package? I was trying to get the Field Trip Toolbox as an add on, and https://in.mathworks.com/matlabcentral/answers/60662-how-do-i-install-fieldtrip-toolbox tells me that installing it from https://www.fieldtriptoolbox.org/ doesn’t go well.
I tried regenerating preferences, as stated in https://www.mathworks.com/matlabcentral/answers/99625-how-do-i-regenerate-my-matlab-preferences, but to no avail. I still get the message:
Error in matab.internal.addons.launchers.showExplorer (line 134)
matlab.internal.addons.Explorer.getInstance.show(navigationData);
Is there no other way than to reinstall the whole package? edf, add-ons MATLAB Answers — New Questions
Surface Area at given hight of an STL file
Hello All,
I have an STL file and I would like to go through it (z-direction) calculating the surface area on the X-Y plane.
I would like to export the data of the layer number and the corrosponding area measured.
My knowlage in matlab is limited so any tips would help.
Thanks!Hello All,
I have an STL file and I would like to go through it (z-direction) calculating the surface area on the X-Y plane.
I would like to export the data of the layer number and the corrosponding area measured.
My knowlage in matlab is limited so any tips would help.
Thanks! Hello All,
I have an STL file and I would like to go through it (z-direction) calculating the surface area on the X-Y plane.
I would like to export the data of the layer number and the corrosponding area measured.
My knowlage in matlab is limited so any tips would help.
Thanks! stl, surface area, 3d object, table, surface, area MATLAB Answers — New Questions
Why do I get “There was an error while extracting product files. Try rerunning the Installer.” when i try to install matlab r2024b ?
Why do I get "There was an error while extracting product files. Try rerunning the Installer." when i try to install matlab r2024b? When i rerun the installer it happens again.
I tried to download the matlab installer again thinking it was some bug, however it continues to happen every time.
My pc is a windows 10, Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz 3.10 GHz, ram 16,0 GB, ssd 240(150 gb free), motherboard asus P8B75-MWhy do I get "There was an error while extracting product files. Try rerunning the Installer." when i try to install matlab r2024b? When i rerun the installer it happens again.
I tried to download the matlab installer again thinking it was some bug, however it continues to happen every time.
My pc is a windows 10, Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz 3.10 GHz, ram 16,0 GB, ssd 240(150 gb free), motherboard asus P8B75-M Why do I get "There was an error while extracting product files. Try rerunning the Installer." when i try to install matlab r2024b? When i rerun the installer it happens again.
I tried to download the matlab installer again thinking it was some bug, however it continues to happen every time.
My pc is a windows 10, Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz 3.10 GHz, ram 16,0 GB, ssd 240(150 gb free), motherboard asus P8B75-M matlab, installation, error MATLAB Answers — New Questions
Working on sagnac-interferometer, HWP(22.5) rotated laser light 45and tilt by mirror to define emergent orthogonal polarized component with frequency component is introduced.
I am working in Sagnac Interferometers. A vertically polarized liight fromaHe–Ne laser is converted into 45 deg linearly polarized light with the help of a half-wave plate (HWP1) oriented at 22.5 deg with respect to the vertical direction and is spatially filtered and collimated after passing through the spatial filter assembly(SF)and lens L.The beam splitter splits the collimated beam with equal intensity into two arms of the interferometer.The beam transmitted by beam splitter passes through atriangular Sagnac interferometer embedded intoa telescope assembly of lenses. The 45 deg polarized beam enters the polarization beam splitter and splits into two counter propagating orthogo nal polarization components in the triangular Sagnac geometry, and the light emits from the beam splitter as angular multi plexed orthogonally polarized components.The mirrors introduce the desired amount of tilt in the emergent orthogonally polarized components Ox and Oy,which can be representedas Ox(r)= exp(iα1r) and Oy(r)= exp(iα2r) ; where α1 andα2 are the frequency coefficients introduced to the orthogonal polarization components due to their off-axis locations in the front focal plane of lens,and r is the transverse spatial coordinate.I am working in Sagnac Interferometers. A vertically polarized liight fromaHe–Ne laser is converted into 45 deg linearly polarized light with the help of a half-wave plate (HWP1) oriented at 22.5 deg with respect to the vertical direction and is spatially filtered and collimated after passing through the spatial filter assembly(SF)and lens L.The beam splitter splits the collimated beam with equal intensity into two arms of the interferometer.The beam transmitted by beam splitter passes through atriangular Sagnac interferometer embedded intoa telescope assembly of lenses. The 45 deg polarized beam enters the polarization beam splitter and splits into two counter propagating orthogo nal polarization components in the triangular Sagnac geometry, and the light emits from the beam splitter as angular multi plexed orthogonally polarized components.The mirrors introduce the desired amount of tilt in the emergent orthogonally polarized components Ox and Oy,which can be representedas Ox(r)= exp(iα1r) and Oy(r)= exp(iα2r) ; where α1 andα2 are the frequency coefficients introduced to the orthogonal polarization components due to their off-axis locations in the front focal plane of lens,and r is the transverse spatial coordinate. I am working in Sagnac Interferometers. A vertically polarized liight fromaHe–Ne laser is converted into 45 deg linearly polarized light with the help of a half-wave plate (HWP1) oriented at 22.5 deg with respect to the vertical direction and is spatially filtered and collimated after passing through the spatial filter assembly(SF)and lens L.The beam splitter splits the collimated beam with equal intensity into two arms of the interferometer.The beam transmitted by beam splitter passes through atriangular Sagnac interferometer embedded intoa telescope assembly of lenses. The 45 deg polarized beam enters the polarization beam splitter and splits into two counter propagating orthogo nal polarization components in the triangular Sagnac geometry, and the light emits from the beam splitter as angular multi plexed orthogonally polarized components.The mirrors introduce the desired amount of tilt in the emergent orthogonally polarized components Ox and Oy,which can be representedas Ox(r)= exp(iα1r) and Oy(r)= exp(iα2r) ; where α1 andα2 are the frequency coefficients introduced to the orthogonal polarization components due to their off-axis locations in the front focal plane of lens,and r is the transverse spatial coordinate. sagnac interferometers, jones matrix MATLAB Answers — New Questions
Translate from English To Arabic
I tried to translate text from English to Arabic using following code:
url = ‘http://ajax.googleapis.com/ajax/services/language/translate’;
page = urlread(url, ‘get’, {‘v’, ‘1.0’,’q’, ‘Hello’, … ‘langpair’, [‘en’ ‘|’ ‘ar’]});
but the result will be
page =
{"responseData": {"translatedText":""}, "responseDetails": null, "responseStatus": 200}
Please help me to solve this problem.I tried to translate text from English to Arabic using following code:
url = ‘http://ajax.googleapis.com/ajax/services/language/translate’;
page = urlread(url, ‘get’, {‘v’, ‘1.0’,’q’, ‘Hello’, … ‘langpair’, [‘en’ ‘|’ ‘ar’]});
but the result will be
page =
{"responseData": {"translatedText":""}, "responseDetails": null, "responseStatus": 200}
Please help me to solve this problem. I tried to translate text from English to Arabic using following code:
url = ‘http://ajax.googleapis.com/ajax/services/language/translate’;
page = urlread(url, ‘get’, {‘v’, ‘1.0’,’q’, ‘Hello’, … ‘langpair’, [‘en’ ‘|’ ‘ar’]});
but the result will be
page =
{"responseData": {"translatedText":""}, "responseDetails": null, "responseStatus": 200}
Please help me to solve this problem. translate arabic, arabic MATLAB Answers — New Questions
Simulink Support Package For Arduino Hardware (24.2.4) issue
I just updated the Simulink Support Package (24.2.4) For Arduino Hardware. When I add a block from it’s library to my model, the picture of the block is empty. Double clicking the block does not show it’s parameter settings. Instead, it shows the following. I never had this problem with previous versions.
This is a typical error message I recieve when I try to execute.
=== Simulation (Elapsed: 2 sec) ===
Error:Invalid setting in ‘untitled/Digital Output’ for parameter ‘System’.
Caused by:
Error evaluating parameter ‘System’ in ‘untitled/Digital Output’
Unable to resolve the name ‘arduinodriver.ArduinoDigitalIO’.I just updated the Simulink Support Package (24.2.4) For Arduino Hardware. When I add a block from it’s library to my model, the picture of the block is empty. Double clicking the block does not show it’s parameter settings. Instead, it shows the following. I never had this problem with previous versions.
This is a typical error message I recieve when I try to execute.
=== Simulation (Elapsed: 2 sec) ===
Error:Invalid setting in ‘untitled/Digital Output’ for parameter ‘System’.
Caused by:
Error evaluating parameter ‘System’ in ‘untitled/Digital Output’
Unable to resolve the name ‘arduinodriver.ArduinoDigitalIO’. I just updated the Simulink Support Package (24.2.4) For Arduino Hardware. When I add a block from it’s library to my model, the picture of the block is empty. Double clicking the block does not show it’s parameter settings. Instead, it shows the following. I never had this problem with previous versions.
This is a typical error message I recieve when I try to execute.
=== Simulation (Elapsed: 2 sec) ===
Error:Invalid setting in ‘untitled/Digital Output’ for parameter ‘System’.
Caused by:
Error evaluating parameter ‘System’ in ‘untitled/Digital Output’
Unable to resolve the name ‘arduinodriver.ArduinoDigitalIO’. arduino, simulink MATLAB Answers — New Questions
Facing problems in nonlinear system
%%%% Problem_01 %%%%
%u_t=u_xx+6u(1-u)%
%u(0,t)=(1+e^(-5t))^(-2)%
%u(1,t)=(1+e^(1-5t))^(-2)%
%u(x,0)=(1+e^x)^(-2)%
clc;
clear all;
format short
L = 1; % Length of the rod
T = 0.05; % Total time
Nx = 7; % Number of spatial steps
Nt = 10; % Number of time steps
alpha = 1; % Thermal diffusivity
dx = L / Nx; % Spatial step size
dt = T / Nt; % Time step size
r = alpha * dt / dx^2
u = sym(‘u’, [Nx+1,Nt+1]);
% Define the spatial grid
x = linspace(0, L, Nx+1);
x
% Set initial condition u(x,0)
u(:, 1) = vpa(0.0001679.*(x.^2-x)+0.00002215.*(1.5.*x.^3-1.5.*x),9);
% Set Dirichlet boundary conditions
u(1, 🙂 = boundary_condition_x0(linspace(0, T, Nt+1)); % u(0,t)
u(end, 🙂 = boundary_condition_xL(linspace(0, T, Nt+1)); % u(1,t)
u;
% Initialize the source term matrix
f = [];
R = [];
for n = 1:Nt
for j = 1:Nx+1
f_expr = (-10*(exp(x(j)-5*(n-0.5)*dt))/(1+exp(x(j)-5*(n-0.5)*dt))^3) -(2*exp(x(j)-5*(n-0.5)*dt)/(1+exp(x(j)-5*(n-0.5)*dt)^3)*((1-2*exp(x(j)-5*(n-0.5)*dt)))/(1+ …
exp(x(j)-5*(n-0.5)*dt)))-0.0003358-0.00019935*x(j) +6*((1/(1+exp(x(j)-5*(n-0.5)*dt))^2)-0.0001679*(x(j).^2-x(j))-0.00002215*((3/2)*(x(j).^3-x(j))))*(1-(1/(1+ …
exp(x(j)-5*(n-0.5)*dt))^2) +0.0001679*(x(j).^2-x(j))+0.00002215*((3/2)*(x(j).^3-x(j)))) + 6*0.5*(u(j,n)+u(j,n+1))*(1-0.5*(u(j,n)+u(j,n+1)));
f{j,n} = f_expr;
end
for j = 2:Nx
eq = (1-6*r)*u(j-1, n+1) + (10 + 12*r)*u(j, n+1) + (1 – 6*r)*u(j+1, n+1) == (1 + 6*r)*u(j-1, n)…
+ (10-12*r)*u(j, n) + (1 +6*r)*u(j+1, n) + dt*(f{j-1,n} +10*f{j,n} + f{j+1,n});
eqs(n,j-1) = eq;
end
% disp("Equations before solving:");
% disp(vpa(eqs(n, :), 6));
vsol = vpasolve(eqs(n,:));
R = struct2cell(vsol);
for j = 2:Nx
u(j,n+1) = min(abs(R{j-1}));
end
end
vpa(u,9);
esol = @(x,t) (1+exp(x-5*t))^(-2);
exact_sol = [];
Compact_sol = [];
Error_Compact = [];
for n = 2:Nt+1
for j = 2:Nx+1
exact_sol(j,n) = esol((j-1)*dx,(n-1)*dt);
Compact_sol(j,n) = u(j,n);
Error_Compact(j,n) = abs(exact_sol(j,n)-Compact_sol(j,n));
end
end
n = 11; % Choose any specific value of n (1 to 10)
j_values = 1:Nx+1;
u_values = u(j_values, n);
exact_val = exact_sol(j_values, n);
Compact_val = Compact_sol(j_values,n);
Compact_error_val = Error_Compact(j_values, n);
Table = table(u_values, exact_val,Compact_val,Compact_error_val, …
‘VariableNames’, {‘E(i,j)’, ‘Exact_Solution’,’Compact_Solution’,’Compact_Error’})
function bc_x0 = boundary_condition_x0(t)% E(0,t)
bc_x0 = zeros(size(t));
end
function bc_xL = boundary_condition_xL(t)% E(1,t)
bc_xL = zeros(size(t));
end%%%% Problem_01 %%%%
%u_t=u_xx+6u(1-u)%
%u(0,t)=(1+e^(-5t))^(-2)%
%u(1,t)=(1+e^(1-5t))^(-2)%
%u(x,0)=(1+e^x)^(-2)%
clc;
clear all;
format short
L = 1; % Length of the rod
T = 0.05; % Total time
Nx = 7; % Number of spatial steps
Nt = 10; % Number of time steps
alpha = 1; % Thermal diffusivity
dx = L / Nx; % Spatial step size
dt = T / Nt; % Time step size
r = alpha * dt / dx^2
u = sym(‘u’, [Nx+1,Nt+1]);
% Define the spatial grid
x = linspace(0, L, Nx+1);
x
% Set initial condition u(x,0)
u(:, 1) = vpa(0.0001679.*(x.^2-x)+0.00002215.*(1.5.*x.^3-1.5.*x),9);
% Set Dirichlet boundary conditions
u(1, 🙂 = boundary_condition_x0(linspace(0, T, Nt+1)); % u(0,t)
u(end, 🙂 = boundary_condition_xL(linspace(0, T, Nt+1)); % u(1,t)
u;
% Initialize the source term matrix
f = [];
R = [];
for n = 1:Nt
for j = 1:Nx+1
f_expr = (-10*(exp(x(j)-5*(n-0.5)*dt))/(1+exp(x(j)-5*(n-0.5)*dt))^3) -(2*exp(x(j)-5*(n-0.5)*dt)/(1+exp(x(j)-5*(n-0.5)*dt)^3)*((1-2*exp(x(j)-5*(n-0.5)*dt)))/(1+ …
exp(x(j)-5*(n-0.5)*dt)))-0.0003358-0.00019935*x(j) +6*((1/(1+exp(x(j)-5*(n-0.5)*dt))^2)-0.0001679*(x(j).^2-x(j))-0.00002215*((3/2)*(x(j).^3-x(j))))*(1-(1/(1+ …
exp(x(j)-5*(n-0.5)*dt))^2) +0.0001679*(x(j).^2-x(j))+0.00002215*((3/2)*(x(j).^3-x(j)))) + 6*0.5*(u(j,n)+u(j,n+1))*(1-0.5*(u(j,n)+u(j,n+1)));
f{j,n} = f_expr;
end
for j = 2:Nx
eq = (1-6*r)*u(j-1, n+1) + (10 + 12*r)*u(j, n+1) + (1 – 6*r)*u(j+1, n+1) == (1 + 6*r)*u(j-1, n)…
+ (10-12*r)*u(j, n) + (1 +6*r)*u(j+1, n) + dt*(f{j-1,n} +10*f{j,n} + f{j+1,n});
eqs(n,j-1) = eq;
end
% disp("Equations before solving:");
% disp(vpa(eqs(n, :), 6));
vsol = vpasolve(eqs(n,:));
R = struct2cell(vsol);
for j = 2:Nx
u(j,n+1) = min(abs(R{j-1}));
end
end
vpa(u,9);
esol = @(x,t) (1+exp(x-5*t))^(-2);
exact_sol = [];
Compact_sol = [];
Error_Compact = [];
for n = 2:Nt+1
for j = 2:Nx+1
exact_sol(j,n) = esol((j-1)*dx,(n-1)*dt);
Compact_sol(j,n) = u(j,n);
Error_Compact(j,n) = abs(exact_sol(j,n)-Compact_sol(j,n));
end
end
n = 11; % Choose any specific value of n (1 to 10)
j_values = 1:Nx+1;
u_values = u(j_values, n);
exact_val = exact_sol(j_values, n);
Compact_val = Compact_sol(j_values,n);
Compact_error_val = Error_Compact(j_values, n);
Table = table(u_values, exact_val,Compact_val,Compact_error_val, …
‘VariableNames’, {‘E(i,j)’, ‘Exact_Solution’,’Compact_Solution’,’Compact_Error’})
function bc_x0 = boundary_condition_x0(t)% E(0,t)
bc_x0 = zeros(size(t));
end
function bc_xL = boundary_condition_xL(t)% E(1,t)
bc_xL = zeros(size(t));
end %%%% Problem_01 %%%%
%u_t=u_xx+6u(1-u)%
%u(0,t)=(1+e^(-5t))^(-2)%
%u(1,t)=(1+e^(1-5t))^(-2)%
%u(x,0)=(1+e^x)^(-2)%
clc;
clear all;
format short
L = 1; % Length of the rod
T = 0.05; % Total time
Nx = 7; % Number of spatial steps
Nt = 10; % Number of time steps
alpha = 1; % Thermal diffusivity
dx = L / Nx; % Spatial step size
dt = T / Nt; % Time step size
r = alpha * dt / dx^2
u = sym(‘u’, [Nx+1,Nt+1]);
% Define the spatial grid
x = linspace(0, L, Nx+1);
x
% Set initial condition u(x,0)
u(:, 1) = vpa(0.0001679.*(x.^2-x)+0.00002215.*(1.5.*x.^3-1.5.*x),9);
% Set Dirichlet boundary conditions
u(1, 🙂 = boundary_condition_x0(linspace(0, T, Nt+1)); % u(0,t)
u(end, 🙂 = boundary_condition_xL(linspace(0, T, Nt+1)); % u(1,t)
u;
% Initialize the source term matrix
f = [];
R = [];
for n = 1:Nt
for j = 1:Nx+1
f_expr = (-10*(exp(x(j)-5*(n-0.5)*dt))/(1+exp(x(j)-5*(n-0.5)*dt))^3) -(2*exp(x(j)-5*(n-0.5)*dt)/(1+exp(x(j)-5*(n-0.5)*dt)^3)*((1-2*exp(x(j)-5*(n-0.5)*dt)))/(1+ …
exp(x(j)-5*(n-0.5)*dt)))-0.0003358-0.00019935*x(j) +6*((1/(1+exp(x(j)-5*(n-0.5)*dt))^2)-0.0001679*(x(j).^2-x(j))-0.00002215*((3/2)*(x(j).^3-x(j))))*(1-(1/(1+ …
exp(x(j)-5*(n-0.5)*dt))^2) +0.0001679*(x(j).^2-x(j))+0.00002215*((3/2)*(x(j).^3-x(j)))) + 6*0.5*(u(j,n)+u(j,n+1))*(1-0.5*(u(j,n)+u(j,n+1)));
f{j,n} = f_expr;
end
for j = 2:Nx
eq = (1-6*r)*u(j-1, n+1) + (10 + 12*r)*u(j, n+1) + (1 – 6*r)*u(j+1, n+1) == (1 + 6*r)*u(j-1, n)…
+ (10-12*r)*u(j, n) + (1 +6*r)*u(j+1, n) + dt*(f{j-1,n} +10*f{j,n} + f{j+1,n});
eqs(n,j-1) = eq;
end
% disp("Equations before solving:");
% disp(vpa(eqs(n, :), 6));
vsol = vpasolve(eqs(n,:));
R = struct2cell(vsol);
for j = 2:Nx
u(j,n+1) = min(abs(R{j-1}));
end
end
vpa(u,9);
esol = @(x,t) (1+exp(x-5*t))^(-2);
exact_sol = [];
Compact_sol = [];
Error_Compact = [];
for n = 2:Nt+1
for j = 2:Nx+1
exact_sol(j,n) = esol((j-1)*dx,(n-1)*dt);
Compact_sol(j,n) = u(j,n);
Error_Compact(j,n) = abs(exact_sol(j,n)-Compact_sol(j,n));
end
end
n = 11; % Choose any specific value of n (1 to 10)
j_values = 1:Nx+1;
u_values = u(j_values, n);
exact_val = exact_sol(j_values, n);
Compact_val = Compact_sol(j_values,n);
Compact_error_val = Error_Compact(j_values, n);
Table = table(u_values, exact_val,Compact_val,Compact_error_val, …
‘VariableNames’, {‘E(i,j)’, ‘Exact_Solution’,’Compact_Solution’,’Compact_Error’})
function bc_x0 = boundary_condition_x0(t)% E(0,t)
bc_x0 = zeros(size(t));
end
function bc_xL = boundary_condition_xL(t)% E(1,t)
bc_xL = zeros(size(t));
end nonlinear, equation system, solve MATLAB Answers — New Questions
bessel funtion drawing problem part two
I am trying to draw the Neumann Bessel Function. I understand why I need to use harmonic function to draw the Y0(x), but why can’t I draw Y1(x) and Y2(x).
%Neumann Bessel Function
x=(0:0.01:15).’;
i=0:50;
hold on
set(gca,’YLim’,[-1,1]); %range
set(gca,’XLim’,[0,15]); %domain
for m=0:2
j=sum((((-1).^i)./(factorial(i).*factorial(i+m))).*(x./2).^(2*i+m),2);
if m ==0
y = bessely(m, x);
else
i_minus=m:50;
j_minus=sum((((-1).^i_minus)./(factorial(i_minus).*factorial(i_minus-m))).*(x./2).^(2*i_minus-m),2);
y=(j.*cos(m*pi)-j_minus)./(sin(m*pi));
end
plot(x,y)
end
legend(‘Y0′,’Y1′,’Y2’)I am trying to draw the Neumann Bessel Function. I understand why I need to use harmonic function to draw the Y0(x), but why can’t I draw Y1(x) and Y2(x).
%Neumann Bessel Function
x=(0:0.01:15).’;
i=0:50;
hold on
set(gca,’YLim’,[-1,1]); %range
set(gca,’XLim’,[0,15]); %domain
for m=0:2
j=sum((((-1).^i)./(factorial(i).*factorial(i+m))).*(x./2).^(2*i+m),2);
if m ==0
y = bessely(m, x);
else
i_minus=m:50;
j_minus=sum((((-1).^i_minus)./(factorial(i_minus).*factorial(i_minus-m))).*(x./2).^(2*i_minus-m),2);
y=(j.*cos(m*pi)-j_minus)./(sin(m*pi));
end
plot(x,y)
end
legend(‘Y0′,’Y1′,’Y2’) I am trying to draw the Neumann Bessel Function. I understand why I need to use harmonic function to draw the Y0(x), but why can’t I draw Y1(x) and Y2(x).
%Neumann Bessel Function
x=(0:0.01:15).’;
i=0:50;
hold on
set(gca,’YLim’,[-1,1]); %range
set(gca,’XLim’,[0,15]); %domain
for m=0:2
j=sum((((-1).^i)./(factorial(i).*factorial(i+m))).*(x./2).^(2*i+m),2);
if m ==0
y = bessely(m, x);
else
i_minus=m:50;
j_minus=sum((((-1).^i_minus)./(factorial(i_minus).*factorial(i_minus-m))).*(x./2).^(2*i_minus-m),2);
y=(j.*cos(m*pi)-j_minus)./(sin(m*pi));
end
plot(x,y)
end
legend(‘Y0′,’Y1′,’Y2’) differential equations, plot MATLAB Answers — New Questions
How to make a table for two different value but depending on third single value?
If i have a function of A= Bx+zC
then i want a table of x and A for each value of z. For diffrent value of z in one file only with diffrent table.
p= 1;B=0.5;C=0.3
for z= [0 1 2 3]
x=0:0.1:p;
A=B.*x+z*C;
pp = fopen(‘A.txt’,’w’);
fprintf(pp,’%6s %6s %12sn’,’z’,’x’,’A’);
fprintf(pp,’%6.2f %6.2f %12.8fn’,A);
fclose(pp);
end
I got out put which is not to my mark .
z x A
0.90 0.95 1.00000000
1.05 1.10 1.15000000
1.20 1.25 1.30000000
1.35 1.40If i have a function of A= Bx+zC
then i want a table of x and A for each value of z. For diffrent value of z in one file only with diffrent table.
p= 1;B=0.5;C=0.3
for z= [0 1 2 3]
x=0:0.1:p;
A=B.*x+z*C;
pp = fopen(‘A.txt’,’w’);
fprintf(pp,’%6s %6s %12sn’,’z’,’x’,’A’);
fprintf(pp,’%6.2f %6.2f %12.8fn’,A);
fclose(pp);
end
I got out put which is not to my mark .
z x A
0.90 0.95 1.00000000
1.05 1.10 1.15000000
1.20 1.25 1.30000000
1.35 1.40 If i have a function of A= Bx+zC
then i want a table of x and A for each value of z. For diffrent value of z in one file only with diffrent table.
p= 1;B=0.5;C=0.3
for z= [0 1 2 3]
x=0:0.1:p;
A=B.*x+z*C;
pp = fopen(‘A.txt’,’w’);
fprintf(pp,’%6s %6s %12sn’,’z’,’x’,’A’);
fprintf(pp,’%6.2f %6.2f %12.8fn’,A);
fclose(pp);
end
I got out put which is not to my mark .
z x A
0.90 0.95 1.00000000
1.05 1.10 1.15000000
1.20 1.25 1.30000000
1.35 1.40 creating fileid MATLAB Answers — New Questions
How can I replicate this plot using the supplied equations?
Post Content Post Content matlab plot MATLAB Answers — New Questions
Problem with Unpack Block
I need help with Simulink UDP Recieve and the Unpack blocks. I am using a C++ code to stream data from two sensors in our lab via UDP into a Simulink UDP block on the same computer. Each frame of my data contains 10 int_32 values. The first int_32 value is either a 0 or a 1 to indicate which of two sensors is the current frame associated with. The rest of the 9 are the payload data from the sensor.
After receiving the frames from the UDP packet, I also use a Display block to monitor the raw byte values. When I put the byte values in the Display block into a vector and call the char() function on the vector, I get the same signal frame that was sent from each sensor. However, the output from the Unpack block is made of some weird numbers. For instance, when I parse the outputs from the Unpack block into two – (1) sensor identity and (2) payload, the identity value switches between 8240 and 8241 instead of 0 and 1. The payload data is also made up of weird numbers not similar to the actual sensor data. A typical frame of raw data from the sensors appears as this: 0 76 -99 9863 -10 8 -1 184 -87 -56. Can anyone help me? NOTE: In the Unpacking block setting, the same problem using Byte alignment of 1 or 4.I need help with Simulink UDP Recieve and the Unpack blocks. I am using a C++ code to stream data from two sensors in our lab via UDP into a Simulink UDP block on the same computer. Each frame of my data contains 10 int_32 values. The first int_32 value is either a 0 or a 1 to indicate which of two sensors is the current frame associated with. The rest of the 9 are the payload data from the sensor.
After receiving the frames from the UDP packet, I also use a Display block to monitor the raw byte values. When I put the byte values in the Display block into a vector and call the char() function on the vector, I get the same signal frame that was sent from each sensor. However, the output from the Unpack block is made of some weird numbers. For instance, when I parse the outputs from the Unpack block into two – (1) sensor identity and (2) payload, the identity value switches between 8240 and 8241 instead of 0 and 1. The payload data is also made up of weird numbers not similar to the actual sensor data. A typical frame of raw data from the sensors appears as this: 0 76 -99 9863 -10 8 -1 184 -87 -56. Can anyone help me? NOTE: In the Unpacking block setting, the same problem using Byte alignment of 1 or 4. I need help with Simulink UDP Recieve and the Unpack blocks. I am using a C++ code to stream data from two sensors in our lab via UDP into a Simulink UDP block on the same computer. Each frame of my data contains 10 int_32 values. The first int_32 value is either a 0 or a 1 to indicate which of two sensors is the current frame associated with. The rest of the 9 are the payload data from the sensor.
After receiving the frames from the UDP packet, I also use a Display block to monitor the raw byte values. When I put the byte values in the Display block into a vector and call the char() function on the vector, I get the same signal frame that was sent from each sensor. However, the output from the Unpack block is made of some weird numbers. For instance, when I parse the outputs from the Unpack block into two – (1) sensor identity and (2) payload, the identity value switches between 8240 and 8241 instead of 0 and 1. The payload data is also made up of weird numbers not similar to the actual sensor data. A typical frame of raw data from the sensors appears as this: 0 76 -99 9863 -10 8 -1 184 -87 -56. Can anyone help me? NOTE: In the Unpacking block setting, the same problem using Byte alignment of 1 or 4. udp recieve/ unpack block MATLAB Answers — New Questions
tfest function does not recognize nearby poles and zeros in a 2dof system
I am using tfestimate and tfest to experimentally derive the frequency response function of a 2 dof system with 1 input and 2 output.
The problem is that tfest seems to cancel or does not recognize a complex pole pair (resonance) near a complex zero pair (antiresonance) around 6 Hz in the tf from input 1 to output 1 and consequently simplifies the frequency response of the system (see image, correct plot in blue vs simplified plot in red):
I tried different types of windowing in tfestimate but the only one that allows me to obtain the correct frequency response after tfest is rectwin without overlap: this works only with mathematical model I/O data, the blue plot shown above, but with the real model data the problem persists. Other windows like hann (which would be more suitable) also leads to a pole-zero simplification after tfest, with mathematical model I/O data too.
Increasing the number of zeros-poles from 2-4 to 6-8 tfest gives me the correct transfer functions, but I absolutely need the model with 2 zeros and 4 poles for a correct dynamic of the system to control by using the identification of its FRF.
To load I/O data see attachment .mat file
The code is the following:
% Upload I/O data
load ‘test_identificazione_chirp_tauGain_0,1.mat’
% Data from real model
th1abs = theta1_rad_MEAS.signals.values;
th2rel = theta2_rad_MEAS.signals.values;
th2abs = th1abs+th2rel;
tauIn = tauInput.signals.values;
nfs = 4096*4; % Number of samples for FFT
Fs = 1000; % Sampling frequency
% Transfer functions estimate from input 1 (tauIn) to outputs 1 and 2 (th1abs and th2abs)
[H_11, f_H_11] = tfestimate(squeeze(tauIn), squeeze(th1abs), rectwin(floor(size(squeeze(tauIn), 1))), 0, nfs*4, Fs);
[H_21, f_H_21] = tfestimate(squeeze(tauIn), squeeze(th2abs), rectwin(floor(size(squeeze(tauIn), 1))), 0, nfs*4, Fs);
% Try also hann window with overlap to get a better curve: hann(floor(size(squeeze(tauIn), 1) / 15)), 3000
% Estimated tf smoothing, by movmean with [x,x] values
H_11 = movmean(H_11,[2,2]);
H_21 = movmean(H_21,[2,2]);
% Estimated tf plot
figure(1)
subplot(1,2,1);
semilogx(f_H_11, mag2db(abs(H_11)), ‘b’, ‘LineWidth’, 0.7);
hold on;
subplot(1,2,2);
semilogx(f_H_21, mag2db(abs(H_21)), ‘b’, ‘LineWidth’, 0.7);
hold on;
% Frequency range to keep only relevant part of tf by tfestimate
fmin = 0.1; % min freq (Hz)
fmax = 15; % max freq (Hz)
idx_11 = (f_H_11 >= fmin) & (f_H_11 <= fmax); % frequency index in the selected range
idx_21 = (f_H_21 >= fmin) & (f_H_21 <= fmax); % frequency index in the selected range
H_11_filtered = H_11(idx_11);
f_11_filtered = f_H_11(idx_11); % corresponding frequencies
H_21_filtered = H_21(idx_21);
f_21_filtered = f_H_21(idx_21); % corresponding frequencies
% rad/s conversion to use in `idfrd`
f_11_rad = f_11_filtered * 2 * pi;
f_21_rad = f_21_filtered * 2 * pi;
% Filtered tf plot
subplot(1,2,1);
semilogx(f_11_filtered, mag2db(abs(H_11_filtered)), ‘r’, ‘LineWidth’, 0.7);
subplot(1,2,2);
semilogx(f_21_filtered, mag2db(abs(H_21_filtered)), ‘r’, ‘LineWidth’, 0.7);
% Creating an identified model based on frequency data
H_11_idfrd = idfrd(H_11_filtered, f_11_rad, ‘Ts’, 0); % continuous time
H_21_idfrd = idfrd(H_21_filtered, f_21_rad, ‘Ts’, 0); % continuous time
% tf estimation in "tf" variable type
np = 4; % system pole number
nz = 2; % system zero number
sys_est_11 = tfest(H_11_idfrd, np, nz);
sys_est_21 = tfest(H_21_idfrd, np, nz);
sys_est = [sys_est_11; sys_est_21]; % [2×1] dimension
% Estimated FRF plot
figure(2)
P = bodeoptions;
P.FreqUnits = ‘Hz’; % Frequency axys in Hz
bodeplot(sys_est, P);
grid on;
hold on;
% Print estimated tf in the Command Window
sys_est
Any help? Thank you in advance!I am using tfestimate and tfest to experimentally derive the frequency response function of a 2 dof system with 1 input and 2 output.
The problem is that tfest seems to cancel or does not recognize a complex pole pair (resonance) near a complex zero pair (antiresonance) around 6 Hz in the tf from input 1 to output 1 and consequently simplifies the frequency response of the system (see image, correct plot in blue vs simplified plot in red):
I tried different types of windowing in tfestimate but the only one that allows me to obtain the correct frequency response after tfest is rectwin without overlap: this works only with mathematical model I/O data, the blue plot shown above, but with the real model data the problem persists. Other windows like hann (which would be more suitable) also leads to a pole-zero simplification after tfest, with mathematical model I/O data too.
Increasing the number of zeros-poles from 2-4 to 6-8 tfest gives me the correct transfer functions, but I absolutely need the model with 2 zeros and 4 poles for a correct dynamic of the system to control by using the identification of its FRF.
To load I/O data see attachment .mat file
The code is the following:
% Upload I/O data
load ‘test_identificazione_chirp_tauGain_0,1.mat’
% Data from real model
th1abs = theta1_rad_MEAS.signals.values;
th2rel = theta2_rad_MEAS.signals.values;
th2abs = th1abs+th2rel;
tauIn = tauInput.signals.values;
nfs = 4096*4; % Number of samples for FFT
Fs = 1000; % Sampling frequency
% Transfer functions estimate from input 1 (tauIn) to outputs 1 and 2 (th1abs and th2abs)
[H_11, f_H_11] = tfestimate(squeeze(tauIn), squeeze(th1abs), rectwin(floor(size(squeeze(tauIn), 1))), 0, nfs*4, Fs);
[H_21, f_H_21] = tfestimate(squeeze(tauIn), squeeze(th2abs), rectwin(floor(size(squeeze(tauIn), 1))), 0, nfs*4, Fs);
% Try also hann window with overlap to get a better curve: hann(floor(size(squeeze(tauIn), 1) / 15)), 3000
% Estimated tf smoothing, by movmean with [x,x] values
H_11 = movmean(H_11,[2,2]);
H_21 = movmean(H_21,[2,2]);
% Estimated tf plot
figure(1)
subplot(1,2,1);
semilogx(f_H_11, mag2db(abs(H_11)), ‘b’, ‘LineWidth’, 0.7);
hold on;
subplot(1,2,2);
semilogx(f_H_21, mag2db(abs(H_21)), ‘b’, ‘LineWidth’, 0.7);
hold on;
% Frequency range to keep only relevant part of tf by tfestimate
fmin = 0.1; % min freq (Hz)
fmax = 15; % max freq (Hz)
idx_11 = (f_H_11 >= fmin) & (f_H_11 <= fmax); % frequency index in the selected range
idx_21 = (f_H_21 >= fmin) & (f_H_21 <= fmax); % frequency index in the selected range
H_11_filtered = H_11(idx_11);
f_11_filtered = f_H_11(idx_11); % corresponding frequencies
H_21_filtered = H_21(idx_21);
f_21_filtered = f_H_21(idx_21); % corresponding frequencies
% rad/s conversion to use in `idfrd`
f_11_rad = f_11_filtered * 2 * pi;
f_21_rad = f_21_filtered * 2 * pi;
% Filtered tf plot
subplot(1,2,1);
semilogx(f_11_filtered, mag2db(abs(H_11_filtered)), ‘r’, ‘LineWidth’, 0.7);
subplot(1,2,2);
semilogx(f_21_filtered, mag2db(abs(H_21_filtered)), ‘r’, ‘LineWidth’, 0.7);
% Creating an identified model based on frequency data
H_11_idfrd = idfrd(H_11_filtered, f_11_rad, ‘Ts’, 0); % continuous time
H_21_idfrd = idfrd(H_21_filtered, f_21_rad, ‘Ts’, 0); % continuous time
% tf estimation in "tf" variable type
np = 4; % system pole number
nz = 2; % system zero number
sys_est_11 = tfest(H_11_idfrd, np, nz);
sys_est_21 = tfest(H_21_idfrd, np, nz);
sys_est = [sys_est_11; sys_est_21]; % [2×1] dimension
% Estimated FRF plot
figure(2)
P = bodeoptions;
P.FreqUnits = ‘Hz’; % Frequency axys in Hz
bodeplot(sys_est, P);
grid on;
hold on;
% Print estimated tf in the Command Window
sys_est
Any help? Thank you in advance! I am using tfestimate and tfest to experimentally derive the frequency response function of a 2 dof system with 1 input and 2 output.
The problem is that tfest seems to cancel or does not recognize a complex pole pair (resonance) near a complex zero pair (antiresonance) around 6 Hz in the tf from input 1 to output 1 and consequently simplifies the frequency response of the system (see image, correct plot in blue vs simplified plot in red):
I tried different types of windowing in tfestimate but the only one that allows me to obtain the correct frequency response after tfest is rectwin without overlap: this works only with mathematical model I/O data, the blue plot shown above, but with the real model data the problem persists. Other windows like hann (which would be more suitable) also leads to a pole-zero simplification after tfest, with mathematical model I/O data too.
Increasing the number of zeros-poles from 2-4 to 6-8 tfest gives me the correct transfer functions, but I absolutely need the model with 2 zeros and 4 poles for a correct dynamic of the system to control by using the identification of its FRF.
To load I/O data see attachment .mat file
The code is the following:
% Upload I/O data
load ‘test_identificazione_chirp_tauGain_0,1.mat’
% Data from real model
th1abs = theta1_rad_MEAS.signals.values;
th2rel = theta2_rad_MEAS.signals.values;
th2abs = th1abs+th2rel;
tauIn = tauInput.signals.values;
nfs = 4096*4; % Number of samples for FFT
Fs = 1000; % Sampling frequency
% Transfer functions estimate from input 1 (tauIn) to outputs 1 and 2 (th1abs and th2abs)
[H_11, f_H_11] = tfestimate(squeeze(tauIn), squeeze(th1abs), rectwin(floor(size(squeeze(tauIn), 1))), 0, nfs*4, Fs);
[H_21, f_H_21] = tfestimate(squeeze(tauIn), squeeze(th2abs), rectwin(floor(size(squeeze(tauIn), 1))), 0, nfs*4, Fs);
% Try also hann window with overlap to get a better curve: hann(floor(size(squeeze(tauIn), 1) / 15)), 3000
% Estimated tf smoothing, by movmean with [x,x] values
H_11 = movmean(H_11,[2,2]);
H_21 = movmean(H_21,[2,2]);
% Estimated tf plot
figure(1)
subplot(1,2,1);
semilogx(f_H_11, mag2db(abs(H_11)), ‘b’, ‘LineWidth’, 0.7);
hold on;
subplot(1,2,2);
semilogx(f_H_21, mag2db(abs(H_21)), ‘b’, ‘LineWidth’, 0.7);
hold on;
% Frequency range to keep only relevant part of tf by tfestimate
fmin = 0.1; % min freq (Hz)
fmax = 15; % max freq (Hz)
idx_11 = (f_H_11 >= fmin) & (f_H_11 <= fmax); % frequency index in the selected range
idx_21 = (f_H_21 >= fmin) & (f_H_21 <= fmax); % frequency index in the selected range
H_11_filtered = H_11(idx_11);
f_11_filtered = f_H_11(idx_11); % corresponding frequencies
H_21_filtered = H_21(idx_21);
f_21_filtered = f_H_21(idx_21); % corresponding frequencies
% rad/s conversion to use in `idfrd`
f_11_rad = f_11_filtered * 2 * pi;
f_21_rad = f_21_filtered * 2 * pi;
% Filtered tf plot
subplot(1,2,1);
semilogx(f_11_filtered, mag2db(abs(H_11_filtered)), ‘r’, ‘LineWidth’, 0.7);
subplot(1,2,2);
semilogx(f_21_filtered, mag2db(abs(H_21_filtered)), ‘r’, ‘LineWidth’, 0.7);
% Creating an identified model based on frequency data
H_11_idfrd = idfrd(H_11_filtered, f_11_rad, ‘Ts’, 0); % continuous time
H_21_idfrd = idfrd(H_21_filtered, f_21_rad, ‘Ts’, 0); % continuous time
% tf estimation in "tf" variable type
np = 4; % system pole number
nz = 2; % system zero number
sys_est_11 = tfest(H_11_idfrd, np, nz);
sys_est_21 = tfest(H_21_idfrd, np, nz);
sys_est = [sys_est_11; sys_est_21]; % [2×1] dimension
% Estimated FRF plot
figure(2)
P = bodeoptions;
P.FreqUnits = ‘Hz’; % Frequency axys in Hz
bodeplot(sys_est, P);
grid on;
hold on;
% Print estimated tf in the Command Window
sys_est
Any help? Thank you in advance! tfest, system identification, frequency response MATLAB Answers — New Questions
Determine the Bode diagram or a transfer function with input output data without tfest
In a partially unknown system, I measured a square-wave signal as input and the associated system response. Now I would like to use fft() to determine the transfer function or the Bode diagram. I have attached the measurements. I have the following code (also from this forum) but it results in this very bad bode plot. where is my mistake?
input = x3bzeit((23000:39000),2);
output = x3bzeit((23000:39000),3);
time = x3bzeit((23000:39000),1)*10^(-6);
Fs = 1/mean(diff(time)); % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = numel(time);
FTinp = fft(input)/L;
FTout = fft(output)/L;
TF = FTout ./ FTinp; % Transfer Function
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
subplot(2,1,1)
plot(Fv, 20*log10(abs(TF(Iv))))
set(gca, ‘XScale’, ‘log’)
title(‘Amplitude’)
ylabel(‘dB’)
subplot(2,1,2)
plot(Fv, angle(TF(Iv))*180/pi)
title(‘Phase’)
ylabel(‘°’)In a partially unknown system, I measured a square-wave signal as input and the associated system response. Now I would like to use fft() to determine the transfer function or the Bode diagram. I have attached the measurements. I have the following code (also from this forum) but it results in this very bad bode plot. where is my mistake?
input = x3bzeit((23000:39000),2);
output = x3bzeit((23000:39000),3);
time = x3bzeit((23000:39000),1)*10^(-6);
Fs = 1/mean(diff(time)); % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = numel(time);
FTinp = fft(input)/L;
FTout = fft(output)/L;
TF = FTout ./ FTinp; % Transfer Function
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
subplot(2,1,1)
plot(Fv, 20*log10(abs(TF(Iv))))
set(gca, ‘XScale’, ‘log’)
title(‘Amplitude’)
ylabel(‘dB’)
subplot(2,1,2)
plot(Fv, angle(TF(Iv))*180/pi)
title(‘Phase’)
ylabel(‘°’) In a partially unknown system, I measured a square-wave signal as input and the associated system response. Now I would like to use fft() to determine the transfer function or the Bode diagram. I have attached the measurements. I have the following code (also from this forum) but it results in this very bad bode plot. where is my mistake?
input = x3bzeit((23000:39000),2);
output = x3bzeit((23000:39000),3);
time = x3bzeit((23000:39000),1)*10^(-6);
Fs = 1/mean(diff(time)); % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = numel(time);
FTinp = fft(input)/L;
FTout = fft(output)/L;
TF = FTout ./ FTinp; % Transfer Function
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
subplot(2,1,1)
plot(Fv, 20*log10(abs(TF(Iv))))
set(gca, ‘XScale’, ‘log’)
title(‘Amplitude’)
ylabel(‘dB’)
subplot(2,1,2)
plot(Fv, angle(TF(Iv))*180/pi)
title(‘Phase’)
ylabel(‘°’) bode, transfer function, fft MATLAB Answers — New Questions