create Continuous sine wave with fixed frequency
17 次查看(过去 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? ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/356215/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/356215/image.png)
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 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!