Plot sin or cosine with Simulink scope
Afficher commentaires plus anciens
Hello all,
I would like to do some simulate some home-made modulation with Simulink, but first things first; so I was trying to plot the output ( a sin wave) from a signal generator into a Simulink scope, however I am coming across a issue when depicting the output into the scope, since I don´t get my sin signal but I got some crappy signal instead as it can be seen below, and looking at its PSD I think I am loosing samples or something with the simulation step.


I have found some aid in this Matlab blog, however, I cannot get the plot that I would like to, my signal input is a sin with f=2.1e6.
Is there something I can do to get my sin signal in the scope?
Thanks in advance,
Regards!
EDIT: I am using matlab2014a
Réponse acceptée
Plus de réponses (1)
Sebastian Castro
le 24 Mar 2015
1 vote
Javier,
By default, if no other blocks drive it, Simulink will choose a sample time of 1/50 the total time -- so, in your case, 2000/50 = 40 seconds. This is definitely too large for a 2.1 MHz sine wave.
To fix this,
- Go to Simulation > Model Configuration Parameters and select the "Solver" pane on the left.
- Once you're there, you can change the "Max time step" parameter to something acceptable -- i.e., anything below 1/(2*fs), and probably an integer divisor of (1/fs).
- If you don't think you need the default variable-step solver in Simulink, you can change to a fixed-step solver with a sample time similar to what I described above.
Does this solve your problem?
- Sebastian
3 commentaires
Sebastian Castro
le 25 Mar 2015
Modifié(e) : Sebastian Castro
le 25 Mar 2015
You interpreted my point correctly. I used "fs" to mean the sampling frequency -- so yes, you choose a sample time such that aliasing is prevented.
Also, I think it's expected for the simulation to take forever. If you're running a 2000-second simulation with a sample time of 2.5e-7, there are a lot of data points to process.
One thing you can do is change from sample-based (one sample at a time) processing to frame-based processing (using buffers). Look at the following link:
- Sebastian
Javier
le 25 Mar 2015
Catégories
En savoir plus sur Scopes and Data Logging dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
