You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/frd.jl
+77-1Lines changed: 77 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -260,7 +260,9 @@ from which it is obvious that ``0 ≤ κ² ≤ 1`` and that κ² is close to 1 i
260
260
"""
261
261
functioncoherence(d::AbstractIdData; n =length(d) ÷10, noverlap = n ÷2, window = hamming, method=:welch, σ =0.05)
262
262
noutputs(d) ==1||throw(ArgumentError("coherence only supports a single output. Index the data object like `d[i,j]` to obtain the `i`:th output and the `j`:th input."))
263
-
ninputs(d) ==1||throw(ArgumentError("coherence only supports a single input. Index the data object like `d[i,j]` to obtain the `i`:th output and the `j`:th input."))
263
+
ifninputs(d) >1
264
+
returnmultiple_coherence(d; n, noverlap, window, σ)
265
+
end
264
266
y, u, h =vec(output(d)), vec(input(d)), sampletime(d)
265
267
if method ===:welch
266
268
Syy, Suu, Syu =wcfft(y, u, n = n, noverlap = noverlap, window = window)
@@ -291,6 +293,80 @@ function wcfft(y, u; n = length(y) ÷ 10, noverlap = n ÷ 2, window = hamming)
291
293
Syy, Suu, Syu
292
294
end
293
295
296
+
functionmultiple_coherence(d::AbstractIdData; n =length(d) ÷10, noverlap = n ÷2, window = hamming, σ =0.05)
297
+
noutputs(d) ==1||throw(ArgumentError("multiple_coherence only supports a single output."))
298
+
ninputs(d) >1||throw(ArgumentError("multiple_coherence requires multiple inputs. Use `coherence` for single input."))
299
+
300
+
y =vec(output(d))
301
+
u =time1(input(d))
302
+
h =sampletime(d)
303
+
304
+
Syy, Suu, Syu =wcfft_mimo(y, u, n = n, noverlap = noverlap, window = window)
305
+
306
+
n_freqs =length(Syy)
307
+
γ2 =zeros(n_freqs)
308
+
309
+
for i in1:n_freqs
310
+
s_xy =conj(Syu[i])
311
+
num =real(dot(s_xy, Suu[i] \ s_xy))
312
+
γ2[i] = num / Syy[i]
313
+
end
314
+
315
+
γ2 =clamp.(γ2, 0.0, 1.0)
316
+
317
+
Sch =FRD(freqvec(h, γ2), γ2)
318
+
return Sch
319
+
end
320
+
321
+
functionwcfft_mimo(y::AbstractVector, u::AbstractMatrix; n =length(y) ÷10, noverlap = n ÷2, window = hamming)
322
+
n_samples, n_inputs =size(u)
323
+
n_samples ==length(y) ||throw(DimensionMismatch("Input and output lengths differ"))
Copy file name to clipboardExpand all lines: src/plotting.jl
+1-2Lines changed: 1 addition & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -268,7 +268,6 @@ coherenceplot
268
268
ArgumentError("Call like this: coherenceplot(iddata; hz=false)")
269
269
d = p.args[1]
270
270
d isa AbstractIdData ||throw(ae)
271
-
ninputs(d) ==1||throw(ArgumentError("coherenceplot only supports a single input. Index the data object like `d[i,j]` to obtain the `i`:th output and the `j`:th input."))
0 commit comments