How to do a damped sine wave
Show older comments
Hi I am trying to do a damped sine wave, but my program is not working. Can someone please tell me what I am doing wrong? Here is my code.
A=10;f=1000;n=5;T=1/f;t=[0:T/100:n*T];s=A*exp(-t).*sin(2*pi*f*t);
plot(t,s)
3 Comments
Walter Roberson
on 16 Feb 2016
Whitespaceisfree.Pleasehavepityonthepeoplewhohavetoreadyourcode.
Star Strider
on 17 Feb 2016
Hi Walter!
I laughed out loud when I read your comment!
jay shah
on 8 Aug 2017
Hi. Include some constant in "exp(-t)" part of your function. Make it like exp(-B.*t) and choose B = 1000 or any other value depending on how much damping you want.
Answers (1)
Star Strider
on 16 Feb 2016
Please describe ‘not working’.
It runs without error for me, and plots the appropriate sine curve. If it’s not damping quickly enough for you, multiply the ‘-t’ in the exponential by some constant (here 1000). Change the constant to produce the result you want.
For example:
A=10;f=1000;n=5;T=1/f;t=[0:T/100:n*T];s=A*exp(-t*1000).*sin(2*pi*f*t);
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!