Does ADC aliasing matter if I'm only working in the time domain? - Page 1
Forum section: electronics / beginners

author: tinfever
author_rank: Regular Contributor
timestamp: November 16, 2022, 12:25:49 am
content: I'm working on a project where I'll be using the ADC inside a microcontroller to sample the output of multiple current sense amplifiers. I'll ideally be sampling pretty fast, maybe 80kHz on each of 10 channels.I've been reading about how aliasing can occur when sampling a signal, which can cause signal frequencies above SampleRate/2 to fold back in to the lower frequency range of the digitized signal. My question is: Is this actually a problem if I'm only working in the time domain?For instance, if all I want to do is plot the digitized data vs time as it comes in, and I'm assuming that each ADC sample accurately reflects the voltage on the ADC input at that time, wouldn't that mean the resulting data points are all correct, and aliasing isn't an issue?Borrowing this image from TI, looking at the first sample point, while I can't determine if the original signal was 1 Hz, 6 Hz, or 8 Hz, the voltage at the time of sampling was definitely 0.75V.:(Source:https://e2e.ti.com/blogs_/archives/b/precisionhub/posts/aliasing-in-adcs-not-all-signals-are-what-they-appear-to-be)I guess the only flaw in this logic would be if I'm sampling a 10 Hz, 1 V p-p, +5V offset sine wave at 10 samples per second, the digitized version could be a flat line at 5.5V, if I'm unlucky enough that I happen to sample at the peak of each cycle. Thus, the digitized signal isn't even an average of the input.Taking this example further, if I add a RC filter with a cutoff frequency of 1 Hz before the ADC, that should attenuate the input signal down 20dB to 10 Hz, 100mV p-p, +5V offset. So then my worst case digitized result would be a flat line at 5.05V, since the RC filter is sort of averaging out every thing that happens between the samples, rather than having that information be lost.So perhaps in the time-domain an anti-aliasing filter sort of averages out the signal between the samples so the digitized result is a closer approximation to the average of the input signal, and nothing too crazy could have happened between the samples without being taken in to account? Is averaging even the right word for that?

author: ataradov
author_rank: Super Contributor
timestamp: November 16, 2022, 01:53:51 am
content: The same logic would apply to 80 kHz sampling rate. If you have signal outside of that band, it would still appear as a valid signal inside the band and there is no way to tell the difference..Anti-aliasing filter removes those high frequency components. Simple windowed average is a form of a low pass filter, which would work. But there are ways to design better filters with sharper cut off characteristics. It all depends on how much high frequency noise you have in your system.

author: radiolistener
author_rank: Super Contributor
timestamp: November 16, 2022, 08:11:06 am
content: yes, it matters. There is no difference what domain you're using. High frequency will be folded and will be seen as a low frequency on ADC output. And when aliasing is already happened, there is no way to distinguish aliased high frequency from a real low frequency. And no way to remove it.This is why anti-aliasing filter should be placedbefore ADC input, because aliasing happens inside ADC. There is no way to remove aliasing by applying digital filter to ADC output.Also, aliasing happens if you're doing decimation (skipping samples), in that case, in order to avoid aliasing, you should apply digital filterbefore decimation. Simple averaging is a kind of low pass filter, so you can use it, but this low pass filter has a smooth slope of frequency response, so using simple average is not effective way to remove aliasing. It's better to use LPF with a sharp slope to cut off high frequencies more effective. You can use FIR LPF if you want to keep linear phase response or IIR LPF if you want less resource requirements.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 16, 2022, 08:31:05 am
content: You still need to think about it more, it seems you haven't truly grasped what aliasing actually means."each ADC sample accurately reflects the voltage on the ADC input at that time, wouldn't that mean the resulting data points are all correct",This is always true! "Aliasing" does not cause wrong ADC input data points, they are all correct."and aliasing isn't an issue"But this is the wrong conclusion. Aliasing is not some magical extra artifact, it's just a fancy name for obvious reality.Switching your notation between time / frequency domain does not change that reality.Maybe a real-life analog helps. Does George (made-up name) drink a lot? So let's visit the bar once a month, make a quick glance around from the door. Jan 1st 9pm: no George. Feb 1st 9pm: no George. Mar 1st 9pm: George is there! So he drinks four times a year, not bad? All data points are correct, but what did we miss? George drinking every other day. The fact we see that happen more rarely than it actually happens because we are not looking, isaliasing.The question in time domain is: are you happy without having any idea what is happening between your samples?Remember, samples are very short.

author: EPAIII
author_rank: Super Contributor
timestamp: November 16, 2022, 10:07:15 am
content: You must ask yourself what exactly do you mean by that statement/question. What do you mean by "in the time domain".Put another way, what are you going to do with the data after collecting it? It is hard for me to think of a scenario where additional low frequencies that are produced by the alias effect would not distort the data collected, but perhaps you really have such a situation. But remember that, by definition, frequency is defined by time: the very unit by which frequency is measured is the reciprocal of time. So frequency is, of it's essence "in the time domain".To be on the safe side it is always best practice to use the low pass filter before the A-D converter. That way there are no higher frequencies to be mirrored/aliased down below the sample frequency. Or they are at least very minimal in amplitude.Quote from: tinfever on November 16, 2022, 12:25:49 am

