Plot sin or cosine with Simulink scope

18 views (last 30 days)
Javier
Javier on 24 Mar 2015
Edited: Javier on 25 Mar 2015
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

Accepted Answer

Javier
Javier on 25 Mar 2015
Edited: Javier on 25 Mar 2015
Finally I solved it with the advices of Sebastian and making use of Mathworks blog.
Thus my solution was:
fo(carrier)= 2e6Hz
Be compliant with Nyquist: fs>=2*fo or Ts<=(To/2) where To=1/(2*fo)=2.5e-7s => Ts = 2.5e-7s
Model parameters
>> solver >> Max step size = Ts = 2.5e-7
>> solver >> Stop time = 0.05
>> Data Import/Export >> Output options : Refine Output >> Refine Factor = 100
Thus I got this signal

More Answers (1)

Sebastian Castro
Sebastian Castro on 24 Mar 2015
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,
  1. Go to Simulation > Model Configuration Parameters and select the "Solver" pane on the left.
  2. 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).
  3. 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 Comments
Sebastian Castro
Sebastian Castro on 25 Mar 2015
Edited: Sebastian Castro on 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
Javier on 25 Mar 2015
Thanks for the advices Sebastian, thanks to then I have managed it but without using the buffers, just reducing the simulation time to 0.05s, a Ts=2..5e-6s(Max time step) and making use of the link I mention in my original post;that's to say, I have use the redefin option under "Data export" and I have set it at 100, then I got a good view of my signal.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!