How to add ramping in sin function

3 views (last 30 days)
RAHUL DOGRA
RAHUL DOGRA on 22 Nov 2021
Commented: Mathieu NOE on 23 Nov 2021
I want to add ramping in sin function for first few mili seconds as shown in figure (red wave) how can I do that. I was trying to plot direct sine function but I am not able to get any ramping. I want to create a dynamic laoding of 5 m/sec2 having a frequency of 20 Hz.
right now i am doing this:
t = 0:0.001:1;
x = 5*sin((125.66)*t);
plot(t,x)

Accepted Answer

Mathieu NOE
Mathieu NOE on 22 Nov 2021
hello
see my little demo below :
clc
clearvars
% signal
Fs = 100;
dt= 1 /Fs;
samples = 1e3;
freq = 10;
t = (0:samples-1)*dt;
x = 3*sin(2*pi*freq*t);
%% create a window (ramp of given slope)
% ascending ramp
t0 = 1; % start time of ramp
t1 = 2; % stop time of ramp
window = zeros(1,length(t));
ind = find(t>=t0 & t<= t1);
tmp = linspace(0,1,length(ind));
window(ind) = tmp;
window(t>t1) = 1;
% descending ramp
t2 = 6; % start time of ramp
t3 = 8; % stop time of ramp
ind = find(t>=t2 & t<= t3);
tmp = linspace(1,0,length(ind));
window(ind) = tmp;
window(t>t3) = 0;
% windowed signal
xw = x.*window;
plot(t,xw)
  2 Comments
Mathieu NOE
Mathieu NOE on 23 Nov 2021
My pleasure !
would you mind accepting my answer ?
tx

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!