adding constant offset to sensor

11 ビュー (過去 30 日間)
Mat CR
Mat CR 2019 年 11 月 18 日
編集済み: Mat CR 2019 年 12 月 6 日
hello there
how can i add a constant offset to my sine wave( zero offset ), then be able to plot the sine wave i have added offset to on top of my original sine wave, i have atttched a picture of what i am talking about.

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 11 月 18 日
Is this?
a=0.5 % amplitude
f=5 % frequency
t=linspace(0,10,500);
acc=-4*a.*pi^2./f.^2 .* sin(2*pi./f .* t);
plot(t,acc,'linewidth',2);
hold on;
off_set=3;
acc=acc+off_set;
plot(t,acc,'g','linewidth',2);
grid on;
legend('Without Offset', 'With Offset 3V')
  2 件のコメント
Mat CR
Mat CR 2019 年 11 月 18 日
thank you very much for your answer
the answer is correct but i want to just use the accerleration with offset and then double intgrate using cumtrapz to obtain velocity and position, but when i plot my offset position it doesnt look anywhere near my real position even tho it has only 0.1 offset from integrating acceleration.
here is the code i used
a=0.5 % amplitude
f=5 % frequency
t=linspace(0,10,500);
v0 = a*(2*pi/f)*cos(2*pi/f*t(1)); % initial velocity
p0 = a*sin((2*pi)/f*t(1)); % initial position
acc= -4*a.*pi^2./f.^2 .* sin(2*pi./f .* t); % accleration data
off_set=0.1;
acc=acc+off_set;
figure (1)
plot(t,acc,'g','linewidth',2);
xlabel('Time (s)')
ylabel('amplitude')
title('accleration')
vel=cumtrapz(t,acc)+v0; % integrated velocity
pos=cumtrapz(t,vel)+p0 % intgrated positon
figure(2)
plot(t,pos,'r-') % plot the position
xlabel('Time (s)')
ylabel('amplitude')
title('offset position')
% what my real position look like real position
pos=a*sin((2*pi)/f*t) % intial position
plot(t,pos,'b-'); % plot for position
title(' real positon')
ylabel('amplitude')
xlabel('time(s)')
i would really appreciate any sort of help thank you
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 11 月 18 日
編集済み: KALYAN ACHARJYA 2019 年 11 月 18 日
I have answered based on original question. Hope the answer helped. Yes it can be, but it require longer time to debug your code.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by