Quick question about low-pass filter and pwm

I'm not sure if i'm asking in the right subforum, please feel free to move if so.

I'm just trying to understand in simple terms what is going on with the low-pas filter.

Let's say we have a 100Hz PWM, 50% duty cycle signal (which is 100 peaks per second). If i make a 10Hz low pas filter, would this mean that only every 10th peak would get registered, and the rest in between these 10th peaks would get lost due to the capacitor reactance?

So during peak 1...the capacitor starts to charge. When peak 1 ends, the capacitor reaches a certain charge. What exactly happens then?

I'm trying to get around the term "cuting-off frequency". How would a 100 peak pwm waveform look if it is cut off at 10Hz (talking purely theoretically, disregarding the low-pass filter)?
I think i seriously need to open the high-school books again, i can't get this question out of my mind for two days.

Thanks.

1 Like

Please read this.
http://www.thebox.myzen.co.uk/Tutorial/PWM.html

Let's say we have a 100Hz PWM, 50% duty cycle signal (which is 100 peaks per second). If i make a 10Hz low pas filter, would this mean that only every 10th peak would get registered, and the rest in between these 10th peaks would get lost due to the capacitor reactance?

No, you're describing a divide-by-ten counter. A lowpass set at 10Hz cutoff frequency means that's where the signal will drop by 3-Db or 70.7% of the amplitude for voltage, or 6Db. power. This is for ONE POLE of filter. You can cascade them for sharper cutoff and each filter will add. In other words, a 3-pole low pass would be reduced by 9Db.

As for using it with PWM, if you want an analog voltage for display purposes you would use a lowpass. If you're merely running a motor, a lowpass isn't necessary because the motor will not respond to a 100Hz square wave anyway. The motor's inductance serves as the lowpass.

So during peak 1...the capacitor starts to charge. When peak 1 ends, the capacitor reaches a certain charge. What exactly happens then?

When the signal is HIGH, the capacitor slowly charges, when the signal is LOW, the capacitor slowly discharges. So the capacitor is always charging or discharging (there will always be some ripple voltage).

If the signal is 5V and PWM's duty is set to 20% (signal is HIGH 20% of the time) so the the capacitor will charge to 20% of 5V = 1V.

The capacitor is just leveling out the peaks (like they all just turned to liquid and dropped to the average value). This makes the PWM work like a digital to analog converter (DAC).

I understand the general working pinciple, it's just that the cut-off frequency term confuses me, especially for a PWM waveform.
I found a youtube video, that explains as so. It basically takes an average of a given waveform.

It averages the 20% High, and the 80% Low, for instance.

That's one way of looking at it. The mathematics for analog filters are pretty involved. To make it worse, when cascading poles, the values interact, so it's best to just grab a free program that does it for you.

My personal favorite is FilterPro, which was originally written by Burr-Brown, a company known world over for their analog expertise. Since TI acquired Burr-Brown, you will now find it on the TI site. I'm running Version 3.1.0.23446 which I think is fairly recent.

Thanks for the info.

My maths knowledge is far from adequate. But from a layman's point of view i'm really scratching my head around this.
Seems as if you have a 100Hz waveform, the 10Hz filter attenuates only the >10Hz part of the waveform.
From what i recall from my maths...frequency is the peak to peak distance in radians.

If you filter the 880Hz frequency in this picture with let's say a 110Hz low-pass filter...my intuition says that the outputting waveform should resemble something more like the actual 110Hz waveform pictured. Slower but with the same amplitude.
Trying this stunt with a PWM waveform is even more perplexing. I'm not sure what am i not seeing here.

Hmm. Maybe i should just leave it at that...

You can not change the frequency with a filter. A low pass filter decreases the amplitude of the signal above the cut of frequency.

Pelle

On your stereo - play with the Bass & Treble knobs.
Low pass filter on PWM is the same - music still sounds the same basically, but you don't hear as many highs (low pass filter) or as many low (high pass filter).

If you filter the 880Hz frequency in this picture with let's say a 110Hz low-pass filter...my intuition says that the outputting waveform should resemble something more like the actual 110Hz waveform pictured. Slower but with the same amplitude.
Trying this stunt with a PWM waveform is even more perplexing. I'm not sure what am i not seeing here.

This is wrong.
You really need to do some research on filters.

my intuition says that the outputting waveform should resemble something more like the actual 110Hz waveform pictured. Slower but with the same amplitude.

That is exactly how filters do not work.

All a filter will do is to lower the amplitude of a signal. The cut off frequency is the point where the signal is reduced by half. So if you have a filter with a cut off frequency of 10Hz and you put a frequency of 10Hz into it the output will be half the input.

If you put a frequency of 100Hz into a filter with a cut off frequency of 10Hz the output will be a 100Hz signal who's amplitude is cut down by a quarter. For each octave ( a doubling of frequency ) you get from the cut off frequency the amplitude of the output will drop by a half. So at 1KHz a filter with 10Hz cutoff frequency will be a half times a half times a half = one eighth of the origional amplitude.

All the filter does is reduce the amplitude of the input signal by an amount determined by how far the input frequency is away from the cut off frequency.

This is an on-line tool where you can make changes then view the output.
RC Low-pass Filter Design for PWM

This is an on-line tool where you can make changes then view the output.

Good!

OP is a bit confused as they are talking about PWM and then about pure sine waves.
Not knowing about what makes up a PWM waveform.

Grumpy_Mike:

my intuition says that the outputting waveform should resemble something more like the actual 110Hz waveform pictured. Slower but with the same amplitude.

That is exactly how filters do not work.

