Low Pass Filter: all you need to know about this circuit

low pass filter, circuit

The coils and the operational amplifiers allow to create very interesting circuits, such as the famous frequency filters. These filters have many applications in the electronics industry. As is the case with the low pass filter, the high pass filter, etc. They are specially interesting for certain sound applications, being able to filter noise, or more or less low sounds according to their frequency. Therefore, they are very useful.

If you want to know more about the low pass filter, and other filters, and how they can help you in your projects with Arduino or DIY, I encourage you to read on…

Electric filters

As its name suggests, a filter is a circuit that consists of a series of coils and capacitors, and even some operational amplifiers, in order to let only certain parts of a frequency pass. That is to say, from the whole spectrum of available frequencies, they will filter one or several parts to prevent them from passing.

If we talk about the spectrum audible by the human being, that goes from 20 Hz to 20 Khz, with filters we could eliminate the lower ones, or the higher ones, in order to let only the more or less high/low sounds pass through. This is something that many audio recording or reproduction systems use, such as microphones, speakers, etc.
Types

Types

Depending on the filter type, or rather, depending on the frequency they block or let through, you have different types of circuits that are

  • Low Pass Filter: they are called this because they are those filters that let the lower frequencies pass and suppress or reduce the passage of the higher frequencies. They are composed of one or more coils (in series with the power supply and the load), and one or two shunt capacitors with the power supply and the load. Remember that the load is understood as the device connected to the filter and that it collects the filter output . Within these filters there are also variants, such as the L, T and π.
  • High-pass filter: the high-pass filter is the opposite of the low-pass filter, in this case, what will filter or limit is the passage of low frequencies, letting the highest ones pass. In this one, the electronic elements that compose it are inverted. That is, here the capacitors will be those in series with the power supply and the load, while the coils will be placed in shunt. There are also the same subtypes as in the case of low-pass filters.
  • Band-pass filter: this type of filter has two frequency band-pass blocking regimes. That is to say, they act both as a low-pass filter and as a high-pass filter, opposing the passage of the lower frequencies and also the higher ones at the same time. In other words, it only allows the passage of the medium frequencies.
  • Band filter: it is exactly the opposite of the previous one, what it does is it filters the passage of the medium frequencies and only allows the passage of the lowest and highest frequencies.

Remember that inductances let low frequencies pass and oppose the passage of high frequencies. On the other hand, the capacitors let the high frequencies pass and oppose the passage of the low frequencies.

I would like to add that filters on a practical level are not perfect, and they can always let through some low or high frequencies that should be blocked. However, they do their job quite well for most applications.

And finally, I would also like to clarify something else, and that is that you have surely heard of the EMA and DEMA filters. EMA (Exponential Moving Average) filters allow you to implement this type of filters in an easy way in embedded devices. As for DEMA (Double Exponential Moving Average) they have a faster response than EMA, maintaining a good suppression of the noise you want to avoid.

Alpha Factor

The alpha factor, which you will see in the Arduino IDE codes in the next section, is the parameter that conditions the behavior of the exponential filter. It is related to the cutoff frequency:

  • Alpha = 1: that provides a signal to the output without filtering.
  • Alpha = 0: the filtering value will always be 0.
  • Alpha = x: other values can achieve other alterations in the AMS filter. If you decrease the Alpha factor you will smoothen more the obtained frequency signal, and also increase the system response time (it takes longer to stabilize).

Filters and Arduino

Arduino bus I2C

To use these filters, using a library for Arduino IDE will make your job much easier. You can use this one.

You should know, that it is not necessary to create the circuit high pass filter or low pass filter to connect it to your Arduino board and work with it. Although you can experiment and create these kinds of simple filters, you can also test how an AMS would work with just the Arduino board and a simple Arduino IDE code. This is all you need to see how it handles filtering some frequencies (in this case you simulate the action and simply filter out some integers/floaters simulating what the filter would actually do).

Here are some examples of code you can use to practice.

Example of digital single filter in Arduino of type low pass:


float lowpass_prev_out [LOWPASS_ANALOG_PIN_AMT],
         lowpass_cur_out [LOWPASS_ANALOG_PIN_AMT];
