Lab 7 - Digital Filter On Arduino
Lab 7 - Digital Filter On Arduino
Objectives:
To design and implement a digital filter using Matlab and Arduino
To observe the limitations of microcontrollers for filter´s implementation.
Pre-lab:
1. To study about the IIR filters design analytically and using software as Matlab or others.
2. Install Matlab and Arduino IDE
3. Install the TimerOne.h library your Arduino IDE
Safety precautions:
Ensure that your circuit connections are correct before applying energy to the it. Remember
that Arduino onlys supports positive voltages and only between 0 and 5 volts.
Procedure:
1. Write a code in Matlab to design a Bandreject filter with the following characteristics
Rejected frequency: 60 Hz
Bandwith: 5 Hz
Passband ripple: 1dB
Order filter: 3
Sampling frequency: 300Hz
Put here the code, put a comment on eachs lien of code to explain it.
clear;clc;
fm=300; % Frecuencia de muestreo
fp1=57.5; %Frecuencia de corte
fp2=62.5; %Frecuencia de paro
Ap=1; %Rizados en banda pasante
n=3;
[num,den]=cheby1(n,Ap,[fp1/(fm/2) fp2/(fm/2)],'stop') %Calcula
coeficientes
freqz (num,den,1024,fm)
2. From the coefficients calculated, write here (using the equation´s editor or similar
program), the following:
then we modify the previous code to fit our needs and load it on the Arduino
we need 7 variables for X and 6 variables for Y
// No hagas nada en el lazo principal
}
CODIGO MODIFICADO
#include "TimerOne.h"
float x1=0; //Variables para filtro
float x2=0;
float x3=0;
float x4=0;
float x5=0;
float x6=0;
float x7=0;
float y1=0;
float y2=0;
float y3=0;
float y4=0;
float y5=0;
float y6=0;
float b2=1.7783;
float b3=-3.8011;
float b4=3.4655;
float b5=-3.4815;
float b6=1.4909;
float b7=-0.7673;
void setup()
{
Serial.begin(115200); // Abre el puerto serial
Timer1.initialize(3333.33); // initialize timer1,Value in para 500 Hz
Timer1.attachInterrupt(interrupcion); // Nombra la rutina de interrupción por timer
}
void interrupcion() //Rutina de interrupción
{
//float ADCval = analogRead(0); //Lee canal analógico y lo convierte a voltaje
float x0 = analogRead(0); //Lee canal analógico y lo convierte a voltaje
float filtrado;
5. Load the program modified and test the filter. Put three different frequencies and put
and image of each one. Explain the images.
At 10 Hz we can see that it lets the signal pass correctly. the input and output go together
Figure 4 10 HZ frequency
b. The 60 Hz
in the following image we can clearly see how it attenuates in an expected way
the desired frequency in this case 60 Hz
Figure 6 60 Hz input
Figure 7 62 Hz input
Advantage:
1. FDs have high noise immunity
2. Accuracy depends on round-off error, which can be handled
3. It is easier and cheaper to change the characteristics of a FD because only the characteristics
are modified.
program variables
4. Variations in temperature and supply voltage do not affect the
stored program structure nor filter performance
5. The cost is progressively lower in computer systems and they increase
permanent processing speeds
Disadvantages:
1. The precision depends on the length of the data word, that is, the one that contains the
filter coefficients.
2. The size of the registers that contain the results of the multiplications can
cause a state of saturation (overflow), so it is necessary to apply rounding
to avoid error propagation.
3. The steeper the filter characteristic, the greater the number of coefficients, which
implies greater processing time, threatening the processes that are desired
perform in real time.
4. If fixed-point microprocessors are used, there will be a need to scale the
coefficients in order to adjust them to the allowed range.