# sampling, filtering, PWM etc.

Discussion in 'Mathematics and Physics' started by PG1995, Sep 22, 2014.

1. ### PG1995Active Member

Joined:
Apr 18, 2011
Messages:
1,681
Likes:
13
Hi

Q1:
Almost always an RC circuit is used as a low pass filter. Why isn't an LR circuit also used as a low pass filter it, in my option, can effectively work as a low-pass filter because impedance for an inductor is 2*pi*f*L which means high frequency components will get attenuated when passing thru the inductor.

One reason might be that an inductor has relatively high resistance.

The other reason stated by Wikipedia is, "In practice, however, capacitors (and RC circuits) are usually preferred to inductors since they can be more easily manufactured and are generally physically smaller, particularly for higher values of components".

Q2:
Periodic sampling operation constitutes a periodic impulse train like this. In frequency domain spikes occurs at fs, 2fs, and so on, where fs=1/Ts. The spikes also extend in negative direction - i.e. negative frequencies. Each spike represents a sinusoid having an amplitude 2π/Ts.

Let's first talk about sampling theoretically. Sampling in time domain is multiplication of the impulse train and signal being sampled, and in frequency domain it's convolution of the impulse train spectrum with that of signal being sampled. This text might be useful here - especially the figure at the bottom, Figure 3-5.

Let's now talk about how sampling is done practically in very simple terms. Suppose that you are sampling the voltage across a resistor. You would use an ADC which connects to the circuit or wire at regular internals, let's talk this interval Ts. Basically ADC connects its internal capacitor for a short time to an external circuit and the capacitor gets charged up. This process of connecting the capacitor to an external circuit for a short time at regular intervals is equivalent to a switching activity where a switch is turned on and off at regular intervals. This regular switching constitutes an impulse train. Do I have it correct?

I'm going to assume that what I said in the paragraph above is correct. We know that an impulse train creates harmonics at regular intervals. Are these harmonics generated in the circuit/wire which is being sampled for voltage at regular intervals? Thank you.

Regards
PG

#### Attached Files:

• ###### IMPULSE_TRAIN.jpg
File size:
38.8 KB
Views:
1,166
Last edited: Sep 22, 2014
2. ### JimBSuper ModeratorMost Helpful Member

Joined:
Sep 11, 2004
Messages:
6,429
Likes:
597
Location:
Q1
At low frequencies, low pass and high pass filters are usually made from RC circuits.
Inductors are large, heavy and expensive compared with a resistor, so for these reasons RC circuits are generally used.
However an LC circuit will usually have better performance than the RC circuit.
The lack of performance by the RC circuit can usually be made up by using several stages of RC and may be an op-amp or two. All for less cost that the LC circuit.

At radio frequencies however, it is usual to use LC circuits, especially when low signal loss is important.
Have a look at the attachment, the antenna filter (in red) is supposed to filter harmonics from the transmitter PA stage and prevent them being radiated.
The coils here will be simply 5 or six turns of wire and there will not be an iron or ferrite core.
Very cheap and simple.
The frequency of interest in this circuit is 150 to 170 MHz.

Q2
Yes, I think you have that correct.

I am not sure what you are asking here.
The sampling circuit should not affect the original signal, it may be needed in its original form elsewhere in the equipment.
The signal after the sampling gate will have some harmonic content because of the sampling process.
The original signal is not the same after the sample gate, so the spectrum of the signal will not be the same, it will contain harmonics generated by the sampling (switching) process.

JimB

• Like x 1
3. ### PG1995Active Member

Joined:
Apr 18, 2011
Messages:
1,681
Likes:
13
Thank you, Jim.

I think it would be better if I rephrase the last part of Q2.

Periodic sampling operation constitutes a periodic impulse train like this. In frequency domain spikes occurs at fs, 2fs, and so on, where fs=1/Ts. The spikes also extend in negative direction - i.e. negative frequencies. Each spike represents a sinusoid having an amplitude 2π/Ts.

Let's first talk about sampling theoretically. Sampling in time domain is multiplication of the impulse train and signal being sampled, and in frequency domain it's convolution of the impulse train spectrum with that of signal being sampled. This text might be useful here - especially the figure at the bottom, Figure 3-5.

