20 lines
468 B
Matlab
20 lines
468 B
Matlab
function plotsine(freq, ampl, duration)
|
|
% plot a sine wave
|
|
% freq: frequency of the sinewave in Hertz
|
|
% ampl: amplitude of the sinewave
|
|
% duration: duration of the sinewave in seconds
|
|
step = 0.01/freq;
|
|
time = 0:step:duration;
|
|
sine = ampl*sin(2*pi*freq*time);
|
|
if duration <= 1.0
|
|
plot(1000.0*time, sine);
|
|
xlabel('Time [ms]');
|
|
else
|
|
plot(time, sine);
|
|
xlabel('Time [s]');
|
|
end
|
|
ylim([-1.2*ampl 1.2*ampl]);
|
|
ylabel('Sinewave');
|
|
title(sprintf('Frequency %g Hz', freq));
|
|
end
|