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

LPF DF 1

The document provides a script for implementing a basic digital Low-Pass Filter using the Direct Form I structure, which includes defining filter coefficients and generating a sample input signal. It details the process of calculating the output signal by utilizing past input and output values, along with updating delay lines for the filter computation. Additionally, the script includes plotting the input and output signals to visualize the filter's effect.

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)
6 views1 page

LPF DF 1

The document provides a script for implementing a basic digital Low-Pass Filter using the Direct Form I structure, which includes defining filter coefficients and generating a sample input signal. It details the process of calculating the output signal by utilizing past input and output values, along with updating delay lines for the filter computation. Additionally, the script includes plotting the input and output signals to visualize the filter's effect.

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

% Script to implement a basic digital Low-Pass Filter (Direct Form I)

% 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)

% Generate a sample input signal (sum of two sinusoids) sampling_frequency = 100; % Hz t =


0:1/sampling_frequency:5; f1 = 5; f2 = 20; input_signal = sin(2pif1t) + 0.5sin(2pif2*t);

% 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;

% Update the delay lines


for k = length(b) - 1:-1:2
x_delay(k) = x_delay(k - 1);
end
if length(b) > 1
x_delay(1) = input_signal(n);
end
for k = length(a) - 1:-1:2
y_delay(k) = y_delay(k - 1);
end
if length(a) > 1
y_delay(1) = output_signal(n);
end

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.

You might also like