0% found this document useful (0 votes)
4 views1 page

Integ 1

The document describes two functions: a basic digital differentiator and a basic digital integrator, both implemented using discrete-time numerical methods. The differentiator uses the backward difference method to approximate the derivative of an input signal, while the integrator employs the forward Euler method to approximate the integral. Example usage for both functions is provided, demonstrating their application on ramp and parabola signals.

Uploaded by

copeyic220
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Integ 1

The document describes two functions: a basic digital differentiator and a basic digital integrator, both implemented using discrete-time numerical methods. The differentiator uses the backward difference method to approximate the derivative of an input signal, while the integrator employs the forward Euler method to approximate the integral. Example usage for both functions is provided, demonstrating their application on ramp and parabola signals.

Uploaded by

copeyic220
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

function output_signal = basic_differentiator(input_signal, gain) % basic_differentiator(input_signal, gain) implements a

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

function output_signal = basic_digital_integrator(input_signal, gain, initial_condition) %


basic_digital_integrator(input_signal, gain, initial_condition) implements % a basic digital integrator using the forward
Euler method. % % What it does: This function takes an input signal (a vector), an integration % gain, and an initial
condition as input. It approximates the integral of % the input signal over time using a discrete-time approximation. %
% Theory: Integration in continuous time is represented by the integral: % % y(t) = ∫ x(τ) dτ % % In the discrete-time
domain, this can be approximated using numerical % methods. The forward Euler method approximates the integral as
a summation: % % y[n] ≈ y[n-1] + gain * x[n] % % where 'gain' represents the scaling factor related to the sampling
interval % (if the input is sampled at a constant rate). This is a simple first-order % approximation of the continuous-
time integral. The output at each time step % is the sum of the previous output and the scaled current input.

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;

subplot(2, 1, 2); plot(time, integrated_signal); xlabel('Time'); ylabel('Output Signal (Approximation of Integral)');


title('Output of Basic Digital Integrator'); grid on; for i = 2:length(input_signal) output_signal(i) = gain * (input_signal(i)
- input_signal(i - 1)); end

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;

subplot(2, 1, 2); plot(time, differentiated_signal); xlabel('Time'); ylabel('Output Signal (Approximation of Derivative)');


title('Output of Basic Digital Differentiator'); grid on;

You might also like