From 9d045f18110fc4c8e5f21d3d9356932914d2bb94 Mon Sep 17 00:00:00 2001 From: adesens <83106965+adesens@users.noreply.github.com> Date: Fri, 10 Dec 2021 21:03:18 -0800 Subject: [PATCH] Create lfo_square --- src/LFO/lfo_square | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/LFO/lfo_square diff --git a/src/LFO/lfo_square b/src/LFO/lfo_square new file mode 100644 index 0000000..8480ebc --- /dev/null +++ b/src/LFO/lfo_square @@ -0,0 +1,37 @@ +function x = lfo_square(amplitude, frequency, phase, fs, duration, input) +% LFO_SQUARE: modulates an input matrix to a square + +% CONTRIBUTORS: +% Aleksandra Desens: Author + +% DOCUMENTATION: +% phase shift is in number of periods +% fs is the sampling frequency - below 20 Hz +% duration - 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 a one dimensional zero matrix to be populated + lfo = zeros(1, n); + + % populate the matrix + for i = 1:n + + t = i * dt; + duty = 0.5; % duty of 0.5 generates a square wave + + st = mod((frequency * t - phase), 1); + + if (st < duty) + lfo(i) = amplitude; + else + lfo(i) = -amplitude; + + end + + % modulate input + x = lfo .* input; + +end