create Continuous sine wave with fixed frequency

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