Let's now talk about how sampling is done practically in very simple terms. Suppose that you are sampling the voltage across a resistor. You would use an ADC which connects to the circuit or wire at regular internals, let's talk this interval Ts. Basically ADC connects its internal capacitor for a short time to an external circuit and the capacitor gets charged up. This process of connecting the capacitor to an external circuit for a short time at regular intervals is equivalent to a switching activity where a switch is turned on and off at regular intervals. This regular switching constitutes an impulse train.

We know that an impulse train creates harmonics at regular intervals. Where are these harmonics generated? I believe they are generated in the circuit being sampled. For example, suppose that in this circuit voltage is being sampled at regular intervals across R2. When ADC is off and no sampling is being done, there is continuous DC current without any harmonics. Once ADC is turned on and sampling process starts, the harmonics are generated in the circuit and now it's not just DC rather it's DC plus harmonics generated due to sampling. Is what I have said so far correct? I hope that I was clear this time. Thank you.

Regards
PG

File size:
16.2 KB
Views:
258

Joined:
Jan 12, 1997
Messages:
-
Likes:
0

5. ### PG1995Active Member

Joined:
Apr 18, 2011
Messages:
1,681
Likes:
13

Hi

First I would request you to help me with the query in my post above. At least guide me in the right direction.

i: The reactance (i.e. a kind of frequency-dependent resistance) of a capacitor is given as 1/2π*f*C and that of an inductor as 2π*f*L. For a capacitor it means that for high frequencies the capacitor offers very little resistance and the inductor offers significant resistance to high frequencies.

Both capacitor and inductor are ideally considered energy storage elements rather than 'energy dissipators' like typical resistors.

Let's focus on only a capacitor. Is capacitor really an energy storage element when it comes to relatively high frequencies? As the frequency is increased, the attenuation also increases. The attenuation really suggests that a capacitor starts working more and more like a regular resistor rather than a storage element as the frequency is increased. What is your opinion?

ii: To proceed with my next query I'm going to assume that you agree to what I have said the above paragraph.

The capacitor acts more and more like a regular resistor as the frequency is increased. It would mean that as the frequency is increased, the energy contained in high frequency signal gets dissipated more across the capacitor. But a capacitor can let energy dissipation only if it lets the current to pass thru it - zero current would mean no energy dissipation. The plated a simple capacitor are separated by a dielectric which is an insulator so how does the current pass thru it?

iii: Since a capacitor can perform filtering function on its own then why are is separate resistor needed in a low-pass filter?

Let me elaborate. Suppose that in this circuit Vin consists of two individual signals - one is a DC signal of 1V and the second is a 100 Hz signal with amplitude of 1V. Let's assume that capacitor's value is 500 uF and resistor R_L is 50Ω. For 100 Hz signal the capacitor's reactance would be 1/(2π*100*500*10^-6)=3.2Ω and for the DC signal it works as an infinite resistance. The 100 Hz signal would tend to pass thru it. I understand that what I'm saying is somewhat flawed but this might help you see what is confusing me. Also note that this question has been asked and answered several times on the web but I'm still confused. Thanks

1: http://www.mrec.org/Stray_Voltage/Capacitors for MREC.pdf (an excellent resource)
2: http://electronics.stackexchange.com/questions/83843/why-use-a-resistor-in-filter-circuits
3: http://books.google.com/books?id=gXXcAAAAQBAJ&pg=PA14&dq=capacitor can filter higher frequencies&hl=en&sa=X&ei=7c8fVOGsIJTxaMPPgvgE&ved=0CBoQ6AEwAA#v=onepage&q=capacitor can filter higher frequencies&f=false

File size:
14.8 KB
Views:
242
6. ### JimBSuper ModeratorMost Helpful Member

Joined:
Sep 11, 2004
Messages:
6,429
Likes:
597
Location:
Trying to expand a bit on your first question.

The signal under test, the one to be sampled is not affected, it (should) remain as it was.
After the sampling switch, we see that the output is effectively the sample gate switching signal modulated by the signal under test.
This is where the harmonics are, not in the original signal.

Look at the pictures.

JimB

