How can I create sine wave with varying amplitude between certain range?

47 views (last 30 days)
I am trying to create a sine wave with varying amplitude. I am using a function for amplitude i.e., sqrt(t) where t is the time stamps. This is creating a sine wave with smoothly increasing amplitude. But I want amplitude to vary between certain range keeping the frequency same. For example, between 1 and 5. Below is the code which I wrote.
fs = 2560; % Sampling frequency
dt = 1/fs; % seconds per sample
StopTime = 5; % seconds
t = (0:dt:StopTime)'; % seconds
F = 20; % Sine wave frequency (hertz)
amp = sqrt(t);
data = amp.*sin(2*pi*F*t);
figure(1);clf(1);
plot(t,data);
title('Sine Wave');
What should be the function of amplitude in order to achieve varying amplitude?
  3 Comments
Subham Sutaria
Subham Sutaria on 11 Dec 2020
I want amplitude to linearly vary between 1 and 5.
I used linspace function and it worked.
Thanks for replying.
RAHUL DOGRA
RAHUL DOGRA on 22 Nov 2021
I want an increased sine function than make it constant after some particular value how can I do that?

Sign in to comment.

Accepted Answer

VBBV
VBBV on 9 Dec 2020
%if
amp = 1:2:5;
data = amp.*abs(sin(2*pi*F*t))
Use abs to plot only the fixed amplitude range
  1 Comment
Subham Sutaria
Subham Sutaria on 10 Dec 2020
Thank you for the reply. it worked. But I wanted more like a single sine wave with varying ampltiude, not multiple sine waves. Is it possible?

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!