Integ 1
Integ 1
basic digital % differentiator using the backward difference method. % % What it does: This function takes an input
signal (a vector) and a % differentiation gain as input. It approximates the derivative of the % input signal over time
using a discrete-time approximation. % % Theory: Differentiation in continuous time is represented by the derivative: %
% y(t) = dx(t) / dt % % In the discrete-time domain, this can be approximated using numerical % methods. The
backward difference method approximates the derivative at % time step n as: % % y[n] ≈ gain * (x[n] - x[n-1]) % %
where 'gain' is often related to the inverse of the sampling interval % (if the input is sampled at a constant rate). This is
a simple first-order % approximation of the continuous-time derivative. The output at each time % step is proportional
to the difference between the current and previous % input samples.
if ~isvector(input_signal)
error('Input signal must be a vector.');
end
output_signal = zeros(size(input_signal));
% The derivative at the first point is not well-defined using backward difference
output_signal(1) = 0; % Or can use forward difference for the first point
if ~isvector(input_signal)
error('Input signal must be a vector.');
end
output_signal = zeros(size(input_signal));
output_signal(1) = initial_condition;
for i = 2:length(input_signal)
output_signal(i) = output_signal(i - 1) + gain * input_signal(i);
end
end
% Example usage: time = 0:0.1:10; ramp_signal = time; integration_gain = 0.1; % Corresponds to the sampling interval
in this case initial_value = 0; integrated_signal = basic_digital_integrator(ramp_signal, integration_gain, initial_value);
figure; subplot(2, 1, 1); plot(time, ramp_signal); xlabel('Time'); ylabel('Input Signal (Ramp)'); title('Input Signal'); grid
on;
end
% Example usage: time = 0:0.1:10; parabola_signal = time.^2; differentiation_gain = 10; % Corresponds to the inverse
of the sampling interval differentiated_signal = basic_differentiator(parabola_signal, differentiation_gain);
figure; subplot(2, 1, 1); plot(time, parabola_signal); xlabel('Time'); ylabel('Input Signal (Parabola)'); title('Input Signal');
grid on;