From 2152d2a8e3b6c6f17502f205d689dc590cad07f7 Mon Sep 17 00:00:00 2001 From: bliou000 <95387384+bliou000@users.noreply.github.com> Date: Sat, 4 Dec 2021 16:28:11 -0800 Subject: [PATCH] LFO based on generate_sine() code --- lfo_sine.m | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lfo_sine.m diff --git a/lfo_sine.m b/lfo_sine.m new file mode 100644 index 0000000..a9acbdb --- /dev/null +++ b/lfo_sine.m @@ -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 \ No newline at end of file