create Continuous sine wave with fixed frequency
31 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Dana
on 4 Sep 2020
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 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!