Skip to content

Commit 6ae9fde

Browse files
committed
Convenience method for state-space realization of FIR system
1 parent dda8d38 commit 6ae9fde

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/demo_systems.jl

+17
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,21 @@ function woodberry()
123123
end
124124

125125

126+
127+
"""
128+
`ssfir(c [,Ts=1]) -> sysd`
129+
130+
Returns a (discrete-time) state-space realization `sysd` of a
131+
finite-impulse response (FIR) system with impulse response `c`.
132+
"""
133+
function ssfir(c::AbstractVector{T}, Ts=1) where T
134+
n = length(c)-1
135+
if n == 0
136+
return ss(c[1], Ts)
137+
end
138+
A = diagm(-1=>ones(T, n-1))
139+
B = [1; zeros(T,n-1)]
140+
ss(A, B, transpose(c[2:end]), c[1], Ts)
141+
end
142+
126143
end

test/test_demo_systems.jl

+22
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,26 @@ sys = ssrand(2,2,5,proper=false,stable=true, Ts=0.5)
3636
sys = ssrand(2,2,5,proper=false,stable=false, Ts=0.5)
3737
@test !isstable(sys)
3838

39+
40+
41+
c = [2.5]
42+
sysd = DemoSystems.ssfir(c)
43+
y = impulse(sysd, 10)[1]
44+
@test y[1] == c[1]
45+
@test y[2:11] == zeros(10)
46+
47+
48+
c = [0.1, 2.5]
49+
sysd = DemoSystems.ssfir(c)
50+
y = impulse(sysd, 10)[1]
51+
@test y[1:2] == c[1:2]
52+
@test y[3:11] == zeros(9)
53+
54+
55+
c = [1,2,5,3]
56+
sysd = DemoSystems.ssfir(c)
57+
y = impulse(sysd, 10)[1]
58+
@test y[1:4] == c
59+
@test y[5:11] == zeros(7)
60+
3961
end

0 commit comments

Comments
 (0)