Fix the equation for generating sawtooth wave
fix the equation for generating sawtooth wave
This commit is contained in:
parent
74978464b5
commit
d2e2bac659
@ -20,19 +20,22 @@ function x = generate_sawtooth(amplitude, frequency, phase, fs, duration, duty)
|
|||||||
% initialize a one dimensional zero matrix to be populated
|
% initialize a one dimensional zero matrix to be populated
|
||||||
x = zeros(1, n);
|
x = zeros(1, n);
|
||||||
|
|
||||||
|
|
||||||
% populate the matrix
|
% populate the matrix
|
||||||
for i = 1:n
|
for i = 1:n
|
||||||
t = i * dt; % time of the i'th sample
|
t = i * dt; % time of the i'th sample
|
||||||
st = mod(frequency * t - phase, 1); % Progression through cycle
|
st = mod(frequency * t - phase, 1); % Progression through cycle
|
||||||
|
|
||||||
slope = 2 * amplitude / period; % the incline slope from start to amplitude
|
slope = 2 * amplitude / period; % the incline slope from start to amplitude
|
||||||
|
mid = period / 2;
|
||||||
|
|
||||||
%part before the straght vertical line
|
%part before the straght vertical line
|
||||||
if(st < period /2)
|
if(st < mid)
|
||||||
x(i) = slope * st;
|
x(i) = slope * st;
|
||||||
|
|
||||||
%part after the straght vertical line
|
%part after the straght vertical line
|
||||||
else
|
else
|
||||||
x(i) = slope * st - amplitude;
|
x(i) = slope * (st - 0.5) - amplitude;
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
Reference in New Issue
Block a user