# Low pass filter value for DAC

I was wondering, how to calculate the values needed for LC/RC filter when using it for digital to analog conversion?

Also, how does the square waves frequency affect DAC ?

For example: lets say I have 10 kHz 5V square wave output to the LPF. From it, I would like to get an analog value, with cut off frequency at 20kHz.

How would I calculate component values needed?

• When you say, "from [a 10 kHz square wave] I would like to get an analog value", are you talking about using pulse-width modulation (PWM)? – The Photon Jul 28 '14 at 16:37
• Yes, sorry I was unclear. – Golaž Jul 28 '14 at 16:38
• You can't encode a 20 kHz analog signal on a 10 kHz PWM signal. You need the PWM carrier frequency (10 kHz in your example) to be higher than the analog signal you are encoding, at least by a factor of 2, and preferably by a factor of 10 or more (to make the reconstruction circuit simple, which is usually the goal of using PWM). – The Photon Jul 28 '14 at 16:46

If you are not very close to the sampling frequency you can assume that the output amplitude from the DAC pretty much represents the input amplitude - this means that the low pass filter you wish to design (if a 1st order) would be based on a resistor feeding a capacitor to ground and the filtered output taken from the capacitor. The 3dB point of the filter is: -

$f_C = \dfrac{1}{2\pi RC}$ so...

Plug 20,000 Hz into the formula and maybe 1000 ohms and see what value capacitor you get. For higher order filters I'd use a 2nd order sallen-key calculator like from here - it's a good site and I trust it for coming up with the goods.

You do need to be aware of the problems if the highest frequency you want to produce is greater than a fifth of the sampling frequency - this will cause an amplitude error and you may want to "straighten" this out with a little bit of high pass filtering to. Here is an explanation and below is the formula that you need to worry about when compensating: - It describes how the amplitude tails off as the input frequency gets closer to the sampling frequency.

• Sampling frequency means PWM frequency, right? – Golaž Jul 28 '14 at 16:46
• If you are using PWM as your DAC output then yes, it could mean sampling frequency. If you are using a regular DAC it's normally called sampling frequency i.e. how often you update the output with a new digital value. – Andy aka Jul 28 '14 at 16:57