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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by