Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 57 ยท Digital Foundations

Digital vs Analog Signals

Learn why computers use digital signals: analog versus digital, logic levels, noise margins, bits and timing diagrams, with live Python and matplotlib examples.

Everything a computer does, from showing this page to playing music, is built from circuits that only ever have to answer one question: is this wire "high" or "low"? That narrow question is the secret behind modern electronics. It is why a chip with billions of parts can work reliably, and why a copy of a file is identical to the original.

This lesson explains the difference between analog and digital signals, how voltage turns into the logic values 0 and 1, why noise margins make digital circuits so robust, and how engineers draw signals over time in timing diagrams. You will also meet the idea that this whole course builds on: a bit is the smallest piece of information.

Analog signals

An analog signal can take any value in a continuous range. The voltage from a microphone, the position of a dimmer knob, and the temperature in a room are all analog quantities. Between 1.00 V and 1.01 V there are infinitely many other values, and each one can mean something different.

That richness is also a weakness. If a microphone signal is 1.250 V and some noise adds 0.020 V, the result is 1.270 V, and nothing in the signal tells you that the extra 0.020 V is wrong. Every wire, every amplifier and every copy adds a little noise, and the errors pile up. This is why a tenth-generation tape copy sounds hissy.

Digital signals

A digital signal is restricted to a small set of allowed values, most often two. Instead of "any voltage", the circuit only cares whether the voltage is in the "low" range or in the "high" range. The two values are called logic levels:

  • Logic 0: low, false, off.
  • Logic 1: high, true, on.

Which voltage means which level depends on the logic family. A common 3.3 V family treats anything near 0 V as low and anything near 3.3 V as high. Older chips used 5 V, and modern processors use 1 V or less inside the chip. The names stay the same, and the voltages change.

Analog or digital?

Analog Any value in a continuous range.
Digital Only a few allowed values, usually two.

Computers pick digital because it survives noise.

1 / 3

From voltage to bit

A single binary digit is called a bit. One bit can hold two values, so it can answer one yes/no question. Two bits can hold four combinations (00, 01, 10, 11), three bits eight, and in general n bits hold 2 to the power n combinations. Groups of bits represent numbers, letters, colors and sounds; the next lessons show how.

A real chip cannot produce exactly 0 V or exactly 3.3 V, and a receiver cannot measure exactly. So each logic family defines four voltage limits. The numbers below are typical for 3.3 V low-voltage TTL; they are illustrative, and a data sheet always has the real values.

Symbol Meaning Example value
VOL Highest voltage a driver outputs for a low 0.4 V
VOH Lowest voltage a driver outputs for a high 2.4 V
VIL Highest voltage a receiver still reads as low 0.8 V
VIH Lowest voltage a receiver still reads as high 2.0 V

Notice the gaps. The driver promises a low of at most 0.4 V, but the receiver accepts anything up to 0.8 V. That difference is the safety zone.

Noise margins

The noise margin is how much unwanted voltage a signal can pick up before the receiver gets it wrong:

  • Low noise margin: NML = VIL โˆ’ VOL = 0.8 โˆ’ 0.4 = 0.4 V
  • High noise margin: NMH = VOH โˆ’ VIH = 2.4 โˆ’ 2.0 = 0.4 V

A low signal can be pushed up by 0.4 V and the receiver still sees a clean low. Voltages between VIL and VIH (0.8 V to 2.0 V here) form the forbidden region: the receiver's behavior is undefined, and a signal should only pass through it quickly while it switches.

The key point is what happens after the receiver. Each gate re-creates a fresh, clean output from a slightly dirty input. Noise does not accumulate along a chain of gates; it is erased at every stage. Analog circuits can never do this.

Noise margins are a design promise, not a guarantee of perfection. If noise is larger than the margin, a bit can still flip. Digital design makes errors rare and detectable, then adds checks such as parity (see the later lesson on error detection).

Recovering bits from a noisy wire

The first example sends eight bits as voltages, adds random noise and then recovers the bits by comparing against a threshold halfway between the levels. The random generator has a fixed seed, so the picture is the same every time. The top chart is what the wire carries, and the bottom chart is the clean digital result.

