From 3336c2923ed155b4e66ba43764cf44333099cecf Mon Sep 17 00:00:00 2001 From: Neelay Joglekar Date: Fri, 10 Dec 2021 16:07:51 -0800 Subject: [PATCH] Seems to work --- src/lfo_freq_sine.m | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/lfo_freq_sine.m diff --git a/src/lfo_freq_sine.m b/src/lfo_freq_sine.m new file mode 100644 index 0000000..3fc4273 --- /dev/null +++ b/src/lfo_freq_sine.m @@ -0,0 +1,32 @@ +function output = lfo_freq_sine(amplitude, frequency, phase, fs, duration, input) +%LFO_FREQ_SINE Modulates the frequency of an input with a sine LFO + +% CONTRIBUTORS: +% Neelay Joglekar: Original author + +% SOURCES: +% Code based off of Benjamin Liou's functions (lfo_sine) +% 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) + + % 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 + + % create output array + output = zeros([1, n]); + + x = 0.0; % theoretical input index, assuming input 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)); + x = mod(x + omega_ratio, n); + 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); + end +end +