Difference equations
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
A difference equation is a rule a digital system runs once per sample: it makes each new output from the new input and a few earlier outputs. Follow one, y[n] = 0.5·y[n−1] + 0.5·x[n], as an input step of height 8 goes in: a delay box remembers the last output, feedback brings it back, and the output climbs 4, 6, 7, 7.5, 7.75 toward 8. You will see why feedback gives an infinite impulse response, check that convolution gives the same answer, and run the rule in Python. It builds on the lessons "The impulse response of a digital system" and "Discrete convolution, step by step".
A rule for every new sample
A difference equation is a rule a system follows once per sample. Ours: y[n] = 0.5·y[n−1] + 0.5·x[n]. The new output is half the new input plus half the last output.
y[n] = 0.5·y[n−1] + 0.5·x[n] x[n] the input, sample number n y[n] the output, sample number n y[n−1] the output one sample earlier four parts do the work: ×0.5 multiply the new input + the adder delay remembers the last output ×0.5 multiply that old output
اقرأ الدرس خطوة بخطوة
A rule for every new sample
A difference equation is a rule a system follows once per sample. Ours: y[n] = 0.5·y[n−1] + 0.5·x[n]. The new output is half the new input plus half the last output.
y[n] = 0.5·y[n−1] + 0.5·x[n] x[n] the input, sample number n y[n] the output, sample number n y[n−1] the output one sample earlier four parts do the work: ×0.5 multiply the new input + the adder delay remembers the last output ×0.5 multiply that old outputStart at rest: y[−1] = 0
The delay box (written z⁻¹ in books) holds one number for one tick: the last output. Before the input starts, nothing has happened yet, so it holds y[−1] = 0. This start is called initial rest.
the rule needs y[n−1] for n = 0 that is y[−1]: before the start initial rest: input 0 before n = 0 -> output 0 too so the delay box starts at y[−1] = 0 a different start value gives different outputs from the same rulen = 0: the first sample
The input jumps to 8. x[0] = 8 is multiplied by 0.5: 4. The delay box gives 0, and 0.5 × 0 = 0. The adder sums them: y[0] = 4 + 0 = 4.
n = 0 0.5·x[0] = 0.5 × 8 = 4 0.5·y[−1] = 0.5 × 0 = 0 y[0] = 4 + 0 = 4 input x[n] = 8 for n ≥ 0 (a step of height 8)Remember the output
The new output is copied into the delay box. One tick later it comes back as y[n−1]. This loop from the output back into the adder is called feedback.
after each sample: delay box <- y[n] next tick it is read as y[n−1] output -> delay -> ×0.5 -> adder is a loop: feedback the delay box is the system's memory: one numbern = 1: feedback at work
x[1] = 8 gives 4 again. The delay box returns y[0] = 4, and half of it is 2. So y[1] = 4 + 2 = 6. The output now depends on the past, not only on the input.
n = 1 0.5·x[1] = 0.5 × 8 = 4 0.5·y[0] = 0.5 × 4 = 2 y[1] = 4 + 2 = 6 same input as before (8), different output (6, not 4): the system has memoryRun it: 7, 7.5, 7.75
The same rule, again and again: y[2] = 4 + 3 = 7, y[3] = 4 + 3.5 = 7.5, y[4] = 4 + 3.75 = 7.75. Each tick closes half of the gap to 8.
n 0.5·x[n] 0.5·y[n−1] y[n] 0 4 0 4 1 4 2 6 2 4 3 7 3 4 3.5 7.5 4 4 3.75 7.75 5 4 3.875 7.875 gap to 8: 4, 2, 1, 0.5, 0.25 ... halved every tickWhere it settles
If the output stops changing, y = 0.5·y + 0.5·8, so y = 8. The output creeps up to the input instead of jumping. That makes this rule a smoother, known as exponential smoothing.
steady state: y[n] = y[n−1] = y y = 0.5·y + 0.5·8 0.5·y = 4 y = 8 closed form (check n = 2): y[n] = 8·(1 − 0.5ⁿ⁺¹) y[2] = 8 × (1 − 0.125) = 7 exponential smoothing: s[n] = α·x[n] + (1 − α)·s[n−1], α = 0.5Impulse response: halves forever
Now feed a single 8, then zeros: 8·δ[n]. Out come 4, 2, 1, 0.5 ... Each output is half the last and never reaches exactly 0. Feedback gives an infinite impulse response (IIR): h[n] = 0.5ⁿ⁺¹.
input 8·δ[n] = 8, 0, 0, 0 ... output = 4, 2, 1, 0.5, 0.25 ... so the impulse response is h[n] = 0.5·0.5ⁿ = 0.5ⁿ⁺¹ for n ≥ 0 never exactly 0: IIR (infinite impulse response) without feedback (no y[n−1] term) it would be FIR: finiteSame answer as convolution
Convolving the step with h[n] gives the same 4, 6, 7, 7.5 ... But h[n] never ends, so that sum grows with n. The rule needs only 2 multiplies, 1 add and one stored number per sample.
y[n] = Σ h[k]·x[n−k], k = 0 .. n y[2] = h[0]·8 + h[1]·8 + h[2]·8 = 4 + 2 + 1 = 7 (same as the rule) convolution at sample n: n + 1 products the rule at any n: 2 products, 1 add two views of one system: impulse response, or difference equationIn Python: a loop with one memory
In Python 3, the rule is a loop. prev is the delay box: it starts at 0 and is updated once per sample. scipy.signal.lfilter([0.5], [1, -0.5], x) runs the same rule and gives the same numbers.
prev = 0.0 for xn in [8, 8, 8, 8, 8]: y = 0.5*prev + 0.5*xn prev = y print(y) prints: 4.0 6.0 7.0 7.5 7.75 with scipy (and numpy): >>> from scipy.signal import lfilter >>> lfilter([0.5], [1, -0.5], [8]*5) array([4. , 6. , 7. , 7.5 , 7.75]) lfilter's a = [1, −0.5] means y[n] − 0.5·y[n−1] = 0.5·x[n]
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01The rule is y[n] = 0.5·y[n−1] + 0.5·x[n], starting at rest. The input is x[n] = 2 for every n ≥ 0. What is y[1]?
y[0] = 0.5 × 0 + 0.5 × 2 = 1. Then y[1] = 0.5 × 1 + 0.5 × 2 = 0.5 + 1 = 1.5.
02In the figure, what does the delay box hold just before sample n is computed?
After each sample the output is copied into the delay box, so at the next tick it is read back as y[n−1]. That one stored number is the system's whole memory.
03Why is the impulse response of y[n] = 0.5·y[n−1] + 0.5·x[n] infinitely long?
After the single input sample, every output is half the one before: 0.5, 0.25, 0.125 ... Halving never gives exactly 0, so the response has no end. Feedback through the delay is what makes it IIR.
04A smoother runs y[n] = 0.8·y[n−1] + 0.2·x[n]. The input is a step of height 10. Where does the output settle?
At steady state y stops changing: y = 0.8·y + 0.2 × 10, so 0.2·y = 2 and y = 10. When the two weights add up to 1, the output settles at the input level.
05In scipy.signal.lfilter([0.5], [1, -0.5], x), what does the −0.5 mean?
lfilter uses a[0]·y[n] = b[0]·x[n] − a[1]·y[n−1]. With a = [1, −0.5] that is y[n] = 0.5·x[n] + 0.5·y[n−1]. Without zi it starts at rest.
المسرد
- Difference equation
- A rule that gives each output sample y[n] from the current and earlier inputs and earlier outputs, such as y[n] = 0.5·y[n−1] + 0.5·x[n].
- Delay (z⁻¹)
- A box that holds one sample for one tick, so what goes in at sample n comes out at sample n + 1. Books draw it as z⁻¹.
- Feedback
- Sending an output back into the system through a delay, so later outputs depend on earlier outputs.
- Recursive
- A difference equation that uses earlier outputs (y[n−1], y[n−2] ...). A nonrecursive one uses only inputs.
- Initial rest
- The start condition: if the input is zero before n = 0, the output is zero before n = 0 too, so the delay starts at y[−1] = 0.
- IIR and FIR
- Infinite and finite impulse response. Feedback usually makes the impulse response go on forever (IIR); without feedback it stops after a few samples (FIR).
- Steady state
- The value the output settles at when the input stays constant and the output stops changing.
الملاحظات والمصادر
- The weights 0.5 and 0.5 and the step height 8 are chosen so every output is a short, exact number. Every value in the figure is computed from this model.
- "Initial rest" (input zero before n = 0 means output zero before n = 0) is the start condition Oppenheim and Schafer use to make a difference equation describe one linear, time-invariant system; scipy.signal.lfilter assumes it when zi is not given.
- Books and scipy put every output term on the left: y[n] − 0.5·y[n−1] = 0.5·x[n]. That is why lfilter's second list holds −0.5 for a feedback weight of +0.5.
- A. V. Oppenheim, A. S. Willsky, S. H. Nawab, Signals and Systems, 2nd ed., Pearson (§2.4.2 and §5.8: linear constant-coefficient difference equations)
- A. V. Oppenheim, R. W. Schafer, J. R. Buck, Discrete-Time Signal Processing, 2nd ed., §2.5 (course text listed on MIT OCW 6.341 readings)
- MIT OpenCourseWare 6.003 Signals and Systems (D. Freeman, Fall 2011): difference equations as a representation of LTI systems
- MIT OpenCourseWare 6.341 Discrete-Time Signal Processing (A. V. Oppenheim)
- SciPy documentation: scipy.signal.lfilter (the difference equation it runs; zi = None means initial rest)
- NumPy documentation: numpy.convolve
- Infinite impulse response (Wikipedia): feedback gives a response that does not become exactly zero
- Exponential smoothing (Wikipedia): s_t = α·x_t + (1 − α)·s_(t−1)
اختبار يتاح بعد الخطوة الأخيرة.