author: tszaboo
author_rank: Super Contributor
timestamp: November 16, 2022, 10:14:04 am
content: If you sample at 80 KSPS, a 90KHz signal will appear as a 70KHz signal. And a 150KHz signal as a 10KHz signal.So get rid of it.If your actual signal is low frequency, and you sample at a high rate, that's good, that means it's very easy to get rid of the noise, because you can just place an RC filter at 1KHz and it will attenuate 100Khz signals by 40dB already, which might be good enough.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 16, 2022, 11:26:15 am
content: Time-domain example:Say you have a sinusoidal waveform at f=10kHz, between 2.0V and 3.0V. You sample at 10kHz. What if your sampling always happens at the maximum 3.0V value of the signal? All samples come back at 3.0V. Are you happy with this? Although every sample is correct description of the signal at that time, does this result represent the reality in any useful way?

author: MrAl
author_rank: Super Contributor
timestamp: November 16, 2022, 04:10:06 pm
content: Quote from: tinfever on November 16, 2022, 12:25:49 amIn reality with most circuits we always work in the time domain except when we do a spectrum analysis. Even filter circuits work in the time domain we just calculate some of that in the frequency domain and specify in the frequency domain.Aliasing is a time domain phenomenon, but often specified with different frequencies, so if you ask about the time domain being different it's not because it's always that anyway.Your question does bring up an interesting view nonetheless. What if we could detect the frequency range with some other circuit and adjust the ADC to account for that.There is also the thought of using interlaced ADC's to get more information input to analyze in order to detect a possible aliasing situtation.After all is said and done however, it's probably just simpler to add an analog pre filter to limit the bandwidth that gets to the ADC input.

author: wasedadoc
author_rank: Super Contributor
timestamp: November 16, 2022, 04:54:34 pm
content: Aliasing will always occur if the sampling frequency is not at least twice the highest frequency present at the input to the sampler. A filter before the sampler is the only way to prevent it.But, and in some cases it is an important but, the input can be perfectly reconstructed even when the sampling rate is lower than twice the highest frequency present. That can be accomplished when the input contains no frequencies that coincide with the aliases. For a practical example using this approach seehttps://www.bbc.co.uk/rd/publications/rdreport_1975_04. Also think about the similarities between sub-Nyquist sampling and the mixer in a superhet radio tuning a 1000 kHz station using a 1455 MHz local oscillator to produce the 455 kHz IF.

author: eugene
author_rank: Frequent Contributor
timestamp: November 17, 2022, 06:23:55 pm
content: Quote from: tinfever on November 16, 2022, 12:25:49 amDo you expect there to be information in the signal above 40 kHz?QuoteHow are you plotting the data and how are you interpreting it? A component at 41 kHz will get folded down to approximately 39 kHz. To produce a low frequency alias requires a frequency component close to 80 kHz that is stable (in time) compared to the sample clock.So the question is, what frequencies do you think you might actually be able to see in the plot? And, what frequencies are you interested in?

author: gf
author_rank: Super Contributor
timestamp: November 18, 2022, 07:01:02 pm
content: Quote from: tinfever on November 16, 2022, 12:25:49 amThe question is, do you only want to plot the sampling points - without further interpretation (then aliasing is indeed not an issue), or do you rather want to fill the gaps between the points and plot a curve that reflects the original continuous-time signal, before it was sampled? Note, there are infinitely many possible curves passing through the sample points, but only one of them can be the original signal. IOW, an unambiguous reconstruction from the samples alone is not possible in general, for arbitrary original continuous-time signals.However, theNyquist–Shannon sampling theoremdefines bandwidth constraints for the original continuous-time signal which (when satisfied) do enable an unambiguous, exact reconstruction of the original continuous-time signal from the samples.

