19-20 Kasım 2020
ONLINE
     Digital Filter Design Based on ARDUINO and Its
                        Applications
                                                          Muharrem Çelebi 1
                            1
                                Kartepe Vocational and Technical Anatolian High School, Kartepe, Kocaeli.
                                                    muharrem.celebi@kocaeli.edu.tr
Abstract—Nowadays, due to the rapid development of digital                    other frequencies to the output. It is called as notch filter and
platforms, digital signal processing has become realizable into               used to suppress mains noise [1].
small size processors. The purpose of this study is to test the                    Digital filters are divided into two groups according to the
filtering process on both PC-based platform and embedded                      impulse response. These are finite impulse response (FIR) and
system. The first goal of this study is to compare the results of the         infinite impulse response (IIR). FIR filters have a linear phase
filtering process obtained in MATLAB and ARDUINO                              response, so the group delay is the same for each input
environments. For the second purpose, filtering process will be
                                                                              frequency. IIR filters have a nonlinear phase response and
tried in real-time on ARDUINO platform with the produced
filter coefficients. Findings obtained as a result of the study are
                                                                              hence the group delay varies according to the applied
presented and discussed.                                                      frequency. Since FIR filters are always stable, it is possible to
                                                                              use them as an adaptive filter. The filter coefficients of FIR
                                                                              filters are many, so the process loads increase. However, IIR
   Keywords— FIR; IIR; filtering; MATLAB; ARDUINO                             filters have a few filter coefficients, so, they have process loads
                                                                              low level [1].
                       I. INTRODUCTION
     The purpose of digital signal processing is to perform on
digital systems instead of operations with analog circuits. In
this way, it performs the same task based on software, without
the need for electronic materials or replacement. This method
ensures that the design is simple and upgradeable. For
example, an analog filter made with RC elements, it is
necessary to change the materials to change the filter's cutoff
frequency. But if the same operation is to be done in digital
filtering, only the filter coefficient should be changed. Despite
the advantages of digital filters, analog filters are used in many
areas, such as cross-over circuits in speaker cabinets.                                          Fig. 1. FIR filter block diagram
     The filters are systems where the desired signals are
transferred to the output and undesired signals are suppressed.
In filter design, if the materials used are made with elements
such as R, C or L, it is defined as an analog filter. If filtering is
done in a digital environment such as PC or microprocessor, it
is called digital filter.
     Various filter designs were realized. In design, the
keyword is the cut-off frequency which means is decision
point. Low-pass filters (LPF) are filters that allow the
frequency values below the cut frequency to pass, and
suppress the frequency above the cut frequency. High-pass
                                                                                                 Fig. 2. IIR filter block diagram
filters (HPF) are filters that allow frequencies above the cut
frequency to be transferred to the output, and not frequencies                    In the Fig. 1 and Fig. 2 above, the xn and yn values
below the cut frequency. The band-pass filter (BPF) has two                   represent the input signals and the output signals in a discrete
cut-off points. This filter transfers the frequency values at                 domain. bn and an represent filter coefficients. As can be seen
between two cut-off frequencies to output and other                           in Fig. 1, the FIR filter multiplies at the past values of input
frequencies are damped. The band-stop filters (BSF) block the                 signal multiplied by bn filter coefficients then the result of
frequencies between the two cut-off frequency and transfer the                each multiplication is added. In Fig. 2, the left side of the
                                                                              block diagrams is similar to the FIR filter, in addition to,
 978-1-7281-8073-1/20/$31.00 ©2020 IEEE
                                                                        263
                                                   19-20 Kasım 2020
                                                   ONLINE
multiplied at the past values of output signal by an filter
coefficients then the result of each multiplication is added.
                       �
               �(�) � � �(�) ∗ �(� − �)                         (1)
                      ���
                       �                     �
               y(n) � � �(k) ∗ x(n − k)   � � �(j) ∗ y(n − j)   (2)
                      ���                    ���
     Singh et al. [2], used the IIR filter to filter the ECG signal                          Fig. 3. Experiment connection - 1
