implemented all remaining generator functions
This commit is contained in:
25
src/Generators/generate_cosine.m
Normal file
25
src/Generators/generate_cosine.m
Normal file
@@ -0,0 +1,25 @@
|
||||
function x = generate_cosine(amplitude, frequency, phase, fs, duration, duty)
|
||||
% GENERATE_WAVENAME: returns a matrix of sampled WAVENAME wave
|
||||
|
||||
% CONTRIBUTORS:
|
||||
% Mekhi Ellington: Original Creator
|
||||
|
||||
% DOCUMENTATION:
|
||||
% phase shift is in number of periods
|
||||
% fs is the sampling frequency: how many sample points per second
|
||||
% duration is time in seconds
|
||||
% duty is a number between 0 and 1
|
||||
|
||||
% initialize local variables from input arguments
|
||||
n = fs * duration; % number of samples (length of matrix)
|
||||
dt = 1 / fs; % sampling period: time between two sample points
|
||||
|
||||
% initialize a one dimensional zero matrix to be populated
|
||||
x = zeros(1, n);
|
||||
|
||||
% populate the matrix
|
||||
for i = 1:n
|
||||
t = i * dt;
|
||||
x(i) = amplitude * cos(2*pi*frequency*t-phase);
|
||||
end
|
||||
end
|
46
src/Generators/generate_heartbeat.m
Normal file
46
src/Generators/generate_heartbeat.m
Normal file
@@ -0,0 +1,46 @@
|
||||
function x = generate_heartbeat(amplitude, frequency, phase, fs, duration, duty)
|
||||
% GENERATE_SINE: returns a matrix of sampled heart monitor wave
|
||||
|
||||
% CONTRIBUTORS:
|
||||
% Alex Nguyen: Original Author
|
||||
% Conner Hsu: Reviewed Code and Assisted in polishing
|
||||
|
||||
% DOCUMENTATION:
|
||||
% phase shift is in number of periods
|
||||
% fs is the sampling frequency: how many sample points per second
|
||||
% duration is time in seconds
|
||||
% duty cycle should be a number between 0 and 0.5.
|
||||
% duty of 0 or less would return 0 for all sample points
|
||||
% duty of 0.5 or less would return a heartbeat signal since there would be
|
||||
% equal amount of space within 1 period to have the right and left sides be equal
|
||||
% 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
|
||||
n = fs * duration; % number of samples (length of matrix)
|
||||
dt = 1 / fs; % sampling period: time between two sample points
|
||||
|
||||
|
||||
% initialize a one dimensional zero matrix to be populated
|
||||
x = zeros(1, n);
|
||||
|
||||
% populate the matrix
|
||||
for i = 1:n
|
||||
t = i * dt; % time at the i'th sample
|
||||
st = mod(frequency * t - phase, 1);
|
||||
|
||||
if (duty-(duty / 2) < st && st < duty)
|
||||
slope = amplitude / duty;
|
||||
intercept = -0.5 * amplitude;
|
||||
x(i) = slope * st + intercept;
|
||||
elseif (duty < st && st < duty+(duty / 2))
|
||||
slope = amplitude / duty;
|
||||
intercept = -amplitude;
|
||||
x(i) = slope * st + (1.5 * intercept);
|
||||
else
|
||||
x(i) = 0;
|
||||
end
|
||||
end
|
55
src/Generators/generate_trapezoid.m
Normal file
55
src/Generators/generate_trapezoid.m
Normal file
@@ -0,0 +1,55 @@
|
||||
function x = generate_trapezoid(amplitude, frequency, phase, fs, duration, duty)
|
||||
% GENERATE_TRAPEZOID: returns a matrix of sampled square wave
|
||||
|
||||
% CONTRIBUTORS:
|
||||
% Daniel Doan: Author
|
||||
|
||||
% DOCUMENTATION:
|
||||
% phase shift is in number of periods
|
||||
% fs is the sampling frequency: how many sample points per second
|
||||
% duration is time in seconds
|
||||
% duty cycle should be a number between 0 and 1.
|
||||
% duty of 0.5 would have 2 trapezoids in first half of each cycle
|
||||
% example of wave with duty of 0.5, where the peaks are amplitude/2:
|
||||
%
|
||||
% ____
|
||||
% / \
|
||||
% / \ ________________
|
||||
% \ /
|
||||
% \____/
|
||||
%
|
||||
|
||||
|
||||
|
||||
% initialize local variables from input arguments
|
||||
n = fs * duration; % number of samples (length of matrix)
|
||||
dt = 1 / fs; % sampling period: time between two sample points
|
||||
|
||||
% initialize a one dimensional zero matrix to be populated
|
||||
x = zeros(1, n);
|
||||
|
||||
% populate the matrix
|
||||
for i = 1:n
|
||||
t = i * dt;
|
||||
|
||||
% periodic ramp from 0 to 1
|
||||
% progression through a cycle
|
||||
st = mod(frequency * t - phase, 1);
|
||||
slope = (amplitude/2) / (duty/8);
|
||||
if(st < duty)
|
||||
if(st < duty/8 || st > 7*duty/8)
|
||||
x(i) = slope * st;
|
||||
else
|
||||
if(st < 5*duty/8)
|
||||
x(i) = amplitude/2 - slope * (st-(3*duty/8));
|
||||
end
|
||||
if(st < 3*duty/8)
|
||||
x(i) = amplitude/2;
|
||||
end
|
||||
if(st > 5*duty/8)
|
||||
x(i) = -amplitude/2;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user