Added comments
This commit is contained in:
parent
f241f1d616
commit
9d49868c0d
@ -9,11 +9,14 @@ function x = generate_heartbeat(amplitude, frequency, phase, fs, duration, duty)
|
|||||||
% phase shift is in number of periods
|
% phase shift is in number of periods
|
||||||
% fs is the sampling frequency: how many sample points per second
|
% fs is the sampling frequency: how many sample points per second
|
||||||
% duration is time in seconds
|
% duration is time in seconds
|
||||||
% duty cycle should be a number between 0 and 1.
|
% duty cycle should be a number between 0 and 0.5.
|
||||||
% duty of 0 or less would return -amplitude for all sample points
|
% duty of 0 or less would return 0 for all sample points
|
||||||
% duty of 0.25 would return +amplitude for first quarter of each cycle
|
% duty of 0.5 or less would return a heartbeat signal since there would be
|
||||||
% then return -amplitude for the remaining three-fourths
|
% equal amount of space within 1 period to have the right and left sides be equal
|
||||||
% duty of 1 would return all +amplitude
|
% duty of greater than 0.5 but less than 1 would return a slope starting at that duty i.e.
|
||||||
|
% the left side but leaving little room to the right side
|
||||||
|
% duty of between 1 and 2 would give a sawtooth wave in the +amplitude.
|
||||||
|
% duty greater than 2 would return 0 for all sample points
|
||||||
|
|
||||||
|
|
||||||
% initialize local variables from input arguments
|
% initialize local variables from input arguments
|
||||||
@ -29,11 +32,11 @@ function x = generate_heartbeat(amplitude, frequency, phase, fs, duration, duty)
|
|||||||
t = i * dt; % time at the i'th sample
|
t = i * dt; % time at the i'th sample
|
||||||
st = mod(frequency * t - phase, 1);
|
st = mod(frequency * t - phase, 1);
|
||||||
|
|
||||||
if (duty-0.25 < st && st < duty)
|
if (duty-(duty / 2) < st && st < duty)
|
||||||
slope = amplitude / duty;
|
slope = amplitude / duty;
|
||||||
intercept = -0.5 * amplitude;
|
intercept = -0.5 * amplitude;
|
||||||
x(i) = slope * st + intercept;
|
x(i) = slope * st + intercept;
|
||||||
elseif (duty < st && st < duty+0.25)
|
elseif (duty < st && st < duty+(duty / 2))
|
||||||
slope = amplitude / duty;
|
slope = amplitude / duty;
|
||||||
intercept = -amplitude;
|
intercept = -amplitude;
|
||||||
x(i) = slope * st + (1.5 * intercept);
|
x(i) = slope * st + (1.5 * intercept);
|
||||||
|
Reference in New Issue
Block a user