On edit. There was a mistake on my part in the sampled spectrum of the AC signal.
The original signal also appears in the output after sampling.
I have changed the picture accordingly.

Last edited: Sep 23, 2014
• Like x 1
7. ### JimBSuper ModeratorMost Helpful Member

Joined:
Sep 11, 2004
Messages:
6,429
Likes:
597
Location:
It is inappropriate to talk about attenuation when considering a capacitor in isolation.

Yes, if you can disconnect the capacitor from the supply when the voltage is at its peak, and then put your fingers across the capacitor terminals, you will see that energy was stored in the capacitor.

As the frequency is increased, the REACTANCE of the capacitor increases, not the ATTENUATION.

Consider a capacitor 1uF, connected across a perfect 50Hz 10Volt supply (perfect = no internal resistance).
Calculate the voltage across the capacitor.
Now do the calculation at 100Hz, 1kHz, 1MHz.
Can you draw a graph showing the attenuation?

Now repeat the exercise where the supply has 10Ohms internal resistance.

There was what can only be described as a never ending acrimonious circular debate here on ETO some months ago on this very topic.
Electrons do not pass through a capacitor in normal operation.
Looking in the wires connecting to the capacitor, there is an alternating current flowing, we can measure it with the usual instruments.
For practical day to day purposes, current appears to flow through the capacitor.
For high minded academic debate, current does not flow through a capacitor.
I will not discuss this any further.

When you tried to draw graphs of attenuation above, I hope you found that it didn't filter all on its own.

JimB

• Like x 1
8. ### PG1995Active Member

Joined:
Apr 18, 2011
Messages:
1,681
Likes:
13
Thanks a lot, Jim.

You have helped me to remove major confusion from my mind. I had been under the impression that it's the signal being sampled which is affected. Now it's clear that all those harmonics are actually generated within the sampling signal.

In the figure, you have used a pulse train instead of an impulse train and x-axis is expanded for the AC signal because you do not want aliasing.

In this figure, please have a look on the number for each spike. I just made up those number. Do you okay the numbers shown for the spectrum of sampled signal? Although I'm almost sure, I still thought that I should ask you. Thank you.

Best wishes
PG

File size:
66.5 KB
Views:
273
File size:
47.6 KB
Views:
241
9. ### PG1995Active Member

Joined:
Apr 18, 2011
Messages:
1,681
Likes:
13
This is an addition to my post above.

I think that in both RC and RL low-pass filters, the relation between the values of both "R" and load resistor matter a lot.

Let me elaborate.

In case of RC low-pass filter, if the value of "R" is more or not much less than the load resistor then a lot of volts gets dropped across the "R" which is waste of energy.

In case of RL low-pass filter situation is somewhat different. The value of load resistor shouldn't be too much that combined parallel resistance of the "R" and load resistor becomes too much .

File size:
10.2 KB
Views:
256
File size:
6.6 KB
Views:
245
10. ### JimBSuper ModeratorMost Helpful Member

Joined:
Sep 11, 2004
Messages:
6,429
Likes:
597
Location:
Impulses sound like pulses in a fancy academic text book.
On every scope that I have ever used, when the voltage jumps up and back down again, it is a pulse!
And similarly if it jumps down and back up, it is a negative going pulse!

Yes I rescaled the axes so that I could easily draw the thing without getting aliases.
As Mrs Nyquists little boy said, the sampling frequency must be at least twice the highest frequency in the signal that you are sampling.
As for the numbers, without pulling out a textbook and reading it myself, I will not comment other that to say that I expect the amplitudes to be dependant on the width of the sampling pulses.

JimB

11. ### JimBSuper ModeratorMost Helpful Member

Joined:
Sep 11, 2004
Messages:
6,429
Likes:
597
Location:
PG
Please note my edit to post #5
JimB

• Thanks x 1
12. ### MrAlWell-Known MemberMost Helpful Member

Joined:
Sep 7, 2008
Messages:
11,056
Likes:
963
Location:
NJ
Hi PG,

Real life capacitors are much different than theoretical ones, as you seem to have noted. The impedance for a theoretical cap is (s is complex frequency):
Zc=1/(s*C)