and remove the noise. Filter coefficients were produced using
Matlab's FDA Tool and used the ATmega16A processor as the                       In this study, two experimental connection are used. The
processor platform. Rahmatillah and Karim [3], designed a IIR               first experiment is offline filtering and the second experiment
Notch filter to reject 50 Hz power line noise. The algorithm                is real-time filtering. Fig. 3 shows the structure of the
were embedded to ARDUINO Due board. Al-Busaidi and                          experimental connection - 1. First, a signal is artificially
Khriji [4], have builded a circuit that measures the ECG                    generated in the MATLAB environment. The sampling period
signal. Low-pass, notch ve band-pass filters were implemented               is chosen as fs = 3000 Hz. The components of this signal have
in this structure. It was used ATmega32 processor. Tan and                  been added to 500Hz, 1000Hz and noise. 300 points of this
Jiang [5], presented teaching material for university students.             artificial signal produced are embedded in ARDUINO. After
In this material, for digital filter implementatirons, they                 this process, the filter coefficients are embedded in the
underlined, sampling time, ADC tehcnique. they used 68HC12                  ARDUINO. All codes and coefficients are executed in
microcontroller and assembley and C languages. Varshney                     ARDUINO board and the results are sent to MATLAB
and Tiwari [6], they designed finite impulse response (FIR)                 environment.
filter and implemented it in hardware as ATmega32 processor.
Vostrukhin and Vakhtina [7], performed moving avarage filter
using MATLAB and ARDUINO. Chiagunye et al. [8], in their
study, low-pass, high-pass and band-pass digital filter were
designed a circuit which is based on PIC16F877A
microcontroller. Sharifi et al. [9], in their paper, designed an
algorithm, for speech recognition based on AVR
microcontroller. Runge et al. [10], in their work, they
improved a system using FPGA for FIR filter. Mohammed
and Ishak [11], created digital filter based on dsPIC30F6010a
for motor driver. Koswatta and Karmakar [12], have builded a
                                                                                             Fig. 4. Experiment connection - 2
moving average filter work on PIC18F452 microcontrroler. It
was used filtering RFID tag reader. Gargava et al. [13],                        Fig. 4 shows the structure of the experimental connection -
established a system of Brain Computer Interfaces (BCI). In                 2. The ARDUINO has an ADC inbuilt, however it doesn't has
this system, EEG signals were filtered, then extracted the                  DAC module inside. That is why, DAC circuit made using
features. Pujari et al. [14], compared the performance of FIR               R2R resistor is soldered and connected with PORTD. In the
filter onto two digital systems. This systems are                           input circuit, sampling is done using the A0 pin. At the output,
microcontroller and FPGA.                                                   an 8-bit output value is generated via PORTD. Pull-up and
                                                                            pull-down connections are performed on the A0 pin with two
                II. MATERIAL AND METHODS                                    10Kohm resistors. In this way, the input signal is kept constant
                                                                            at 2.5V DC level. In addition, with the 1uF capacitor, the
    In this study, FIR_LPF, IIR_LPF, FIR_HPF, IIR_HPF                       ARDUINO is insulated with the signal generator. In sampling,
experiments were carried out for 4 filters. These filters were              it is carried out in 10-bit resolution. However, filtering
calculated by the MATLAB program's filterDesigner tool.                     analysis and DAC operations are performed at 8-bit resolution.
With the export command, bn and an coefficients are produced                    Each FIR filter and IIR filter are designed with a 5th
and transferred to the ARDUINO environment. MATLAB-                         degree filter. Sampling frequency is decided as 3000Hz. The
ARDUINO can easily communicate with a single cable. This                    parameter values of the FIR filter are fpass = 750Hz, fstop =
allows data and results to be transferred quickly.                          1000 Hz. For the IIR filter, fc = 750Hz is tuned. The response
                                                                            of the filters obtained in accordance with these values are
                                                                            presented in Fig. 5.
                                                                      264
                                                       19-20 Kasım 2020
                                                       ONLINE
                                                                                prescaler values into ADCSRA registers. The measured fs
                                                                                values are presented in Fig. 7.
                                                                                                Fig. 7. Maximum sampling frequency
                                                                                    When above Fig. 7 is examined, the minimum and
                                                                                maximum sampling intervals of ARDUINO are displayed. It
                                                                                can sample between 333kHz and at least 8.9kHz. To provide
                 Fig. 5. FIR and IIR filter response                            the fs = 3000 Hz we need, the delay cycle is performed with
                                                                                the while loop when each sample is obtained. The codes used
                III. EXPERIMENTAL RESULTS
                                                                                for this process are displayed in Fig. 8.
    Fig. 6 depicts the result graphics obtained after the first
