fixed generate_trapezoid

This commit is contained in:
Daniel Doan 2021-12-11 12:00:02 -08:00
parent fa14d13430
commit 5aa770b541

View File

@ -37,19 +37,22 @@ function x = generate_trapezoid(amplitude, frequency, phase, fs, duration, duty)
st = mod(frequency * t - phase, 1); st = mod(frequency * t - phase, 1);
slope = (amplitude/2) / (duty/8); slope = (amplitude/2) / (duty/8);
if(st < duty) if(st < duty)
if(st < duty/8 || st > 7*duty/8) if(st <= duty/8)
x(i) = slope * st; x(i) = slope * st;
else else
if(st < 5*duty/8) if(st <= 5*duty/8)
x(i) = amplitude/2 - slope * (st-(3*duty/8)); x(i) = amplitude/2 - slope * (st-(3*duty/8));
end end
if(st < 3*duty/8) if(st <= 3*duty/8)
x(i) = amplitude/2; x(i) = amplitude/2;
end end
if(st > 5*duty/8) if(st >= 5*duty/8)
x(i) = -amplitude/2; x(i) = -amplitude/2;
end end
end end
if(st >= 7* duty/8)
x(i) = -amplitude/2 + slope*(st-(7*duty/8));
end
end end
end end
end end