Hello,
I would like to use PLECS to perform system ID on some black-box discrete time signal processing algorithms in DLL form (compiled either from C->DLL, or verilator->C+±>DLL)
As an example, I have implemented a simple discrete integrator in c:
// block.c
#include "DllHeader.h"
DLLEXPORT void plecsSetSizes(struct SimulationSizes* aSizes) {
aSizes->numInputs = 1;
aSizes->numOutputs = 1;
aSizes->numStates = 1;
aSizes->numParameters = 0;
}
DLLEXPORT void plecsStart(struct SimulationState* aState) {
aState->states[0] = 0.0;
aState->outputs[0] = 0.0;
}
DLLEXPORT void plecsOutput(struct SimulationState* aState) {
// Integrator as defined in: https://www.youtube.com/watch?v=7Gl4kJUjp4c 15:55
aState->outputs[0] = aState->inputs[0] + aState->states[0];
aState->states[0] = aState->outputs[0];
}
Here is the gain and phase response I expect to see (Discrete time):
Here is the gain and phase response which I observe in PLECS when performing an AC sweep with default settings:
test.plecs (6.9 KB)
Please advise.
Hi,
this method will not help you for measuring frequencies beyond the nyquist frequency. If you replicate your DLL with a discrete integrator block, provide a sinusoidal input whose frequency is larger than 1/sample_time, and run a PLECS simulation you will see that the results are quite bad. This will also happen with the AC Sweep, so whatever frequency transformation you do with those results will not make any sense.
Multitone analysis seems to work well, the other analyses do not, I am not sure why.
small_signal_problems_z_integrator.plecs (9.5 KB)
Hi Enrique,
Thank you for your response. My aim is to analyze black-box DLLs in the frequency domain, so replicating the DLL with blocks is not an option.
I have experimented briefly with AC sweep, Impulse Response, and Multitone analyses before writing this post, however I was not able to achieve satisfactory results.
Kind regards,
Nick
I did not mean that you should replicate your DLL with discrete blocks, I meant that the problem you have can be replicated with PLECS native blocks. To me that indicates that the current methods are not very appropriate to do what you need.
In any case the integrator is quite tricky, probably any other model would give less issues (e.g. low-pass-filter). When the analysis provides perturbations in multiples of Fs/2, you will be sampling DC value, this is sent to the open loop integrator and the system will not have a Steady-state (which makes the AC sweep and impulse response to fail).
Thank you Enrique. I see that the integrator is a particularly hard case, and also that applying a perturbation to an existing ac input can improve performance somewhat.