20. Introduction to filters
In this lesson, we will explore passive filters and complete a do-it-yourself exercise using an RC filter to do DAC from a PWM signal.
Impedance
Resistors, capacitors, and inductors are linear devices, meaning that there is a linear relationship between current and voltage. For resistors, the current and voltage are in phase. That is, for a sinusoidal input voltage, the current is also sinusoidal with zero phase shift. This makes sense via Ohm’s law;
where
where
Because of the linearity of these elements, it is convenient to instead define a complex impedance,
which gives
The current is completely in phase with the voltage (which we already knew from Ohm’s law), meaning that resistors are completely (you guessed it) resistive. That is, for resistors, the impedance is
Now, let’s put a sinusoidal voltage across a capacitor.
Thus,
Here, the impedance is
These relations are useful to remember; the impedance for a resistor is
A generalized voltage divider
In the previous lesson, we learned about voltage dividers. Consider the same circuit as a voltage divider, but instead of resistance R₁ and R₂, we have generic impedances Z₁ and Z₂.
The expression for the voltage divider generalizes,
We will use this generalized voltage divider architecture to make filters.
RC filters
Now that we have worked out that how voltage dividers work for general impedances, let us consider the case where
The amplitude is found by taking the magnitude of the above expression, giving
Note that in taking the amplitude, we are ignoring the phase shift. The result is interesting because the magnitude of the output voltage is frequency dependent. For frequencies much smaller than
Thinking exercise 6: Passive low-pass RC filter
Show that when the situation is switched around, when Z₁ is a resistor with resistance
Do-it-yourself exercise 8: DAC with PWM
In previous lessons, we have used the MCP4725 breakout board to perform digital-to-analog conversion. This enables us to have an analog voltage available. Now, you will try to get an analog voltage by filtering a pulse-width-modulated signal. You will compare these signals to a signal you get from the MCP4725.
Wire up this circuit:
Write an Arduino sketch that does the following.
Uses I2C to send a sinusoidal voltage with amplitude 5 V and frequency of 1 Hz to the MCP4725 DAC. The converted voltage is read in on pin A0.
Uses digital pin 3 to send a sinusoidally varying voltage with amplitude 5 V and frequency 1 Hz. Remember, PWM works by switching the voltage on and off, such that the average voltage matches what you want. In this case, the average voltage you are sending with
analogWrite()
is varying sinusoidally.Uses digital pin 6 to do the same.
The PWM signals from pins 3 and 6 each go through a passive RC filter. The output voltages of these filters is read in on pins A1 and A2, respectively.
You should send the readings from A0, A1, and A2 over serial to be plotted.
For the passive filters in the circuit, what frequencies would you expect to be filtered out? Note that the frequency of the pulse-width-modulated signal from digital pin 3 is 490 Hz and that from digital pin 6 is 980 Hz. Make plots of the signals from the MCP4725 DAC, pin 3 + RC filter, and pin 6 + RC filter. Do your plots agree with your assessment about filtered frequencies? Finally, what are some drawbacks of using PWM + an RC filter to perform DAC?
Answer to low-pass filter exercise
When we swap the resistor and capacitor from the high-pass filter, we get
which gives
So, when the frequency