From de5e295e4d2a046c43ee9ba5a22d3fd943d8f383 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Thu, 14 Dec 2023 08:24:29 +0100 Subject: [PATCH] fix #909 --- lib/ControlSystemsBase/src/discrete.jl | 3 +++ lib/ControlSystemsBase/test/test_discrete.jl | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/ControlSystemsBase/src/discrete.jl b/lib/ControlSystemsBase/src/discrete.jl index 1d0b7ea33..c708a0fbc 100644 --- a/lib/ControlSystemsBase/src/discrete.jl +++ b/lib/ControlSystemsBase/src/discrete.jl @@ -143,6 +143,9 @@ This method of translation is useful when analyzing hybrid continuous/discrete s The resulting system will be be a static system in feedback with pure delays. When `method = :causal`, the delays will be positive, resulting in a causal system that can be simulated in the time domain. When `method = :acausal`, the delays will be negative, resulting in an acausal system that **can not** be simulated in the time domain. The acausal translation results in a smaller system with half as many delay elements in the feedback path. """ function d2c_exact(sys::AbstractStateSpace{<:Discrete}, method=:causal) + if sys.nx == 0 + return DelayLtiSystem(d2c(sys)) + end T = sys.Ts A,B,C,D = ssdata(sys) if method === :acausal diff --git a/lib/ControlSystemsBase/test/test_discrete.jl b/lib/ControlSystemsBase/test/test_discrete.jl index 37d509418..c02a2ade0 100644 --- a/lib/ControlSystemsBase/test/test_discrete.jl +++ b/lib/ControlSystemsBase/test/test_discrete.jl @@ -164,6 +164,13 @@ pd = c2d_poly2poly(A, 0.1) # rd = step(sys, 0:10) # rc = step(sysc_causal, 0:10) # @test rd.y ≈ rc.y atol = 1e-8 + + sys = ss(1,1) + sysc = d2c_exact(sys) + sysc2 = DelayLtiSystem(ss(1)) + @test sysc.P.P ≈ sysc2.P.P + @test sysc.P.ny ≈ sysc2.P.ny + @test sysc.Tau ≈ sysc2.Tau end