Python A noisy analog wire becomes clean bits

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The blue curve is messy, but the green waveform is perfect, because every sample was reduced to one of two answers. The bit values printed above the plot are read in the middle of each time slot, away from the edges where the signal is changing.

When noise wins

The second example measures what happens as the noise grows. It sends 10,000 random bits through a model of the 3.3 V levels from the table, adds uniform noise of a chosen size, and counts three outcomes: read correctly, landing in the forbidden region, or flipped to the wrong value.

Python Noise margin experiment

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

With noise smaller than the 0.4 V margin, every bit is read correctly. Larger noise first pushes signals into the forbidden region, and only much larger noise flips bits outright. This is the pattern you want: errors appear gradually and only when the noise is far larger than the design expected.

Timing: signals live in time

A logic level is only meaningful at the moment someone looks at it. In a timing diagram the horizontal axis is time and the vertical axis is the logic level of one or more signals. A signal is drawn as a flat high line, a flat low line, and vertical transitions called edges: a rising edge goes 0 to 1 and a falling edge goes 1 to 0.

Many circuits use a clock, a signal that alternates regularly between 0 and 1. Data changes on one clock edge and is sampled on another, so everyone agrees when to look. Later lessons on flip-flops and counters rely on this.

The last example draws a clock together with a data signal that changes just after each rising edge.

Python Drawing a timing diagram

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The dotted lines mark the rising edges of the clock. Every change in DATA happens right after one, and the signal stays steady for the rest of the cycle. That steady stretch is when a receiver can safely read it.

Why computers are digital

Putting the pieces together, digital wins for four practical reasons:

  1. Noise immunity. Thresholds and margins turn small errors into no errors.
  2. Exact copies. Bits can be copied, stored and sent forever without loss, with error detection on top.
  3. Simple, uniform parts. A circuit that only distinguishes high from low is cheap to make and shrink, which is how billions of transistors fit on one chip.
  4. Math applies. Two-valued signals follow Boolean algebra, so circuits can be designed, simplified and proven with logic instead of guesswork.

Analog still matters at the edges: microphones, radios and sensors are analog, and converters turn their signals into bits and back again.

Characteristics and limits of digital systems

The four reasons above explain why digital circuits dominate. In practice, the characteristics of a digital system are best seen next to an analog one:

Characteristic Digital system Analog system
Noise immunity high: any value inside a noise margin is read as the same bit low: every disturbance becomes part of the signal
Copying and storage exact, unlimited copies; storage is just more bits (memory, disks) each copy loses quality (generation loss); storage degrades
Accuracy set by the number of bits: add a bit to double the resolution set by component tolerances, drift and temperature
Flexibility behavior is changed by software or by reprogramming changing behavior means changing components
Processing arbitrary complex operations on numbers limited to what the circuit physically does
Cost cheap and shrinking, thanks to uniform parts precision components are expensive

Digital systems also have limits. A continuous quantity is represented only approximately, as a limited number of levels, so there is always a rounding error. A signal can only be captured faithfully if it is measured often enough. Processing takes time (latency), and a digital design needs a clock and careful timing. The next section looks at how the border between the two worlds is crossed.

Converting between analog and digital

The real world is analog, so a digital system needs two converters at its edges. An analog-to-digital converter (ADC) turns a voltage into a binary number, and a digital-to-analog converter (DAC) turns a number back into a voltage. An ADC works in two steps.

  1. Sampling: measure the voltage at regular instants, at the sampling rate f_s. The sampling theorem (Nyquist-Shannon) says that all of a signal is captured only if f_s is more than twice the highest frequency in it. Sample slower and fast components masquerade as slow ones, an error called aliasing. That is why audio is sampled at 44.1 or 48 kHz to capture content up to about 20 kHz.
  2. Quantizing: round each sample to one of 2^n levels for an n-bit converter. The step size is Vref / 2^n (for a full-scale range Vref), and the rounding error is at most half a step. Each extra bit halves the step and improves the signal-to-quantization-noise ratio by about 6 dB: SQNR โ‰ˆ 6.02 n + 1.76 dB for a full-scale sine wave.

A stream of such numbers is called PCM (pulse-code modulation), the basis of CDs, WAV files and the digital telephone network (8000 samples per second, 8 bits per sample, which gives 64 kbit/s).

