Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

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

0 votes
5,501 views
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?
closed with the note: Problem solved
asked Nov 14, 2023 by gcosens (15 points)
closed Nov 17, 2023 by gcosens

1 Answer

0 votes
 
Best answer
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.
answered Nov 16, 2023 by Bryan Lieblick (1,905 points)
selected Nov 17, 2023 by gcosens
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.
...