Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ztrans #853

Closed
BobKruse opened this issue Dec 29, 2017 · 7 comments · Fixed by #1129
Closed

ztrans #853

BobKruse opened this issue Dec 29, 2017 · 7 comments · Fixed by #1129

Comments

@BobKruse
Copy link

Hi,
I'm an octave novice trying to work my way through the examples in Fred Taylor's "Digital Filters: Principles and Applications with MATLAB". And the very first example used a ztrans function that is in MATLAB's Symbolic Math Toolbox but it is not in octaves symbolic package.

It would be nice if someone had the time to add it to the package.

Thanks,
Bob

@cbm755
Copy link
Collaborator

cbm755 commented Dec 31, 2017

I agree that would be nice, but its not (yet) implemented in the upstream sympy project (sympy/sympy#12502). If it were implemented there, it would be easy to support it here.

See also: https://stackoverflow.com/questions/43247480/how-to-do-z-transform-using-python-sympy/43269596

I've added ztrans and iztrans to "nice to have" list in Issue #215.

@BobKruse
Copy link
Author

BobKruse commented Jan 2, 2018 via email

@cbm755
Copy link
Collaborator

cbm755 commented Jan 2, 2018

If you have time, a nice way to move this forward would be to implement it in @sym/ztrans.m just using the mathematical definition. (Based on the upstream comments, it might not be very useful but it would at least get this started).

@Dsantra92
Copy link

Has there been any update on this feature-request?

@alexvong243f
Copy link
Collaborator

alexvong243f commented Apr 28, 2022

I've been thinking about how to implement iztrans for some time. While ztrans can be implemented using the definition alone, the same cannot be done for iztrans as its definition involves contour integral over some circle centered at the origin with sufficiently large radius such that the function is analytic on and outside the circle. I don't see how to do it in general as sympy can only find isolated singularities of a function, but not non-isolated singularities, branch points, ...

Then I realize we don't actually have to do any integration, all we need is the ability to compute Taylor series coefficients.

Given a sequence (xₙ), its (one-sided) Z-transform is given by the Laurent series

       +∞
      ____
      ╲
       ╲   xₙ
        ╲  ──
x₀ +    ╱   n
       ╱   z
      ╱
      ‾‾‾‾
     n = 1

which is convergent on {z ∈ ℂ | |z| > R} for some R ∈ [0, +∞]

Conversely, given X(z), it can be written as a Laurent series which is convergent on {z ∈ ℂ | |z| > R} for some R ∈ [0, +∞] and hence X(1 / z) is a Taylor series which is convergent on {z ∈ ℂ | |z| < 1 / R}

So basically, to find the inverse (one-sided) Z-transform for X(z), we compute fps(X.subs(z. 1 / z)).subs(z, 1 / z). Unfortunately, this snippet doesn't actually work because subs doesn't work on FormalPowerSeries and AFAIK there is no way to convert a power series into a sequence. As a result, we need to use compute_fps instead.

I haven't work out all the details. If my understanding is correct, this approach should work.

@cbm755
Copy link
Collaborator

cbm755 commented Apr 28, 2022

Interesting! I don't know enough fps and compute_fps to offer much in the way of comments at the moment.

Focusing first ztrans first:

  1. How does one represent a sequence x_n (in SymPy and/or Symbolic)?
  2. Is SymPy likely to know/figure out what those FormalPowerSeries converge to? I mean, if I put in sin(n), am I likely to get a closed-form solution out?

alexvong243f pushed a commit to alexvong243f/octsympy that referenced this issue May 3, 2022
@alexvong243f alexvong243f mentioned this issue May 3, 2022
alexvong243f pushed a commit to alexvong243f/octsympy that referenced this issue May 3, 2022
alexvong243f pushed a commit to alexvong243f/octsympy that referenced this issue May 3, 2022
@alexvong243f
Copy link
Collaborator

I have added ztrans in PR #1121.

alexvong243f pushed a commit to alexvong243f/octsympy that referenced this issue May 10, 2022
alexvong243f pushed a commit to alexvong243f/octsympy that referenced this issue May 10, 2022
alexvong243f pushed a commit to alexvong243f/octsympy that referenced this issue May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants