How to perform fft on variable sample rate PLECS blockset data in Matlab workspace?

I’m trying to overlay spectrum data from several different simulation runs. I’m using PLECS blockset and am automating the simulation runs and parameter variation in my matlab script.

I have run into a problem calculating the FFT of the output data due to the variable timestep used in PLECS. I tried using the nuffft function to cope with the changing timestep but I’m not getting sensible results.

I’m not keen to use a fixed timestep as my simulation will run very slowly and I risk missing switching events.

Please can you advise the best way of generating an FFT of variable sample rate PLECS output data in Matlab?

Rather than doing a variable-sample rate FFT one could simply export the relevant data at the desired sample rate. This is compatible with a variable-step solver - it only ensures that simulation solutions are reported at the specified time step. This would only be problematic if the sample time was set excessively small.

One could use the PLECS “To File” block or one of the many logging options included in Simulink (the “To Workspace” block comes to mind). Both of these blocks have a “Sample time” parameter.

If you want to proceed using variable-sample rate data, could you share your script or a simple example? The nufft() results are sensitive to the input arguments.

Thanks Bryan, the fixed sample time output enabled me to use the normal FFT function and solved my problem.

I also spotted an mistake in my variable rate script so I think I now know why the output was so wrong.