experiment. In MATLAB environment, a test signal has been
artificially generated. Then, this sign was first filtered in
MATLAB environment and illustrated sequentially in the right
column. After this process, the test signal and filter
coefficients are embedded in ARDUINO. The results obtained
after this process are sent and illustrated in MATLAB
environment. When the filtering results are compared with, the
results of the operations performed in both MATLAB and
ARDUINO environment give similar results.
                                                                                                  Fig. 8. Sampling and delay code
                                                                                Another important point is that the processing time of the FIR
                                                                                and IIR library used should be calculated. Improved
                                                                                ARDUINO-Filters library [15] was used for filtering. The
                                                                                results of these measurement times are presented in Table 1.
                                                                                            TABLE I.      PROCESSING TIMES OF FILTERS
                                                                                     FIR_LPF        IIR_LPF           FIR_HPF           IIR_HPF
                                                                                      145 µs          251 µs           146 µs             249 µs
                                                                                     If the filter degree is increased, the processing time to the
                Fig. 6. Experiment - 1 filtering results
                                                                                filter increases. This increases the total Ts duration and the Fs
                                                                                value decreases. The filtering process is insufficient in
    In the second stage, real-time filtering process is started.                reducing the degree of filter. Therefore, in this study, 5th order
One of the most important problems here is the correct                          filters were designed for each filtering process.
adjustment of the fs value of the processor. In the ARDUINO                          Table I. When examined, the highest processing time is
command list, there is a command that directly adjusts the fs                   about 250 µs IIR filter. In addition to this time, the sampling
value. With ADCSRA register, the sampling rate can be                           process, output_PORTD and delay_time must be included in
adjusted. As a starting point, the sampling frequency values of                 processes. For this reason, the total processing time is about
this register should be determined. Therefore, 100 sampling                     300 µs. When this time is reversed, the maximum real-time fs
were performed on a 100-element array. Before and after this                    is 3300 Hz. As a result, fs = 3000 Hz was chosen.
sampling process, time measurement was done using the
micros () command. Then, the actual fs value was calculated
by measuring the elapsed time in between two time points.
This process was calculated for ADPS0, ADPS1, ADPS2
                                                                          265
                                                      19-20 Kasım 2020
                                                      ONLINE
                                                                               real-time process, setting the Fs value incorrectly, or not being
                                                                               able to set it, will result in false results. There is no need for
                                                                               such an adjustment in the experiments carried out in the PC
                                                                               environment.
                    Fig. 9. Total processing time                                  The results obtained in this study showed that when
                                                                               MATLAB and ARDUINO results are compared, they give
    However, as seen in Fig. 7, although the sampling values                   similar results. As a result of the results obtained in the second
are high, the fs value decreases due to the inclusion of other                 part, the digital filters has been successfully realized in real-
processing times (filtering time, output_PORTD etc.).                          time. High sampling frequency can be reached with faster
    The sine signals, whose amplitude is 4.2Vpp and the                        ARDUINO platforms.
