# What is the min. sample rate freq for a square wave acquisition with amplitude measurement [closed]

EDITED FOR MORE CLARITY

I'm a bit confused by this

I have a digital signal (actually UART, NRZ) of 70KHz that will be sampled by a ADC. The goal will be to decode this signal, but ADC is used because amplitude measurements will be used too.

The swing will be from 40V (high) to 34V (low) but occasionally, other digital control signals will appear on line (not UART) down to few volts.

I am asking because I try to figure out a more elevate explanation (than empirically one) in selection of (expensive) ADC. There are a lot of limitations such SPI speed, frame to be compatible with CPU, etc.

Now clearly a Nyquist point (2x) will not apply here since decoding will be impossible. We empirically selected (for ADC size calculation) some 10x value of oversampling or somewhere around 700Ksps.

Of course, infinite sample will reproduce the square but as one reply bellow, how far should I go or how to better approach this selection.

Please don't post what I could do, bitbang, GPIO, etc.

This is a clear question for a real problem and I would spend all my points (or buy if possible) for serious answers (no bounty hunters).

## closed as unclear what you're asking by Chris Stratton, Enric Blanco, Autistic, Scott Seidman, Voltage SpikeMay 12 '17 at 19:38

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Unless you edit to add your apparent amplitude requirement to the question and explain it, this seems to reduce to "how to design a UART" and the answer is "examine published designs" – Chris Stratton May 11 '17 at 15:31
• Given all you seem to want to say about the analog requirement is that it is "Because of some measuring device" I'm voting to close the question as unclear. – Chris Stratton May 11 '17 at 15:32
• just edited, see above – orfruit May 11 '17 at 15:33
• No, you explained nothing. – Chris Stratton May 11 '17 at 15:34
• From the still-too-limited information you have posted, there's little reason why the built-in ADCs of numerous cheap microcontrollers wouldn't seem to work with scaling of the input voltage (for example many from the stm32 series will do a megasample if not more in the case of the stm32f3xx). But there's also still no reason to assume that the digital data needs to be decoded through the ADC used for the analog measurements - nothing in the information yet posted suggests you cannot accomplish the two tasks independently. – Chris Stratton May 12 '17 at 17:47

Without the Signal to Noise Ratio, and a statement of what Bit Error Rates are tolerable, then a solution cannot be defined.

There is always noise, and there is always trash (RFI, SwitchReg HFI, MCU trash into the ADC by way of the ADC-MCU interface lines).

When a "square wave" is amplified (the OP has given no amplitude spec), the resistors used to set gain will add KT/Boltzsmann/Johnson noise. Unless the resistors are metal-film, the resistors will have excess-noise proportional to the sqrt(current) due to "Pauli exclusion effect".

What system crashes will occur, if a bit error occurs?

EDIT1 Every Tau of settling allows another 8.6dB of measurement accuracy, assuming a 1-pole time constant. 10Tau allows 86dB, or 14 bits accuracy. To achieve that accuracy, you must have an error-budget, and account for thermal noise, EFI, HFI, etc.

Years ago, I was asked to evaluate the existing industrial fire-alarm systems for upgrades. This sounds like that kind of system.

By the way, the 8.6dB is a Neper.

EDIT Given you want to measure a voltage, an NRZ waveform, with some accuracy, this particular menu/worksheet may assist your thinking. NEPERS are builtin to the tool.

The tool has builtin ElectricField and MagneticField interference databases; simply click on "efi" or on "hfi" to view or edit and select/deselect. To use the interferers, click "gargoyles" and "I/C" (the PCB traces). Then click "UPDATE" to read the newly computed SNR/ENOB.

• this is a voltage transm. UART like, with idle (high) 40V and 34V in low state. Between normal UART frames, there are some signal pulses that may go down to few volts, so range will be 2V...40V. This I divided with 1:10 (so noise too) and fed into ADC. Now the prob. is that we try to understand how far is worth to go with (expensive) ADC performances in context of prop. detection of NRZ stream. We already determined empirically that a 10x would be sufficient but what I like (and expect) from more experienced colleagues is to hear some pros and cons regarding ADC selection – orfruit May 12 '17 at 9:15
• I'm really impressed :)))))) Anyhow, I know would work, but hoping that this board, find some scientific answers to better understand the phenomenon behind. Thanks! – orfruit May 13 '17 at 9:01

So, the answer here is it depends. As in, it depends what you want. If you want to sample an unknown wave, and then perfectly reproduce it, you wont be able to if it's a perfect square wave. If you want to sample an unknown wave, and then almost perfectly reproduce it if it's a square wave, you will be able to but your sample rate will need to be very high, and exactly how high will depend on how sharp you want the square wave corners.

