Added documentation
This commit is contained in:
parent
079800ac25
commit
b27aef78a9
@ -5,11 +5,13 @@ function output = lfo_freq_sine(amplitude, frequency, phase, fs, duration, input
|
|||||||
% Neelay Joglekar: Original author
|
% Neelay Joglekar: Original author
|
||||||
|
|
||||||
% SOURCES:
|
% 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
|
% https://dsp.stackexchange.com/questions/2349/help-with-algorithm-for-modulating-oscillator-pitch-using-lfo
|
||||||
|
|
||||||
% DOCUMENTATION:
|
% 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
|
% initialize local variables from input arguments
|
||||||
n = fs * duration; % number of samples (length of matrix)
|
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
|
% create output array
|
||||||
output = zeros([1, n]);
|
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
|
% populate output
|
||||||
for i = 1:n
|
for i = 1:n
|
||||||
t = i * dt; % time at the i'th sample
|
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);
|
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_0 = floor(x) + 1;
|
||||||
x_1 = mod(x_0 + 1, n) + 1;
|
x_1 = mod(x_0 + 1, n) + 1;
|
||||||
output(i) = (input(x_1) - input(x_0)) * (x - x_0) + input(x_0);
|
output(i) = (input(x_1) - input(x_0)) * (x - x_0) + input(x_0);
|
||||||
|
Reference in New Issue
Block a user