Plot sin or cosine with Simulink scope

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

 采纳的回答

Javier
Javier 2015-3-25
编辑:Javier 2015-3-25
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

更多回答(1 个)

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 个评论

Hi Sebastian,
I don't understand enterely what you explain in point 2, what is fs for you?. I can now understand that simulink is taking the 40s as Ts, therefore if I want to avoid the aliasing I have to be compliant with
fs>=2*fo or Ts<(To/2) where To=1/(2*fo)=2.5e-7s with fo=2e6
I have set as Max time step To=2.5e-7 and now the simulation seems to take forever, and I am not able to see any signal
What am I doing again wrong?
Thanks in advance,
regards
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
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.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by