However, if you already know that your wave is square, and you just want to see when its high or low, then you can just sample at whatever the data rate is, which in this case seems to be 70kbps. To be safe, you should probably sample at double that, so 140KHz.

edit: slightly pedantic here, but if your wave is a "square wave" with a constant frequency, then technically you cant send any data with it because its just a repeating high and then low. I think what you probably mean is a binary wave.

• I should also note that, if you know it's a digital wave, you dont need to sample it with an ADC if you have any GPIO's available. – BeB00 May 11 '17 at 15:20
• That the actual problem is likely data recovery rather than reconstruction is an important point. But data recovery may actually require a higher sampling rate, if there is no shared timing reference clock. UARTs typically use 8 or 16x oversampling in order to "figure out" the timing. There are other possibilities, but without a locked timing reference there needs to be some input to an "early or late" adjuster. Some kind of phase comparator could potentially be an alternative to discrete time sampling. – Chris Stratton May 11 '17 at 15:21
• Like I said, this is a NRZ (like UART) and I want to decode in software. Clearly, 2x oversample is useless. I empirically concluded that some 10x will give me a 10% bitcell error (jitter). But I am looking for more elevate answer. – orfruit May 11 '17 at 15:23
• @user1734108 then why don't you just look at (software) UART design documents? 8x or 16x is typical. Unless you have analog noise, you don't need an ADC. Why aren't you literally using a UART? – Chris Stratton May 11 '17 at 15:24
• @Chris, thanks for comments. No, must be ADC since some precise amplitude must be determined (measured). Otherways, yes, it's just a ordinarily UART. – orfruit May 11 '17 at 15:25

Nyquist still applies. You just need to determine the highest frequency in your system. In theory, a square-wave has an infinite bandwidth. You need to determine how far you want to go before you decide it's "close enough". This could be because either your system already filters out any higher frequencies, or because you deem that you have a close enough match.

A square wave contains all the odd harmonics of your signal. In other words, your 70kHz will contain frequencies at 210kHz, 350kHz, 490kHz, ...

Things get a little more complicated when you include the fact that you are dealing with a NRZ wave. The spectrum of an NRZ wave is (from Couch, Digital an Analog Communication Systems, 7th edition):

$$P_{unipolar NRZ}(f) = \frac{A^{2} T_{b}}{4}\Bigg( \frac{\sin(\pi f T_{b})}{\pi f T_{b}}\Bigg)\Bigg[1 + \frac{1}{T_b}\delta(f)\Bigg]$$

where $\frac{1}{T_b} = R$, the symbol rate of the data, and $A$ is the amplitude.

If you plot this, you get the following shape (again, credit goes to Leon W. Couch):

We often say that you need the "first null bandwidth" to get something that matches your input well enough to figure out what was transmitted. In this case, we can see that this first null is at R, or in your case, 70kHz. Bipolar NRZ (Using $A$ and $-A$ instead of only $A$ and 0) looks the same, only the Dirac-Delta at DC is removed.

Not that if you really do plan on using an ADC to sample the waveform, you will have to use a anti-aliasing filter to prevent the spectrum to fold back and cause issues due to aliasing.

You might now wonder "wait a second, so my 70kHz NRZ contains no frequency components at 70kHz?!" Yes! But watch out - this is when you think of the NRZ to be random and infinite. As soon as you accept that this is not the case, it will return. But still, this seemingly counter-intuitive result can be intuitively explained. Because you have random data, you can think of it as having both the positive and negative sine wave at your frequency. A series of 101010 has the positive, 010101 has the negative. Whenever you get the two, it's like you "switch" between the two. These thus cancel each other out, resulting in a null at the symbol rate.

• looks like the most complete answer. I accepted, but may I ask (i also already question myself) "how far should I go?". This is because at some very tight calculations, I am at 95% to reach what I want (eg. 606KHz sample rate instead of 650) – orfruit May 11 '17 at 15:36
• This posting is not a useful response to the actual problem, but that does tend to happen with badly stated questions. – Chris Stratton May 11 '17 at 15:38
• @ChrisStratton: The question originally didn't have all the extra information, and boiled down to "I have a NRZ signal, What will be the minimum usable sample rate? I guess Nyquist don't apply here.", hence my answer. – Joren Vaes May 11 '17 at 15:40
• @user1734108, it's only 25 minutes since you asked your question. Accepting an answer so quickly may discourage other answers as people around the world wake up and get a chance to read your question. Usually we advise waiting at least 24 hours before accepting an answer. – The Photon May 11 '17 at 15:41
• I kind of agree with chris, but it's still got interesting information. I'm just a bit curious about the OP's comment on his question about only being interested in practice (not theory), and then marking a theory response as an answer. – BeB00 May 11 '17 at 15:42