How to do a damped sine wave

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

Whitespaceisfree.Pleasehavepityonthepeoplewhohavetoreadyourcode.

Hi Walter!
I laughed out loud when I read your comment!
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.

Sign in to comment.

Answers (1)

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

Asked:

on 16 Feb 2016

Commented:

on 8 Aug 2017

Community Treasure Hunt

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

Start Hunting!