# How to infer equivalent PID controller coefficients from an existing black box ccontroller?

I have a 2 input, 2 output system that I have recorded in response to 1. steps (actually quasi-steps, with 50 ms rise time + some overshoot), and 2. sine waves from 0.5 to 50 Hz, in both open and closed loop. In the open loop configuration, I can infer the internal parameters based on knowledge of the system's structure. In the closed loop configuration, a controller with ~60 ms delay brings the output close to a given target (which is separate from the input signal), but I can't figure out what the controller parameters are. I've attempted to model it as a PID controller using numerical (euler) simulations, but it seems to quickly become unstable when either I or D components are increased. In contrast, I can create the model in transfer function form and predict the frequency response, but I don't know howto then predict the response to arbitrary inputs (such as the quasi-steps, or sine waves where the control signal might differ from the input).

The system (u2 is the "goal/setpoint", F is the controller feedback with 60 ms delay, y2 is just a second output that I use to compare to data to infer H):

For example, here is the output from the transfer function (solid) v. numerical simulation (dashed) of the entire model in closed loop, for a 0.5 Hz input:

My question is: 1. Is there a better way to infer the PID parameters of F than using a numerical simulation + fminsearch (matlab) approach?

1. (Maybe this is a separate question, sorry). If not, how to think about the discrepancy between the implicitly stable TF response and the oscillating numerical response? How can I avoid the oscillations in the numerical response?

If response of any linear time invariant system to an input is the convolution of the input with the impulse response of the system.

So if you have measured the impulse response then you can find the output using convolution.

If you cant create the conditions to accurately measure an impulse response you can measure the step response. The impulse response is then the derivative of the step response.

http://lpsa.swarthmore.edu/Transient/TransInputs/TransImpulseTime.html

Obviously as time progresses a brute force convolution requires too much computation because you would be numerically integrating over ever longer times.

The solution is typically to either limit the scope of the convolution in time by modeling the system as a Finite Impulse Response system (FIR).

The other way is to use some sort of mathematical shortcut (such as recursion) to determine the next output based on the input signal and the prior output. This is Infinite Impulse Response (IIR).

Yes there is a way to find out what the parameters are:

1) You need to record all inputs and outputs

2) Use system identification to find out what your plant parameters are. Here is another link that has a better description

If you don't come from a controls background the concepts will be difficult to understand here is another good resource to understand the background

The basic idea is that you have a system $y(t) = h(t)*x(t)$ if you take the laplace transform you get $y(s) = h(s)*x(s)$ or what your really after is $y(s)/x(s) = h(s)$.

This gets much more complicated if your sampling, add in noise or have a MIMO system such as yours. Another thing, it's really useful to have data that captures all of the system dynamics. If you want to model all of the systems bandwidth a square wave, step function or dirac delta (Hitting it with a hammer) is better. These have frequency content across all frequencies where a sine wave only has frequency content in a few frequenices.