Reorganized Into Folders

This commit is contained in:
Darell Chua Yun Da
2021-12-10 10:01:30 +08:00
parent 88f77fed35
commit f856cdcd2b
41 changed files with 53 additions and 4 deletions

37
src/LFO/lfo_sawtooth.m Normal file
View File

@@ -0,0 +1,37 @@
function x = lfo_sawtooth(amplitude, frequency, phase, fs, duration, input)
% LFO_SAWTOOTH: modulates an input matrix to a sawtooth parameter
% CONTRIBUTORS:
% Ben Zhang: Function Author
% DOCUMENTATION:
% frequency is below 20Hz for people to hear the sound
% fs and duration should be same as input
% 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 lfo, which will be used to modulate the input
lfo = zeros(1, n);
period = 1 / frequency; % period of the wave
slope = 2 * amplitude / period; % the incline slope from start to amplitude
% populate lfo matrix
for i = 1:n
t = i * dt; % time at the i'th sample
st = mod(frequency * t - phase, 1); % Progression through cycle
%part before the straght vertical line
if(st < period /2)
lfo(i) = amplitude * slope;
%part after the straght vertical line
else
lfo(i) = amplitude * (slope - 1);
end
% modulate input
x = lfo .* input;
end

29
src/LFO/lfo_sine.m Normal file
View File

@@ -0,0 +1,29 @@
function x = lfo_sine(amplitude, frequency, phase, fs, duration, input)
% LFO_SINE: modulates an input matrix
% CONTRIBUTORS:
% Benjamin Liou: Original author
% DOCUMENTATION:
% frequency is typically below 20Hz (according to wikipedia)
% fs and duration should be same as input
% 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 lfo, which will be used to modulate the input
lfo = zeros(1, n);
% populate lfo matrix
for i = 1:n
t = i * dt; % time at the i'th sample
lfo(i) = amplitude * sin(2 * pi * frequency * t - phase);
end
% modulate input
x = lfo .* input;
end