author: TimFox
author_rank: Super Contributor
timestamp: November 18, 2022, 08:37:33 pm
content: Note that that important theorem gives the minimum sample rate that allows the input waveform to be reconstructed.The samples themselves, especially when close to that minimum sample rate, do not necessarily form a good approximation to the input waveform when connecting the dots, but appropriate interpolation (e.g., with a sinc function) will theoretically reconstruct the original waveform perfectly if the sample rate is above the minimum value for the input bandwidth.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: November 19, 2022, 01:22:48 am
content: "How much", depends on the application, but in general, yes.For example, if you're doing a time domain control, you might have fairly low-latency sampling -- and that includes not just digital delay (maybe just a short sliding average or 1-2-1 filter, say) but analog as well (a modest RC or RLC just a bit below Fs/2?).If you're doing an AC control, like a switching supply, or motor controller with synthetic sine, etc., maybe you want to filter low enough, or sample often enough, to average out some of the ripple; or sample synchronously so the ripple cancels out (for better or worse, i.e., aliased to DC). I recently did a resonant control that takes samples in quadrature, to better average out the ripple, independent of load phase shift; doesn't account for harmonics, but those will be a smaller part, so it's an acceptable compromise.Then after that, it goes into your PID loop or whatever. You can't run this too fast, either, else it just goes unstable -- alternating divergent values as it feeds back on itself. The compromise in analog systems is phase: you incur a lot of phase shift, filtering inputs and outputs as you go; the compromise in digital systems is samples: it just takes a lot of them to do much of anything, so as to still maintain the illusion of continuity, of curvature, that you're ultimately trying to mimic.So for control purposes, maybe the AA filter is fairly tight and modest, and maybe there's a small FIR filter after the converter, but you make up all of that in the control anyway, which has to be however much slower to do its thing.For signal purposes, it's a simple matter of SNR with respect to out-of-band spectrum getting downmixed. You might need quite a high sample rate to keep flat phase response (Bessel AA filter), if that be a requirement; if not, a more relaxed analog filter will be suitable, but since digital sampling is so much cheaper in general these days, you tend to oversample, and maybe implement something close to a brick-wall filter (FIR or IIR as the case may be) before downsampling. Which is more or less what CD audio did (1-bit data) (IIRC?), and what a lot of sound cards do today (of course no oneneeds192kSps 24-bit multichannel audio, but it's convenient to oversample and get just that edge in performance -- performance that might never be realized in any particular environment, but which is more tolerant of different environments).Tim

author: tinfever
author_rank: Regular Contributor
timestamp: November 21, 2022, 02:26:47 am
content: Wow! Thanks for all the responses!I have two applications in mind where this question has come up for me:1) Measuring the current consumption of a device and then calculating the moving average of the current consumption for various time windows (100us, 1ms, 10ms, 100ms, etc.). Essentially the device requires inverse-time overcurrent protection with various overcurrent limits for the various moving averages and I was thinking about how to implement it. This is where the thought came up of "If all the samples are valid, then the device was really drawing X current at Y time. I don't know the frequency of interest and I'm not sure I even care about it."2) I'm building an electronic load and I want the current to be measured, digitized, and then saved and plotted on a computer. For the sake of discussion, the plotting would be purely for human consumption and wouldn't have any sort of sin(x)/x interpolation. The current waveform would be roughly a square wave at about 3.5 kHz.I've been thinking all of this more and playing with it in LTSpice, and I think I'm getting there.I made a ADC-like circuit that demonstrates the sampling but doesn't do any quantizing.Inputting at 3.5 kHz square wave with a superimposed 1 MHz sine wave representing noise, with no anti-aliasing filter, I can actually see the 1 MHz noise aliasing down to what looks like a 40 kHz square wave superimposed on my primary signal. Adding an RC filter with 40 kHz cutoff, eliminates most of that aliasing to better represent the "average" signal.No filter:Filter:As everyone said, despite the aliased version actually being composed of valid data points, it doesn't represent the original signal very well. The filtered version looks much closer to what I'd call correct. I guess the more specific thing to say would be that the result much better represents the signal of interest, as determined by the circuit designer I guess.While the anti-aliasing filter is reducing noise(?) from higher frequencies, it is also reducing the rise time and creating some distortion of its own. So I guess there is a balance between filtering enough to reduce any high frequency noise but also not so much that the result is distorted. Of course this example is probably the most challenging since it is a square wave, and the real solution is probably just to sample faster.I think the key point you all mentioned was that the anti-aliasing filter helps take in to account what the signal is doing between the samples.

author: Kleinstein
author_rank: Super Contributor
timestamp: November 21, 2022, 08:37:35 am
content: The type of ADC can make a difference: SAR type ADCs, like most integrated with µCs are actually sampling for rather short times and can have quite some problems with aliasing.Sigma delta type ADCs already include filtering and only need a more basic AA filtering for a much higher frequency (the internal sampling frequency).Digital filtering can have the advantage of relatively fast settling compared to an analog filter. Most filters preserve the mean value. So even if the waveform is distorted the area tends to stay the same.The AA filters out interference from an superimposed signal outside the Nyquist band (in the example the 1 MHz sine). It also acts on noise in the relevant frequency bands and this way the AA filter also reduces the noise.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: November 21, 2022, 09:04:02 am
content: Oh I know this one, PC/server/backplane power?Tim

author: tinfever
author_rank: Regular Contributor
timestamp: November 22, 2022, 01:18:36 am
content: Quote from: T3sl4co1l on November 21, 2022, 09:04:02 amIndeed! That was what initially prompted this question in my head a while ago, although I/we later decided to keep it simple and stick with analog for now (when I eventually resume that project).Current project is the world's most ridiculous electronic load!

author: David Hess
author_rank: Super Contributor
timestamp: November 24, 2022, 08:54:50 pm
content: Some time domain instruments work in exactly that way, with an assumption that undersampling will be present. The histogram of the undersampled is the same as the original signal and many measurements only require the histogram, like average, RMS, and peak.If synchronization between the source and the sampling clock is a problem, then the sampling clock can dithered with noise to prevent synchronization. Some advanced frequency counters do this for the same reason.