but for a more real life capacitor we have:
Zc=(Rp*s^2*C*L+s*L+Rp*Rs*s*C+Rs+Rp)/(Rp*s*C+1)

You can see right away that in addition to the capacitance C itself the (more) real life cap also has:
Rs: a series resistance
Rp: a parallel resistance
L: a series inductance.

This means that at some frequency it's going to act like a total filter circuit rather than just a cap.

Also, when the frequency increases to the point where we can no longer call it a lumped element, the actual physical size itself starts to show an effect on the performance and in that case we dont have equations based on only time and circuit values, we have equations based on time, circuit values, and spacial dimensions. We usually dont talk about this too much in forums because it's a lot more complicated and takes a lot more time to discuss than just working with current and voltage and time.

So when the frequency increases you have to think differently sometimes and there are going to be cutoffs where we cant do things the way we did when we assumed we had well behaved purely electrical models.

Can a capacitor act as a filter all by itself?
It surely can, and you can see from that impedance formula above that it has the same response as a filter, but that's not the way we usually use it in circuits until we get into high frequency stuff. Then we have to think about it more and try to figure out what is going to change.

The ADC input looks like a resistor in series with a capacitor. When the ADC input is switched into a connection with an external circuit, the amount the external voltage changes depends on the impedance of the external circuit and the value of the ADC series resistor, and the time it takes to recover depends on the RC time constant.
It should not be hard to calculate because you can assume the external signal has a series resistance Re, and the ADC has series resistance Rs, and the cap value is just C, and the external signal voltage is just Vs. So we have:
Vs in series with Re and Re in series with Rs and Rs in series with C and the initial voltage of C is zero. All you have to do is calculate the time expression for the junction of Re and Re (the voltage response) and that will reveal the waveform there.
You can expect a voltage equal to Vs and as the switch is closed it will decrease suddenly to Vs*Rs/(Rs+Re) followed by an exponential waveform as the cap charges up to Vs. You should be able to do this but if you dont want to i can show you if you like. BTW the negative terminal of Vs goes to ground and so does the other terminal of the ADC cap.

Code (text):

+---Re---o---Rs---+
|        v        |
Vs                C
|                 |
+-----------------+--GND

Last edited: Sep 25, 2014
• Like x 1
13. ### PG1995Active Member

Joined:
Apr 18, 2011
Messages:
1,681
Likes:
13
Thank you, Jim, MrAl.

Q1: I have added negative frequencies to the spectrum of sampled signal in this figure. I hope that I haven't done it wrongly. Anyway, I think that set of frequencies in yellow highlights (or, any other frequencies except the central set of frequencies) need to be removed/attenuated using a filter. Do I have it correct?

Q2: I'm going to assume that what I said above is correct. This would mean that an ADC uses an internal filter for that purpose. Correct?

Q3: I don't think that filters can differentiate between positive and negative frequencies. They see both positive and negative frequencies with the same lens. For example, a filter wouldn't differentiate between +4Hz and -4Hz. Do I have it correct?

Thank you.

File size:
83.3 KB
Views:
370
14. ### JimBSuper ModeratorMost Helpful Member

Joined:
Sep 11, 2004
Messages:
6,429
Likes:
597
Location:
Correct.
Negative frequencies are just a mathematical concept, they do not exist in real world engineering.

Can I get back to you later on the subject of filtering, you may be very confused, and in turn so am I.

JimB

• Like x 1
15. ### MrAlWell-Known MemberMost Helpful Member

Joined:
Sep 7, 2008
Messages:
11,056
Likes:
963
Location:
NJ
Hello again,

I wanted to note that i worded my previous post a little incorrectly so i'd like to correct that here. We were talking about the effect the ADC input has on the external signal being measured. The circuit looks like a signal source Vs in series with a resistor R1 and that is in series with R2 the internal ADC resistance and that is in series with the ADC internal cap.
We want to know the voltage at the junction of the two resistors because that is what gets affected.
So the better wording is:
You can expect a voltage equal to Vs and as the switch is closed it will suddenly decrease to Vs*Rs/(Rs+Re) followed by an exponential waveform as the cap charges up to Vs.
I've changed it in the previous post too now.
Here's the time equation for that junction:
v=Vs*(1-R1*e^(-t/(R1*C1+R2*C1)))/(R1+R2)

