You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Generate the following signals in Simulink
3 views (last 30 days)
Show older comments
Good evening Matlab community. I am a bit new to simulink. I would like to know how to plot the function x(t)= 5*cos(30*pi*t+0.25*pi) using blocks. My attempt is below: but the output is all wrong. How do I plot this function? Am I supposed to use a constant source? the contents of my function block is in the other pic. I want a clear xy plot in the scope. Or do I use the xy plot block? I would appreciate any guidance thank you!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/160278/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/160279/image.jpeg)
19 Comments
Purushottama Rao
on 31 Jan 2017
Are u intended to use sine wave as the input for the function?? I feel that you are looking for a some kind of sine func defined by y. In that case 'u' should be time and a linearly increasing. Use a clock instead of a sine wave as the input to the function.
Aaron Connell
on 31 Jan 2017
I see that worked thank you! How can I reduce the frequency of the output? is it a clock parameter or something that I set int he function block?
Aaron Connell
on 31 Jan 2017
cause it cycles far too many times per second than I would like. I would want one cycle per second
Aaron Connell
on 31 Jan 2017
I figured out how to zoom, but now the maximas and minimas look jagged or blocky...assuming this is numerical approximation? How can I smoth them?
Purushottama Rao
on 31 Jan 2017
Edited: Purushottama Rao
on 31 Jan 2017
you can go for more sampling time by discretizing the model. Use a power gui block to do so.
Aaron Connell
on 31 Jan 2017
Unsure how to do that. Would adding a zero order hold help?
Purushottama Rao
on 31 Jan 2017
Include a powergui block in your model from library. In the powergui parameters, change the model to dicrete model and enter the sampling time such as 5e-5 or so.
Aaron Connell
on 31 Jan 2017
didn't work, did I do it right?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/185741/image.jpeg)
Purushottama Rao
on 31 Jan 2017
can u attach ur model??
Aaron Connell
on 31 Jan 2017
it wont let me attach a .slx file
Aaron Connell
on 31 Jan 2017
hold on let me dropbox it with a url
Aaron Connell
on 31 Jan 2017
Edited: Aaron Connell
on 31 Jan 2017
It is question 2 specifically, same issue for those two signals
Purushottama Rao
on 31 Jan 2017
Edited: Purushottama Rao
on 31 Jan 2017
I was trying to replicate your model here. One trick for your problem is to use a gain block with unit gain in front of the function and Set the sampling time to the value entered in powergui.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/185745/image.png)
Aaron Connell
on 31 Jan 2017
okay let me try it out hold on, and thank you so much for your help!
Aaron Connell
on 31 Jan 2017
added the gain block, so set the sampling time in which block?
Purushottama Rao
on 31 Jan 2017
Edited: Purushottama Rao
on 31 Jan 2017
set the sampling time in the gin block parmeter.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/185747/image.png)
Aaron Connell
on 31 Jan 2017
ahh! My gain block does not have a sampling section underneath multiplication
Purushottama Rao
on 31 Jan 2017
Edited: Purushottama Rao
on 31 Jan 2017
You can also use a zero order hold block in the same way. Dont forget to change the sampling time.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/185749/image.png)
Aaron Connell
on 31 Jan 2017
That did it! Thank you!!!!!
Accepted Answer
Purushottama Rao
on 31 Jan 2017
Use a clock as an input in place of sine wave. To reduce the number of cycles you need to modify the function y. If you are looking for 1 cycle/second then use a function similar to y= 5*cos(2*pi*u+0.25*pi)
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)