Skip to content

Commit 0902fe3

Browse files
committed
updates
1 parent 8d60c66 commit 0902fe3

File tree

1 file changed

+113
-15
lines changed

1 file changed

+113
-15
lines changed

lib/ControlSystemsBase/src/freqresp.jl

Lines changed: 113 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,27 @@ freqresp(G::Union{UniformScaling, AbstractMatrix, Number}, w::Real) = G
4646
"""
4747
sys_fr = freqresp(sys, w)
4848
49-
Evaluate the frequency response of a linear system
49+
Evaluate the frequency response of a linear system.
5050
51-
`w -> C*((iw*im*I - A)^-1)*B + D`
51+
For continuous systems, computes `G(jω) = C(jωI - A)^{-1}B + D`
52+
For discrete systems, computes `G(e^{jωT}) = C(e^{jωT}I - A)^{-1}B + D`
5253
53-
of system `sys` over the frequency vector `w`.
54+
# Arguments
55+
- `sys::LTISystem`: The system to analyze
56+
- `w::AbstractVector{<:Real}`: Frequency vector (rad/s)
57+
58+
# Returns
59+
- `sys_fr`: Complex frequency response array of size `(ny, nu, length(w))`
60+
61+
See also [`freqresp!`](@ref), [`evalfr`](@ref), [`bode`](@ref), [`nyquist`](@ref).
62+
63+
# Examples
64+
```julia
65+
using ControlSystemsBase
66+
sys = ss([-1 0; 0 -2], [1; 1], [1 1], 0)
67+
w = exp10.(LinRange(-2, 2, 200))
68+
resp = freqresp(sys, w)
69+
```
5470
"""
5571
@autovec () function freqresp(sys::LTISystem, w_vec::AbstractVector{W}) where W <: Real
5672
te = timeevol(sys)
@@ -299,12 +315,29 @@ end
299315
mag, phase, w = bode(sys[, w]; unwrap=true)
300316
301317
Compute the magnitude and phase parts of the frequency response of system `sys`
302-
at frequencies `w`. See also [`bodeplot`](@ref)
318+
at frequencies `w`. The frequency response is evaluated as `G(jω)` for continuous
319+
systems and `G(e^{jωT})` for discrete systems.
320+
321+
# Arguments
322+
- `sys::LTISystem`: The system to analyze
323+
- `w::AbstractVector`: Frequency vector (rad/s). If omitted, a default frequency range is used.
324+
- `unwrap::Bool`: If true (default), apply phase unwrapping to avoid discontinuities
325+
326+
# Returns
327+
- `mag`: Magnitude of frequency response, size `(ny, nu, length(w))`
328+
- `phase`: Phase in degrees, size `(ny, nu, length(w))`
329+
- `w`: Frequency vector used
303330
304-
`mag` and `phase` has size `(ny, nu, length(w))`.
305-
If `unwrap` is true (default), the function `unwrap!` will be applied to the phase angles. This procedure is costly and can be avoided if the unwrapping is not required.
331+
Note: Phase unwrapping is computationally expensive and can be disabled for better performance. For higher performance, see the function [`bodemag!`](@ref) that computes the magnitude only.
306332
307-
For higher performance, see the function [`bodemag!`](@ref) that computes the magnitude only.
333+
See also [`bodeplot`](@ref), [`bodemag!`](@ref), [`freqresp`](@ref).
334+
335+
# Examples
336+
```julia
337+
using ControlSystemsBase
338+
sys = tf(1, [1, 1])
339+
mag, phase, w = bode(sys)
340+
```
308341
"""
309342
@autovec (1, 2) function bode(sys::LTISystem, w::AbstractVector; unwrap=true)
310343
resp = freqresp(sys, w)
@@ -330,8 +363,34 @@ end
330363
"""
331364
mag = bodemag!(ws::BodemagWorkspace, sys::LTISystem, w::AbstractVector)
332365
333-
Compute the Bode magnitude operating in-place on an instance of [`BodemagWorkspace`](@ref). Note that the returned magnitude array is aliased with `ws.mag`.
334-
The output array `mag` is ∈ 𝐑(ny, nu, nω).
366+
Compute the Bode magnitude operating in-place on an instance of [`BodemagWorkspace`](@ref).
367+
368+
# Arguments
369+
- `ws::BodemagWorkspace`: Pre-allocated workspace created with [`BodemagWorkspace`](@ref)
370+
- `sys::LTISystem`: The system to analyze
371+
- `w::AbstractVector`: Frequency vector (rad/s)
372+
373+
# Returns
374+
- `mag`: Magnitude of frequency response, size `(ny, nu, length(w))`.
375+
Note: The returned array is aliased with `ws.mag`.
376+
377+
# Performance
378+
This function provides significant performance benefits for repeated magnitude calculations:
379+
- Avoids memory allocation by reusing workspace arrays
380+
- Optimized for systems with many frequency points
381+
382+
For thread-safe applications, create one workspace per thread.
383+
384+
See also [`BodemagWorkspace`](@ref), [`bode`](@ref), [`freqresp!`](@ref).
385+
386+
# Examples
387+
```julia
388+
using ControlSystemsBase
389+
sys = tf(1, [1, 1])
390+
w = exp10.(LinRange(-2, 2, 200))
391+
ws = BodemagWorkspace(sys, w)
392+
mag = bodemag!(ws, sys, w)
393+
```
335394
"""
336395
function bodemag!(ws::BodemagWorkspace, sys::LTISystem, w::AbstractVector)
337396
freqresp!(ws.R, sys, w)
@@ -349,9 +408,28 @@ end
349408
re, img, w = nyquist(sys[, w])
350409
351410
Compute the real and imaginary parts of the frequency response of system `sys`
352-
at frequencies `w`. See also [`nyquistplot`](@ref)
353-
354-
`re` and `img` has size `(ny, nu, length(w))`"""
411+
at frequencies `w`. The frequency response is evaluated as `G(jω)` for continuous
412+
systems and `G(e^{jωT})` for discrete systems.
413+
414+
# Arguments
415+
- `sys::LTISystem`: The system to analyze
416+
- `w::AbstractVector`: Frequency vector (rad/s). If omitted, a default frequency range is used.
417+
418+
# Returns
419+
- `re`: Real part of frequency response, size `(ny, nu, length(w))`
420+
- `img`: Imaginary part of frequency response, size `(ny, nu, length(w))`
421+
- `w`: Frequency vector used
422+
423+
See also [`nyquistplot`](@ref), [`freqresp`](@ref), [`bode`](@ref).
424+
425+
# Examples
426+
```julia
427+
using ControlSystems
428+
sys = tf(1, [1, 1])
429+
w = logspace(-2, 2, 100)
430+
re, img, w = nyquist(sys, w)
431+
```
432+
"""
355433
@autovec (1, 2) function nyquist(sys::LTISystem, w::AbstractVector)
356434
resp = freqresp(sys, w)
357435
return real(resp), imag(resp), w
@@ -361,10 +439,30 @@ end
361439
"""
362440
sv, w = sigma(sys[, w])
363441
364-
Compute the singular values `sv` of the frequency response of system `sys` at
365-
frequencies `w`. See also [`sigmaplot`](@ref)
442+
Compute the singular values of the frequency response of system `sys` at
443+
frequencies `w`. The frequency response is evaluated as `G(jω)` for continuous
444+
systems and `G(e^{jωT})` for discrete systems.
445+
446+
# Arguments
447+
- `sys::LTISystem`: The system to analyze
448+
- `w::AbstractVector`: Frequency vector (rad/s). If omitted, a default frequency range is used.
366449
367-
`sv` has size `(min(ny, nu), length(w))`"""
450+
# Returns
451+
- `sv`: Singular values of frequency response, size `(min(ny, nu), length(w))`
452+
- `w`: Frequency vector used
453+
454+
The singular values provide information about the system's gain characteristics
455+
across different frequencies and input/output directions.
456+
457+
See also [`sigmaplot`](@ref), [`freqresp`](@ref), [`bode`](@ref).
458+
459+
# Examples
460+
```julia
461+
using ControlSystems
462+
sys = ss([-1 0; 0 -2], [1 0; 0 1], [1 1; 0 1], 0)
463+
sv, w = sigma(sys)
464+
```
465+
"""
368466
@autovec (1) function sigma(sys::LTISystem, w::AbstractVector)
369467
resp = freqresp(sys, w)
370468
ny, nu = size(sys)

0 commit comments

Comments
 (0)