• Thanks x 1
16. ### JimBSuper ModeratorMost Helpful Member

Joined:
Sep 11, 2004
Messages:
6,429
Likes:
597
Location:
About these filters and harmonics and things, let me just waffle for a bit in no particular order.

Mr Al makes a correct point about what happens when an ADC is switched to the thing to be measured.
I woud like to add that all measurement systems should not change the thing that they are measuring, or if they do, the change should be acceptably small within the error limits of the measurement being made. I think that makes sense.

When an ADC samples a signal, it measures the instantaneous value of the signal.
Because of the condition known as aliasing, the signal being measured is filtered so that there are no components in the signal that connects to the sampling gate at a frequency higher than half the sampling frequency.
Once the capacitor on the input of the ADC is charged to the voltage of the signal, the ADC can do its thing and create a number which represents that signal voltage.
That number is than stored somewhere.
If we take many readings of the signal, we can have many numbers, all stored in memory somewhere, maybe as a contiguous array.
What we do with those numbers is up to us.

If we want to recreate the signal which we sampled, we can write the numbers to a DAC at the same rate at which we sampled them.

If the original signal was a sinewave, the recreated signal will be a sinewave - almost.
It will actually be a stepped sinewave, there will be little steps in the waveform, each step corresponding to a number written to the DAC.
Because of the steps, the spectrum will now look something like this:

If we want just the original signal, we need a low pass filter to remove the clock and its harmonics and the aliases. This will smooth out the steps in recreated signal waveform.

You may like to try downloading the datasheet for a DDS (Direct Digital Synthesiser) type AD9851 which works by writing values of a digitised sinewave to a DAC.

That is enough waffle for now, I hope that this helps.

JimB

• Like x 1
17. ### MrAlWell-Known MemberMost Helpful Member

Joined:
Sep 7, 2008
Messages:
11,056
Likes:
963
Location:
NJ
Hello again,

I tried to edit my last post but the server was having problems again so i couldnt.

What i was going to add was that the formula for the junction of the two resitors:
v=Vs*(1-R1*e^(-t/(R1*C1+R2*C1)))/(R1+R2)

shows a dip when the ADC switches in, and for values of R1=1k and R2=2k and Vs=5v and C1=100pf we see a dip that goes down as low as (about) 3.3v, but if a cap as little as 0.01uf is added on the ADC chip input pin then the formula becomes more complicated but it shows that then the dip only goes down by about 50mv, so then it only dips down to about 4.95 volts, then the cap charges up to the full 5.00 volts. So there is much less interference with the small external cap.
The formula is a little long so im not sure if you are interested in it. With the values above though it looks like this:
v=5+6065*e^(-45459089*t/9)/120136-6065*e^(-890911*t/9)/120136

• Like x 1
18. ### PG1995Active Member

Joined:
Apr 18, 2011
Messages:
1,681
Likes:
13
Thank you, JimB, MrAl.

I'm sorry but it looks like that the queries Q1 and Q2 from post #12 still remain unanswered. It might be possible that you have already helped me with those queries indirectly but I didn't get your point. In that cast, I'm sorry.

If we want to get only the original signal then we need to remove those 'superfluous' upper and lower sidebands - highlighted in yellow in this figure. Fort this purpose an ADC circuit should contain an internal low-pass filter which is capable of removing those upper and lower sidebands and in my opinion the cutoff frequency of such a filter should be internally adjustable because different signals being sampled might have different frequency components.

I''m including a block diagram of 10-bit ADC here taken from page #114 of Reference Manual for PIC PIC16F87X: https://drive.google.com/file/d/0B_XrsbDdR9NEWkRKeUNkeTJMVmc/edit?usp=sharing

Thank you.

Last edited: Sep 25, 2014
19. ### JimBSuper ModeratorMost Helpful Member

Joined:
Sep 11, 2004
Messages:
6,429
Likes:
597
Location:
My rambling post#15 was an attempt to sort this out, let me try again.

In post #12 you are asking about the output from a sampling gate which is a train of pulses varying in amplitude according to the input signal.
The frequency spectrum of that output is as you have shown in post#12.
This is sent to the input of the ADC, it does not need any more filtering.

