5.5.4 · Coding › Embedded Systems & Real-Time Software
Real world continuous hai (voltage smoothly time aur amplitude mein vary karta hai). CPU sirf discrete numbers samajhta hai. Ek ADC (Analog-to-Digital Converter) continuous voltage ko ek number mein badalta hai; DAC yeh kaam ulta karta hai.
Do sawaal quality decide karte hain:
Hum amplitude ko kitne fine tarike se slice karte hain? → resolution (bits).
Hum time mein kitni baar measure karte hain? → sampling rate (Hz).
Agar koi bhi galat ho toh digital copy ek jhooth hai. Nyquist woh rule hai jo batata hai ki frequency ke baare mein jhooth na bolne ke liye minimum speed kya honi chahiye.
N -bit converter ke distinct output codes ki sankhya 2 N hoti hai. Resolution sabse chhota voltage step hai jo woh represent kar sakta hai, ise LSB (Least Significant Bit) kehte hain.
YEH FORMULA KYUN? Har bit ek yes/no switch hai. N independent binary switches ke saath aap 0 se 2 N − 1 tak count kar sakte ho. Toh poora input span V r e f ko 2 N levels mein divide kiya jaata hai jo 2 N − 1 gaps se alag hote hain.
Worked example 12-bit ADC,
V r e f = 3.3 V
2 12 = 4096 codes.
LSB = 3.3/4095 ≈ 0.806 mV .
Yeh step kyun? ~0.8 mV se chhota koi bhi input change dikh nahi sakta — woh same code mein hi land karta hai.
1.65 V ke liye code: code = round ( 3.3 1.65 × 4095 ) = 2048 . Round kyun? ADC nearest level pe snap karta hai (mid-tread quantizer).
Hum har T s seconds mein signal ki value lete hain. Sampling rate f s = 1/ T s samples per second (Hz) hoti hai.
Minimum speed kyun zaroori hai
Ek sine wave ko apna upar-neeche dikhane ke liye kam se kam do samples per period chahiye. Kam samples ke saath, ek fast wave ek slow wave se alag nahi dikh sakti — woh khud ko disguise kar leti hai. Yeh disguise aliasing hai.
Worked example Aliasing in action
Signal f = 1800 Hz, f s = 1000 Hz par sampled.
Nyquist = 500 Hz; 1800 > 500 → aliasing hota hai. Kyun? Yeh f s > 2 f ma x ko violate karta hai.
round ( 1800/1000 ) = 2 , toh f a l ia s = ∣1800 − 2000∣ = 200 Hz.
Result: ek 1.8 kHz tone ek fake 200 Hz tone ke roop mein record hota hai. Fix: ADC se pehle ek anti-aliasing low-pass filter jo 500 Hz se upar sab kuch khatam kar de.
Worked example Audio CD design
Human hearing ~20 kHz tak hai → f s > 40 kHz chahiye. CD 44.1 kHz use karta hai. Extra margin kyun? Real anti-alias filters perfectly sharp nahi hote; yeh gap (40→44.1 kHz) filter ko roll off karne ki jagah deta hai.
Codes leta hai aur voltage output karta hai V o u t = code × LSB , phir ek reconstruction (smoothing) low-pass filter staircase steps ko hataata hai taaki ek continuous wave recover ho sake.
Intuition Reconstruction ko bhi filter kyun chahiye
DAC har sample ko T s ke liye constant rakhta hai (zero-order hold) → ek staircase. Sharp steps mein high-frequency junk hota hai (signal ki images). Smoothing filter (cut-off ≈ f s /2 ) steps ko mita deta hai, smooth original bacha rehta hai.
Common mistake "Nyquist kehta hai exactly
2 f ma x par sample karo."
Yeh sahi kyun lagta hai: formula mein literally 2 hai. Trap: exactly 2 f par aap har baar zero crossings par land kar sakte ho aur zero read kar sakte ho — reconstruction guaranteed nahi hai. Condition strict hai: f s > 2 f ma x , aur practice mein filter margin ke liye ≥ 2.5 × .
Common mistake "Zyada bits aliasing fix karte hain."
Yeh sahi kyun lagta hai: zyada bits = higher fidelity, toh zaroor zyada = har jagah better. Fix: bits = amplitude precision; aliasing ek time/frequency problem hai. Koi bhi bits ek aisi frequency recover nahi kar sakti jo aapne under-sample ki ho. Aapko faster f s ya anti-alias filter chahiye.
= V r e f / 2 N exactly."
Yeh sahi kyun lagta hai: 2 N code count hai. Fix: 2 N codes ke beech 2 N − 1 gaps hote hain, toh exact LSB = V r e f / ( 2 N − 1 ) . / 2 N ek approximation hai.
Recall Feynman: ek 12-saal ke bacche ko explain karo
Socho ek moving wave ko draw karna by apni pencil paper par thodi thodi der mein dot karke.
Resolution = tumhare paper par kitni height-lines hain (zyada lines = smoother heights). Sampling rate = tum kitni baar dot karte ho. Agar koi wave fast upar-neeche hilti hai lekin tum bahut slow dot karo, toh tumhare dots ek alag, slow wave banate hain — yeh ek magic trick hai jise aliasing kehte hain jahan fast wave ek slow wave ki tarah chhupta hai. Rule: kam se kam har wiggle mein do baar dot karo. DAC woh dost hai jo tumhare dots ko wapas ek smooth wave mein jodta hai.
"Bits = Height, Rate = Time, Two-times = No Crime."
Height → resolution/LSB. Time → sampling. Two-times → f s > 2 f ma x tumhe aliasing jail se bahar rakhta hai.
ADC resolution (bits) kya determine karta hai? Amplitude precision — levels ki sankhya 2 N aur step size LSB = V r e f / ( 2 N − 1 ) .
N-bit ADC ke LSB ka formula? V r e f / ( 2 N − 1 ) ≈ V r e f / 2 N .
3.3 V ref ke saath 12-bit ADC ka LSB? ≈ 0.806 mV (3.3/4095 ).
Nyquist criterion batao. f s > 2 f ma x ek band-limited signal ko perfectly reconstruct karne ke liye.
Nyquist frequency kya hai? f s /2 — sampling rate f s par representable highest frequency.
Aliasing kya hai? f s /2 se upar ka high-frequency content fold back ho jaata hai aur ek lower frequency ki tarah dikhta hai.
1000 Hz par sample kiya 1800 Hz ka alias frequency? ∣1800 − 2 ⋅ 1000∣ = 200 Hz.
Aliasing kaise rokein? ADC se pehle anti-aliasing low-pass filter (cut-off below f s /2 ).
CD 40 kHz ki jagah 44.1 kHz kyun use karta hai? Anti-alias filter ke roll-off ke liye 2 × 20 kHz se upar margin.
N-bit ADC ka ideal SNR? 6.02 N + 1.76 dB (≈6 dB per bit).
Quantization noise ke liye q 2 /12 kyun? Width q ki uniform distribution ka variance q 2 /12 hota hai.
DAC ka reconstruction filter kya karta hai? Zero-order-hold staircase ko smooth karta hai, f s /2 se upar ki spectral images hataata hai.
Kya bits add karne se aliasing fix hoti hai? Nahi — bits amplitude precision fix karte hain; aliasing ke liye faster f s ya filter chahiye.
Quantization Noise & SNR
Anti-Aliasing Filters
Zero-Order Hold & Reconstruction
Fourier Transform & Frequency Domain
Fixed-Point vs Floating-Point in Embedded DSP
Successive Approximation vs Sigma-Delta ADC
Sensor Interfacing on Microcontrollers
Continuous real-world signal
Nyquist fs greater than 2 fmax