From d2e2bac65973c9528c95cab68415ed6c27037000 Mon Sep 17 00:00:00 2001 From: Ben Zhang <2690287331@qq.com> Date: Sun, 5 Dec 2021 20:53:41 -0800 Subject: [PATCH] Fix the equation for generating sawtooth wave fix the equation for generating sawtooth wave --- src/generate_sawtooth.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/generate_sawtooth.m b/src/generate_sawtooth.m index 61fd0da..3886e99 100644 --- a/src/generate_sawtooth.m +++ b/src/generate_sawtooth.m @@ -20,19 +20,22 @@ function x = generate_sawtooth(amplitude, frequency, phase, fs, duration, duty) % initialize a one dimensional zero matrix to be populated x = zeros(1, n); + % populate the matrix for i = 1:n t = i * dt; % time of the i'th sample st = mod(frequency * t - phase, 1); % Progression through cycle slope = 2 * amplitude / period; % the incline slope from start to amplitude + mid = period / 2; + %part before the straght vertical line - if(st < period /2) + if(st < mid) x(i) = slope * st; %part after the straght vertical line else - x(i) = slope * st - amplitude; + x(i) = slope * (st - 0.5) - amplitude; end -end \ No newline at end of file +end