All a filter will do is to lower the amplitude of a signal. The cut off frequency is the point where the signal is reduced by half. So if you have a filter with a cut off frequency of 10Hz and you put a frequency of 10Hz into it the output will be half the input.

If you put a frequency of 100Hz into a filter with a cut off frequency of 10Hz the output will be a 100Hz signal who's amplitude is cut down by a quarter. For each octave ( a doubling of frequency ) you get from the cut off frequency the amplitude of the output will drop by a half. So at 1KHz a filter with 10Hz cutoff frequency will be a half times a half times a half = one eighth of the origional amplitude.

All the filter does is reduce the amplitude of the input signal by an amount determined by how far the input frequency is away from the cut off frequency.

That makes sense yes. It's actually opposite of what i thought.
However i'm still somewhat confused as how exactly this correlates with this picture:

The picture is obvious. You have two frequencies...the higher pitched one will be filtered, and the lower will pass.
But if i have just one (unmodulated) frequency, and i apply a filter...i'm going to get just the attenuation of the signal as you described. Am i understanding this correctly?

Somebody mentioned using a high-fi and the equalizer to filter out treble for instance. In this case the audio signal is heavily modulated and contains all sorts of frequencies (fro 20Hz to 20kHz).
Hmm, on second though that's actually it. If only the base is left, and then you start to slide down that, you'll basically be "turning down the volume".
What are the sliders doing technically..."adjusting" the RC components of the filter?
The base line...lets say has a range from 20Hz to 200Hz, is the slider basically increasing the low pass filter cut-off value from 0Hz to 200Hz?

So trying this with the PWM signal. 100Hz, 100% duty PWM signal would yield a halved amplitude, but still 100% duty, if i put a 100Hz filter on it. So 5V down to 2,5V?
Same with 50% duty. It'd get 2,5V for half cycle.

The average i was talking about is not actually a true average. It would be that, only if i used a 100Hz low-pass filter on a 100Hz signal, right?

Please pardon the complications, but this issue is somewhat bugging me. :slight_smile:

@LarryD

As far as i know a PWM is juts a purely positive (or negative) square waveform with a cycle that can be from 0-100%. O% means constantly OFF (low), 100% constantly ON (high)...and let's say 80% is...80% of the cycle ON and 20% OFF.

@dlloyd

Haha. Nice one. :smiley:

P.S. Found a really good explanation video

A few youtube videos later, and I think i'm starting to understand the theoretical operation.

But thanks anyway for the help.

Low pass filters do work a lot like, but not exactly as Grumpy_Mike sayd.

Cuttoff frequency means the amplitude is -3dB
-3dB means half the power (relative power is measured in 10log) but usally we measure voltage and then -3dB means 0.71 of the amplitude (relative amplitude is measured in 20log)

A single-pole low-pass filter has a rolloff of 6dB/octave which is the same as a rolloff of 20dB/decade.
So 100Hz measured at the output of a simple 10Hz RC lowwpass filter (first order filter) will be 20dB reduced at the output. In voltage -20dB means 1/10th of the amplitude.
For a PWM signal of 100Hz 50-50 duty cycle into a simple 10Hz low-pass filter we will measure a DC output of half the amplitude of the squarewave. On top of this DC there will be 100 Hz and a lot of uneven harmonics like 300Hz, 500Hz, 700Hz and more uneven harmonics at an ever decreasing amplitude.

It is all mathematics. Fourier analyse of a 50-50 square wave of 100 Hz, tells us there will be a 100Hz component of amplitude 4/pi + 300Hz component of 4/(3pi) amplitude + 500Hz of amplitude 4/(5pi) etc etc
the 100Hz component will be -20dB so [1/10 of 4/pi] about 0.127 of the amplitude of the square wave
the 300Hz component will be -30dB so [1/30 of 4/(3pi)] about 0.014 (1.4%) of the square wave amplitude.
the 500Hz component will be -34dB s0 [1/50 of 4/(5
pi)] about 0.005 (0.5%) of the square wave amplitude.
(http://www.allaboutcircuits.com/vol_2/chpt_7/2.html)

Higher order components are lower because fourier analyse says the amplitude is lower combined with the effect of the higher attenuation in the low-pass filter.
So higher order like 7th and 9th harmonics can sometimes be neglected because there amplitude is less than 0.25% of the original square wave amplitude.

When the PWM input signal has not an exact 50-50 duty cycle or varies in duty-cycle then the mathematics really get complicated.
So a long answer for a quick question. I hope my explanation was clear and sorry for the boring mathematics, but electronics aint easy.

PWM to Simple DAC (with sample code)
PWM to Sine wave (with sample code)

You have two frequencies...the higher pitched one will be filtered, and the lower will pass.
But if i have just one (unmodulated) frequency, and i apply a filter...i'm going to get just the attenuation of the signal as you described. Am i understanding this correctly?

Yes. That is it for sin signals.

Now you have got that consider a PWM signal.
The whole point about filtering a PWM signal is to remove as much of the AC component as possible and leave just the DC component. That DC component is set by the duty cycle of the square wave, so you want to turn PWM into the appropriate DC voltage level. So the cut off frequency needs to be a long way from the actual frequency of the PWM modulation so that the modulation frequency gets removed. However if you get the cutoff frequency too low then the DC will not be able to change very quickly.
For example suppose you had a cutoff frequency of 0.1Hz and the PWM duty cycle changed it would be 10 seconds before the DC voltage got to the correct level for the duty cycle.

I know this link has been posted before but look at the animation of the input duty cycle and the DC level.
http://www.thebox.myzen.co.uk/Tutorial/PWM.html