1
$\begingroup$

Below code is for 1st order sigma delta modulator used in ADC/DAC circuits.

z[0] = 0; u[0] = 0; y[0] = 0;
x[n_Integer] := 0.01 n; 
y[n_Integer] := If[u[n] \[GreaterSlantEqual] 1, 1, 0]; 
q[n_Integer] := u[n] - y[n]; u[n_Integer] := u[n - 1] + z[n]; 
z[n_Integer] := x[n] - y[n - 1];

Now you shall obtain results e.g. y[10], z[15] based on above code. But actually when n is larger than 21, the code keeps running. You cannot get the result instantly.

I tried to use RSolve but failed. I suspect it is because of the quantization function y[n]. "RSolve::deqx: Supplied equations are not difference equations of the given functions."

RSolve[{q[n] == u[n] - y[n], u[n] == u[n - 1] + z[n], z[n] == x[n] - y[n - 1], y[n] == If[u[n\[GreaterSlantEqual] 1, 1, 0], x[n] == 0.01 n, z[0] == u[0] == y[0] == 0}, {u, y, z, q}, n] 

The DifferenceRoot seems not working as well.

Actually this is a piece of cake in Excel. But to decribe it in a mathematically proper way in MMA becomes difficult.

$\endgroup$

1 Answer 1

1
$\begingroup$

Use memoization of evaluated function values to avoid repeated identical recursion:

z[0] = 0; u[0] = 0; y[0] = 0;
x[n_Integer] := x[n] = 0.01 n;
y[n_Integer] := y[n] = If[u[n] >= 1, 1, 0];
q[n_Integer] := q[n] = u[n] - y[n]; 
u[n_Integer] := u[n] = u[n - 1] + z[n];
z[n_Integer] := z[n] = x[n] - y[n - 1];
$\endgroup$
2
  • $\begingroup$ This is a great job. Thank you so much. By the way, may I know where I can find such advanced function definition? $\endgroup$
    – metroidman
    Nov 30, 2023 at 9:45
  • $\begingroup$ @metroidman Just check e.g. workflowguide/SymbolsAndFunctions in document. (Online version is here: reference.wolfram.com/language/workflowguide/…) $\endgroup$
    – xzczd
    Dec 1, 2023 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.