frequency values are 500Hz, 1000Hz and 1400Hz
respectively, are produced from the signal generator. These
signals are applied to the A0 pin, respectively. The filtered                                                  REFERENCES
sign obtained was exported by PORTD with DAC circuit.                          [1]   S. Ertürk, "Digital Signal Processing", Birsen Publishing, Istanbul,
Both input signs and filtered signs are displayed in Fig. 10.                        Turkey, 2005.
                                                                               [2]   N. Singh, S. Ayub and J. P. Saini, " Design of digital IIR filter for noise
                                                                                     reduction in ECG signal", 5th International Conference and
                                                                                     Computational Intelligence and Communication Networks IEEE, pp.
                                                                                     171-176, 2013.
                                                                               [3]   A. Rahmatillah and Ataulkairm, " IIR digital filter design for powerline
                                                                                     noise cancellation of ECG signal using arduino platform", International
                                                                                     Conference on Physical Instrumentation and Advanced Materials,
                                                                                     Journal of Physics, 2017.
                                                                               [4]   A. M. Al-Busaidi and L. Khriji, "Digitally filtered ECG signal using
                                                                                     low-cost microcontroller", International Conference on Control,
                                                                                     Decision and Information Technologies (CoDIT), 2013, pp.258-263.
                                                                               [5]   L. Tan, J. Jiang, "Teaching Digital Filter Implementations Using the
                                                                                     68HC12 Microcontroller", American Society for Engineering Education
                                                                                     (ASEE), 2011.
                                                                               [6]   V. Varshney and M. Tiwari, "Realization of an FIR filter using
                                                                                     ATMEGA32 microcontroller", IEEE International Conference on
                                                                                     Emerging Trends in Computing and Communication Technologies
                                                                                     (ICETCCT), 2017.
                                                                               [7]   A. Vosrukhin and E. Vakhtine, " Studying Digital Signal Processing on
                                                                                     Arduino Based platform", Proceedings of the 15th International
                                                                                     Scientific Conference on Engineering for Rural Development, Jelgava,
                                                                                     Latvia, 2016.
                                                                               [8]   T. Chiagunye, I. Somtoochukw and E. A. Okereke, "Designing a
                                                                                     Microcontroller-Based Low-Pass, High-Pass and Band-Pass Digital
                                                                                     Filter with Op-Amp", Journal of Multidisciplinary Engineering Science
                                                                                     and Technology (JMEST), Vol. 2, issue 5, 2015.
                                                                               [9]   O. Sharifi, A. Zaeri and E. Ghafarioun, "Design and Implementation of
                                                                                     Simple Speech Recognition System Based-on Digital Filters in AVR
                Fig. 10. Oscilloscope images of signals
                                                                                     Microcontroller", Majlesi Journal of Multimedia Processing, vol.
                                                                                     1, 2012.
    12 pictures seen in Fig. 10 have been added. In each
                                                                               [10] C. R. Runge, M. Cerqueira and F. J. Arnold, " Introducing
picture, the input signal and output signal are drawn. The top                      programmable logic devices in physics laboratories: a practical guide for
signal is the input sign, the bottom signal is the output sign.                     the implementation of experiments", Revista Brasileira de Ensino de
500 Hz, 1000Hz and 1400Hz filtered signs are displayed from                         Fisica, 2020.
left to right. FIR_LPF, IIR_LPF, FIR_HPF, IIR_HPF results                      [11] M. F. Mohammed and D. Ishak," Improved BLDC motor performance
are listed top to below in this field.                                              with digitally filtering back-EMF using dsPIC30F microcontroller",
                                                                                    IEEE Student Conference on Research and Development (SCOReD),
    When examining Fig. 10, in LPF processes, when it will                          2009.
go towards high frequency, the output amplitude value                          [12] R. Koswatta and N. C. Karmakar, " Moving average filtering technique
decreases. Similarly, in HPF processes, the output amplitude                        for signal processing in digital section of UWB chipless RFID reader",
decreases as we go towards low frequencies. When FIR and                            Asia-Pacific Microwave Conference, 2010.
IIR filters are compared among themselves, they are 5th                        [13] P. Gargava, K. Sindwani and S. Soman, "Controlling an arduino robot
                                                                                    using Brain Computer Interface",3rd International Conference on
degree in both filters. However, the ratio of the IIR filter to the                 Reliability, Infocom Technologies and Optimization, 2014.
compression of the signals is better.                                          [14] S. Pujari, A. Yeotkar, V. Shingare, S. Monin and B. Kokare,
                                                                                    "Performance analysis of microcontroller and FPGA based Signal
                                                                                    Processing a case study on FIR filter design and implementation",
                       IV. CONCLUSION                                               International Conference on Industrial Instrumentation and Control
                                                                                    (ICIC), 2015.
   In filter design, the exact determination of the Fs value is
                                                                               [15] website : https://github.com/tttapa/Filters
important for the accuracy of the processes. However, in a
                                                                         266