create Continuous sine wave with fixed frequency

11 ビュー (過去 30 日間)
Dimitrios Topouridis
Dimitrios Topouridis 2020 年 9 月 4 日
回答済み: Dana 2020 年 9 月 4 日
Hi,
i want to create a contiuous sine wave, with a frequency of 0.2Hz.
I want the wave to start when the x-axis is at 200. Now i wrote some code but i want to expand the time of an oscillation from 5s. to something else. how do i do that?
speed = 27.8;
straighttime= 5560/speed;
step=2;
time = 0:step:1200;
waypointsdata=0.2*sin(2*pi*0.2*time);
transpose(time);
transpose(waypointsdata);
waypointmarkers = [time;waypointsdata]';
if straighttime >0
strike = round(ceil(straighttime)/step);
waypointmarkers(1:strike,2)=0;
end
waypoints(:,[1,2]) = waypointmarkers;
waypoints(:,3)=zeros;
plot(time,waypoints(:,2)) , grid on

採用された回答

Dana
Dana 2020 年 9 月 4 日
freq = 0.2; % freqeuency of sine wave (pick whatever you want)
T0 = 200; % period sine wave starts
T1 = 240; % period sine wave stops
smprt = 20; % Sampling rate (plotting points per period of the sine wave).
% If this is too low, the plot won't look right.
t = linspace(T0,T1,ceil((T1-T0)*freq*smprt)); % sampling times
x = sin(2*pi*freq*t); % sine wave value
% pad t and x with an initial zero to start plot at (0,0); we'll cut the
% plot off later
t = [0,t];
x = [0,x];
figure(1)
clf
plot(t,x)
xlim([175,242]) % set the x-axis limits (roughly what you had in your fig.)

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by