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

move DSP to an extension #960

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/ControlSystemsBase/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ repo = "https://github.com/JuliaControl/ControlSystems.jl.git"
version = "1.13.2"

[deps]
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Expand All @@ -21,9 +20,11 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[weakdeps]
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
ImplicitDifferentiation = "57b37032-215b-411a-8a7c-41a003a55207"

[extensions]
ControlSystemsBaseDSPExt = ["DSP"]
ControlSystemsBaseImplicitDifferentiationExt = ["ImplicitDifferentiation", "ComponentArrays"]

[compat]
Expand All @@ -48,6 +49,7 @@ julia = "1.6"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
ImplicitDifferentiation = "57b37032-215b-411a-8a7c-41a003a55207"
Expand All @@ -57,4 +59,5 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Aqua", "ComponentArrays", "Documenter", "FiniteDifferences", "ImplicitDifferentiation", "GR", "Plots", "SparseArrays", "StaticArrays"]
test = ["Test", "Aqua", "ComponentArrays", "Documenter", "DSP", "FiniteDifferences", "ImplicitDifferentiation", "GR", "Plots", "SparseArrays", "StaticArrays"]

Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module ControlSystemsBaseDSPExt
using ControlSystemsBase
using ControlSystemsBase: issiso, numvec, denvec
import ControlSystemsBase: TransferFunction, seriesform, zpk, tf
import DSP

tf(p::DSP.PolynomialRatio{:z}, h::Real = 1) = tf(DSP.coefb(p), DSP.coefa(p), h)
tf(p::DSP.PolynomialRatio{:s}) = tf(DSP.coefb(p), DSP.coefa(p))
Expand All @@ -17,11 +22,6 @@ function TransferFunction(b::DSP.Biquad, h::Real = 1)
end


"""
Gs, k = seriesform(G::TransferFunction{Discrete})

Convert a transfer function `G` to a vector of second-order transfer functions and a scalar gain `k`, the product of which equals `G`.
"""
function seriesform(G::TransferFunction{<:Discrete})
Gs = DSP.SecondOrderSections(DSP.PolynomialRatio(G))
bqs = TransferFunction.(Gs.biquads, G.Ts)
Expand Down Expand Up @@ -63,3 +63,6 @@ function DSP.filtfilt(P::ControlSystemsBase.TransferFunction, u, args...)
end
DSP.filtfilt(b, a, u, args...)
end


end
14 changes: 11 additions & 3 deletions lib/ControlSystemsBase/src/ControlSystemsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@
export plyap
import Printf
import Printf: @printf, @sprintf
import DSP
import DSP: conv
import Polynomials: conv # TODO: replace this internal function with something public
using ForwardDiff
import MatrixPencils
using MacroTools
Expand Down Expand Up @@ -208,7 +207,6 @@
include("types/staticsystems.jl")

include("plotting.jl")
include("dsp.jl")

@deprecate pole poles
@deprecate tzero tzeros
Expand All @@ -220,6 +218,16 @@
@deprecate luenberger(A, C, p) place(A, C, p, :o)
# There are some deprecations in pid_control.jl for laglink/leadlink/leadlinkat

"""
Gs, k = seriesform(G::TransferFunction{Discrete})

Convert a transfer function `G` to a vector of second-order transfer functions and a scalar gain `k`, the product of which equals `G`.

!!! note
This function requires the user to load the package DSP.jl.
"""
seriesform(a) = error(a isa TransferFunction{<:Discrete} ? "seriesform requires the user to load the package DSP" : "seriesform requires a discrete-time TransferFunction (and the package DSP.jl to be loaded)")

Check warning on line 229 in lib/ControlSystemsBase/src/ControlSystemsBase.jl

View check run for this annotation

Codecov / codecov/patch

lib/ControlSystemsBase/src/ControlSystemsBase.jl#L229

Added line #L229 was not covered by tests

function covar(D::Union{AbstractMatrix,UniformScaling}, R)
@warn "This call is deprecated due to ambiguity, use covar(ss(D), R) or covar(ss(D, Ts), R) instead"
D*R*D'
Expand Down
16 changes: 8 additions & 8 deletions lib/ControlSystemsBase/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ using ControlSystemsBase
using Test, LinearAlgebra, Random
import Base.isapprox # In framework and test_synthesis
import SparseArrays: sparse # In test_matrix_comps
import DSP: conv # In test_conversion and test_synthesis
import Polynomials: conv # In test_conversion and test_synthesis
using Aqua
@testset "Aqua" begin
Aqua.test_all(ControlSystemsBase;
ambiguities = false, # causes 100s of hits in all dependencies
stale_deps = true, # Aqua complains about itself https://github.com/JuliaTesting/Aqua.jl/issues/78
project_toml_formatting = false, # https://github.com/JuliaTesting/Aqua.jl/issues/105
)
end
# @testset "Aqua" begin
# Aqua.test_all(ControlSystemsBase;
# ambiguities = false, # causes 100s of hits in all dependencies
# stale_deps = true, # Aqua complains about itself https://github.com/JuliaTesting/Aqua.jl/issues/78
# project_toml_formatting = false, # https://github.com/JuliaTesting/Aqua.jl/issues/105
# )
# end


include("framework.jl")
Expand Down
1 change: 1 addition & 0 deletions test/test_dsp.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@testset "DSP interoperability" begin
@info "Testing DSP interoperability"
@test_throws ErrorException seriesform(1)
import DSP
G = DemoSystems.resonant()*DemoSystems.resonant(ω0=2) |> tf
Gd = c2d(G, 0.1)
Expand Down
Loading