Added documentation

This commit is contained in:
Neelay Joglekar 2021-12-10 16:57:21 -08:00
parent 079800ac25
commit b27aef78a9

View File

@ -5,11 +5,13 @@ function output = lfo_freq_sine(amplitude, frequency, phase, fs, duration, input
% Neelay Joglekar: Original author
% SOURCES:
% Code based off of Benjamin Liou's functions (lfo_sine)
% Code inspired by Benjamin Liou's lfo functions
% Code also inspired by Darren and Anne's pitch envelopes
% Source for frequency modulation equation:
% https://dsp.stackexchange.com/questions/2349/help-with-algorithm-for-modulating-oscillator-pitch-using-lfo
% DOCUMENTATION:
% Frequency is modulated by 20 semitones (20 above, 20 below)
% Frequency is modulated by sine wave with given amplitude (in octaves, not Hz)
% initialize local variables from input arguments
n = fs * duration; % number of samples (length of matrix)
@ -18,12 +20,17 @@ function output = lfo_freq_sine(amplitude, frequency, phase, fs, duration, input
% create output array
output = zeros([1, n]);
x = 0.0; % theoretical input index, assuming input not discrete
x = 0.0; % the theoretical input index if the input were not discrete
% populate output
for i = 1:n
t = i * dt; % time at the i'th sample
omega_ratio = 2 ^ (20/12 * sin(2 * pi * frequency * t - phase));
% Increment x based off of sine wave output
omega_ratio = 2 ^ (amplitude * sin(2 * pi * frequency * t - phase));
x = mod(x + omega_ratio, n);
% Linearly interpolate the actual indicies adjacent to x
% to get an output value
x_0 = floor(x) + 1;
x_1 = mod(x_0 + 1, n) + 1;
output(i) = (input(x_1) - input(x_0)) * (x - x_0) + input(x_0);