int lowpass_input [LOWPASS_ANALOG_PIN_AMT];
 
 
int adcsample_and_lowpass(int pin, int sample_rate, int samples, float alpha, char use_previous) {
  // pin: Used Arduino analog pin
  // sample_rate:    The right ratio
  // samples: Samples
  // alpha: The Alpha factor for the low pass filter
  // use_previous: If true, it continues to be adjusted to the most recent value.
 
  float one_minus_alpha = 1.0-alpha;
  int micro_delay=max(100, (1000000/sample_rate) - 160);
  if (!use_previous) {
    lowpass_input[pin] = analogRead(pin);
    lowpass_prev_out[pin]=lowpass_input[pin];
  }
  int i;
  for (i=samples;0;i--) {
    delayMicroseconds(micro_delay);
    lowpass_input[pin] = analogRead(pin);
    lowpass_cur_out[pin] = alpha*lowpass_input[pin] + one_minus_alpha*lowpass_prev_out[pin];
    lowpass_prev_out[pin]=lowpass_cur_out[pin];
  }
  return lowpass_cur_out [pin];
}
 
int resulting_value;
 
void setup() {
   Serial.begin(9600);
   resulting_value = adcsample_and_lowpass(0, 1000, 300, 0.015, false);
}
 
void loop() {
   resulting_value = adcsample_and_lowpass(0, 1000, 150, 0.015, true);
   Serial.println(resulting_value);

Example of code for Arduino type high pass:


int sensorPin = 0; //pin used for ADC
int sensorValue = 0; //Initiate variable sensor equivalent to EMA Y
float EMA_a = 0.3; //Initialization of EMA Alpha
int EMA_S = 0; //Initiation of EMA s
int highpass = 0;
 
void setup(){
  Serial.begin(115200);
  EMA_S = analogRead(sensorPin);
}
 
void loop(){
  sensorValue = analogRead(sensorPin); //Lead the value of the ADC sensor
  EMA_S = (EMA_a*sensorValue) + ((1-EMA_a)*EMA_S); //Execute EMA filter
  highpass = sensorValue - EMA_S; //Calculate highpass
 
  Serial.println(highpass);
   
  delay(20); //Wait 20ms
}

Arduino code example bandpass:

int sensorPin = 0; //Pin for ADC
int sensorValue = 0; //Insert the sensor variable, equals EMA Y
 
float EMA_a_low = 0.3; //Initiate EMA Alpha
float EMA_a_high = 0.5;
 
int EMA_S_low = 0; //Start EMA S
int EMA_S_high = 0;
 
int highpass = 0;
int bandpass = 0;
 
void setup(){
  Serial.begin(115200);
   
  EMA_S_low = analogRead(sensorPin);
  EMA_S_high = analogRead(sensorPin);
}
 
void loop(){
  sensorValue = analogRead(sensorPin); //Lead the value of the ADC sensor
   
  EMA_S_low = (EMA_a_low*sensorValue) + ((1-EMA_a_low)*EMA_S_low); //Execute EMA
  EMA_S_high = (EMA_a_high*sensorValue) + ((1-EMA_a_high)*EMA_S_high);
   
  highpass = sensorValue - EMA_S_low;
  bandpass = EMA_S_high - EMA_S_low;
 
  Serial.print(highpass);
  Serial.print(" ");
  Serial.println(bandpass);
   
  delay(20);
}

Example of Arduino code for band:


int sensorPin = 0; //Pin used for ADC
int sensorValue = 0; //Start for EMA Y
 
float EMA_a_low = 0.05; //Initiate EMA alpha
float EMA_a_high = 0.4;
 
int EMA_S_low = 0; //Start EMA S
int EMA_S_high = 0;
 
int highpass = 0;
int bandpass = 0;
int bandstop = 0;
 
void setup(){
  Serial.begin(115200);
   
  EMA_S_low = analogRead(sensorPin);
  EMA_S_high = analogRead(sensorPin);
}
 
void loop(){
  sensorValue = analogRead(sensorPin); //Lead the value of the ADC sensor
   
  EMA_S_low = (EMA_a_low*sensorValue) + ((1-EMA_a_low)*EMA_S_low); //Execute EMA
  EMA_S_high = (EMA_a_high*sensorValue) + ((1-EMA_a_high)*EMA_S_high);
   
  bandpass = EMA_S_high - EMA_S_low;
 
  bandstop = sensorValue - bandpass;
 
  Serial.print(sensorValue);
  Serial.print(" ");
  Serial.print(EMA_S_low);
  Serial.print(" ");
  Serial.println(bandstop);
   
  delay(20);
}

Remember that ADC is Arduino’s analog-to-digital converter. It uses a range of 0-5v, splitting into ranges of 0-1023. If the value is 0v it takes 0 digital value, and if it is 5v it takes 1023 as the signal value, 1v can be 204m, 2v would be 408, etc. [/highlighted]

I advise you to modify and experiment with these codes. You can see the result in a very graphic way thanks to the Serial Plotter of the Arduino IDE. Remember that if you have doubts about programming Arduino or how to use the IDE, you can download the free PDF course from HwLibre.

Leave a Comment

*

*