Documentation |
This example shows how to use the slew rate as an estimate of the rising and falling slopes of a triangular waveform. Create three triangular waveforms. One waveform has rising-falling slopes of +/- 2, one waveform has rising-falling slopes of +/- 1/2, and one waveform has a rising slope of +2 and a falling slope of -1/2. Use slewrate to find the slopes of the waveforms.
Create a triangular waveform with rising-falling slopes of +/- 2. Set the sampling interval to 0.01 seconds, which corresponds to a sampling frequency of 100 hertz.
t = 0:0.01:1; x = 2*t; x = [x fliplr(x)]; tnew = [t t+1.01]; plot(tnew,x); xlabel('Time'); ylabel('Amplitude');
Calculate the slew rate for the triangular waveform. Input the sampling frequency (100 Hz) to obtain the correct positive and negative slope values.
s = slewrate(x,100)
Create a triangular waveform with slopes of +/- 1/2. Set the sampling interval to 0.01 seconds, which corresponds to a sampling frequency of 100 hertz.
t = 0:0.01:1; x = 1/2*t; x = [x fliplr(x)]; tnew = [t t+1.01]; plot(tnew,x); xlabel('Time'); ylabel('Amplitude');
Calculate the slew rate for the triangular waveform. Input the sampling frequency (100 Hz) to obtain the correct positive and negative slope values.
s = slewrate(x,100)
Create a triangular waveform with a rising slope of +2 and a falling slope of -1/2. Set the sampling increment to 0.01 seconds, which corresponds to a sampling frequency of 100 hertz.
t = 0:0.01:1; x = 2*t; t1 = 1:0.01:5; x1 = -1/2*(t1-1)+2; y = [x x1]; tnew = [t t1]; plot(tnew,y); xlabel('Time'); ylabel('Amplitude');
Determine the slew rate.
s = slewrate(y,100)
The first element of s is the rising slope and the second element is the falling slope.