Merge pull request #60 from ltcptgeneral/trapezoid_fix

fixed generate_trapezoid
This commit is contained in:
Daniel Doan 2021-12-11 12:01:03 -08:00 committed by GitHub
commit 2efe0e9981
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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