Python Sampling, quantizing and aliasing

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first table is PCM at work: each sample becomes a 3-bit code and the reconstructed value differs from the sample by a rounding error. (This quantizer has no level exactly at zero, so a sample of 0.000 is reconstructed as +0.125.) The second table checks the rule of thumb: the measured signal-to-noise ratio climbs by 6 dB per bit and agrees with the formula. The last part is aliasing: sampled at 1000 Hz, a 900 Hz tone gives exactly the same numbers as a 100 Hz tone, so no later processing can tell them apart. This is why real ADCs have an anti-aliasing filter in front that removes frequencies above f_s / 2.

Types of converters

An ADC needs a way to decide which level the input matches, and there is a trade-off between speed and hardware.

  • A flash ADC has 2^n - 1 comparators, one per threshold, which all look at the input at once and give a thermometer code that an encoder converts to binary. It is the fastest, but 8 bits already need 255 comparators.
  • A successive-approximation (SAR) ADC uses one comparator and a DAC. It tries the bits from the most significant down: set a bit, compare the DAC output with the input, keep the bit if the DAC is still below the input. It needs n clock steps and very little hardware, and is the common choice in microcontrollers.
  • A DAC sums weighted currents or voltages. A binary-weighted DAC uses resistors in the ratio R : 2R : 4R : ..., which is hard to manufacture accurately for many bits. The R-2R ladder uses only two resistor values and is easy to make precisely.
Python SAR ADC, flash ADC and DAC trade-offs

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The SAR trace is a binary search with a DAC in the loop: eight comparisons find the code 168 for 3.30 V (the final output 3.281 V is the nearest level below the input, because the converter truncates). The flash converter gets the same answer in one step but with 255 comparators, and at 12 bits it would need 4095. The R-2R ladder removes the 128-to-1 spread of resistor values of the binary-weighted DAC.

Delta modulation

PCM sends a full number for every sample. Delta modulation sends a single bit per sample: is the input above or below the receiver's current staircase approximation? The staircase then moves one fixed step up or down. It needs no multi-bit converter and the bit stream is easy to decode (just integrate). It has two classic problems. If the step is too small, the staircase cannot follow a steep section (slope overload), and if it is too large, it oscillates around a quiet signal (granular noise). Adaptive delta modulation repairs both: the step grows while the bits keep repeating (the signal is running away) and shrinks when they alternate.

Python Delta modulation and adaptive delta modulation

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

With a fixed step, the loud part needs a big step (anything below the steepest slope of 0.157 per sample overloads, and the error stays above 0.5), while the quiet part is best with a small step. No single fixed step is good for both, but the adaptive version has a small error in each part. Adaptive step sizes are also the idea behind ADPCM, a common coding method for voice.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main advantage of a digital signal over an analog one?

    Receivers only decide high or low, so noise smaller than the margin disappears at each stage instead of accumulating.
  2. 2. A driver outputs a low of at most 0.4 V and the receiver accepts up to 0.8 V as low. What is the low-level noise margin?

    NM_L = VIL - VOL = 0.8 - 0.4 = 0.4 V.
  3. 3. What is the forbidden region?

    Between the highest accepted low and the lowest accepted high, the receiver may read 0, 1 or something in between, so signals should only cross it while switching.
  4. 4. How many different values can 5 bits represent?

    Each bit doubles the number of combinations, so 5 bits give 2 to the power 5, which is 32.

Summary

  • An ADC samples (at more than twice the highest frequency, or aliasing occurs) and quantizes (about 6 dB of signal-to-noise per bit); SAR, flash and delta-modulation converters trade speed against hardware, and DACs turn codes back into voltages.
  • Analog signals vary continuously and pick up noise that cannot be separated from the signal; digital signals use a few allowed values, usually two.
  • Logic 0 and logic 1 correspond to voltage ranges, defined by VOL, VOH, VIL and VIH.
  • Noise margins (NML = VIL โˆ’ VOL, NMH = VOH โˆ’ VIH) let each gate clean up its input, so noise does not accumulate.
  • A bit is one binary digit; n bits give 2n combinations.
  • Timing diagrams show logic levels over time, with rising and falling edges and a clock that says when to read.

Next: Binary, Octal and Hexadecimal, the number systems used to write down bits.