LPF DF 1
LPF DF 1
% Define filter coefficients (example - can be obtained from design methods) b = [0.02, 0.06, 0.09, 0.06, 0.02]; %
Numerator coefficients (feedforward) a = [1, -2.1, 1.8, -0.5, 0.05]; % Denominator coefficients (feedback)
% Initialize output signal and delay lines output_signal = zeros(size(input_signal)); x_delay = zeros(length(b) - 1, 1); %
Delay line for input y_delay = zeros(length(a) - 1, 1); % Delay line for output
% Implement the Direct Form I filter for n = 1:length(input_signal) % Calculate the output y_n = b(1) * input_signal(n);
for k = 2:length(b) y_n = y_n + b(k) * x_delay(k - 1); end for k = 2:length(a) y_n = y_n - a(k) * y_delay(k - 1); end
output_signal(n) = y_n;
end
% Plot the input and output signals figure; subplot(2, 1, 1); plot(t, input_signal); xlabel('Time (s)'); ylabel('Input Signal');
title('Input Signal'); grid on;
subplot(2, 1, 2); plot(t, output_signal); xlabel('Time (s)'); ylabel('Output Signal'); title('Output of Low-Pass Filter'); grid
on;
% Theory: This code implements a digital Infinite Impulse Response (IIR) % low-pass filter using the Direct Form I
structure. IIR filters use both % past input values (feedforward terms, coefficients 'b') and past output % values
(feedback terms, coefficients 'a') to compute the current output. % The Direct Form I structure is a straightforward
implementation of the % filter's difference equation. The filter coefficients 'b' and 'a' determine % the filter's frequency
response characteristics (cutoff frequency, roll-off, % etc.) and are typically obtained through filter design techniques
(e.g., % Butterworth, Chebyshev). The delay lines store past input and output samples % needed for the filter
calculation at each time step.