How to add ramping in sin function

43 次查看(过去 30 天)
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)

采纳的回答

Mathieu NOE
Mathieu NOE 2021-11-22
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 个评论
RAHUL DOGRA
RAHUL DOGRA 2021-11-23
thanks alot sir. it will really help me.
Mathieu NOE
Mathieu NOE 2021-11-23
My pleasure !
would you mind accepting my answer ?
tx

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by