MATLAB Answers



Asked by mohamed al-asklany on 22 Mar 2012

if i have a simulink model and the output of low pass filter is sin signal with certain frequency if i want to know this frequency and display it on a screen what should i do? remark simulation model time is (inf.)




No products are associated with this question.

2 Answers

Answer by K E
on 22 Mar 2012

I would output the signal to the workspace and calculate the frequency from within Matlab; here is an example approach. You could use Matlab to start your simulation too using the sim command, and afterward plot the spectrum that you calculate.


on 26 Mar 2012

You first need to export the simulation time and signal that you want to analyze from Simulink to Matlab using the 'ToWorkspace' block. Once these variables are in the Matlab workspace, set t equal to your simulation time variable and x equal to your simulation signal (for example position). Once you have t and x in your Matlab workspace, follow the example ( to obtain freq and Pyy. Then you can find the peak using the code that I supplied earlier:

Pyy1 = Pyy(1:128) ;
frequencyOfBiggestPeak = freq(Pyy1 == max(Pyy1)) ; % Hz

my simulink model time is inf
how i can import data from simulink in inf tim?

on 4 Apr 2012

You could decide how much time you would need to get a good estimate of the frequency (for example, 30 periods of a 10-second sine wave would be 300 seconds), then put an event listener ( in your model that would output the results to the workspace at 300 seconds.

I think you can use the option named display which is available in sink block.. I am not sure also whether this will work or not.


  1 Comment

no no no,i want to get freq not to show its spectrum

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!