It is the signal before the sampling gate which must be filtered to remove frequencies above half the sample frequency, to prevent aliases.

JimB

• Thanks x 1
20. ### PG1995Active Member

Joined:
Apr 18, 2011
Messages:
1,681
Likes:
13
Thanks a lot.

I'm sorry but it's not clear yet. Let me try again.

Yes.

Thanks for confirming it.

Well, that's confusing. Please have a look on this figure and notice the harmonics numbering along the frequency axes. We already have agreed that positive and negative frequencies are the same. The ADC should only use the harmonics or frequency components in green highlight as the correct representation of the signal being sampled. If the ADC is also going to use upper and lower harmonics (or, sidebands?) other than highlighted harmonics then it's not going to be the actual representation of the signal being sampled.

#### Attached Files:

• ###### jim5.jpg
File size:
91.2 KB
Views:
286
Last edited: Sep 26, 2014
21. ### MrAlWell-Known MemberMost Helpful Member

Joined:
Sep 7, 2008
Messages:
11,056
Likes:
963
Location:
NJ
Hello,

There is no "input filter" there really, that's just the equivalent ADC input and it has a capacitor to store the voltage so the ADC circiut can read it. I suppose you can look at it like a filter, but the cutoff frequency will then be up in the hundreds of kilohertz. For example, if the total internal series resistance Rs if 5k and the cap is 100pf, the cutoff frequency would be around 320kHz, if Rs is twice that then the cutoff is roughly around 160kHz. Since the fastest sampling rate is much lower than that you really need your own external filter (such as a capacitor across the input pin or capacitor and another series resistor to form a low pass filter). So in short the internal part of the ADC is not relevant enough to use as a filter you have to employ your own if there are other frequencies that have to be filtered out.

You seem to be saying that you might have say a 100Hz signal with 1kHz riding on it, and you only want to measure the 100Hz signal. Well, when the 1kHz peaks it is going to raise the voltage of the 100hz signal, and when it dips it will lower the voltage of the 100Hz signal, so the ADC will see a signal that is sometimes higher and sometimes lower in amplitude and thus get incorrect readings. The internal 'filter' is no where near good enough to filter out the 1kHz signal so you need an external filter.
Now if you consider the 1kHz noise and the noise is not synced to the 100Hz signal (something that may or may not be possible to guarantee) then you might get away with sampling without a filter because the 1kHz will average out to zero. It's a little tricky doing it this way though because you have to make sure the 1kHz really looks like random noise becaues if it has any properties that do not appear in actual random noise then there will be a tendency to either make the voltage look higher or look lower, which you dont want because that causes inaccuracy. Determining the way the noise affects the signal is very tricky though and some attempts to address this technique can be found in oversampling theory, although even that is tricky
For example, if we have a DC signal and a 1kHz sine wave of small amplitude can we consider that sine wave noise? The fact is, the sine averages to zero over time but i am not sure if that is enough because the voltage vs time of the 1kHz signal makes the voltage at some time periods look more probable than others (near the peaks of course) and a noise signal would not have that consistency because the voltage would be totally random (as well as average to zero). We could look into this farther i guess.

In short though, the internal RC time constant of the ADC is too short to do any significant filtering (ie the cutoff frequency is too high).

I managed to significantly reduce the complexity of the function of the voltage that will be seen at the chip ADC input pin so that means we can include the 5pf pin capacitance too, but that's not enough to help the filtering either. As i was saying before, the pin can be pulled down to around 3.3v without an external cap, but that's with 1k source impedance and 2k internal resistance, and i think it would be higher than 2k, but just for comparison we have the following view:
1. No external cap: 3.3v
2. 0.01uf cap: 4.950 volts
3. 0.1uf cap: 4.955 volts

From above, we see that no cap means the voltage can pull down significantly but only for a short time, and with a small cap of 0.01uf it pulls down by about 50mv, and with ten times that cap value it only pulls down by 5mv, so increasing the cap value 10 times results in the voltage only being pulled down by 10 times less than with the smaller cap.
We could also look at the cutoff frequencies.

• Like x 1