correlationLags static method
Returns lag indices equivalent to scipy.signal.correlation_lags.
For correlate(in1, in2, mode=...), returned lags align with each output
sample in the chosen mode.
Example:
final lags = Conv.correlationLags(4, 3, mode: CorrOutMode.full);
// [-2, -1, 0, 1, 2, 3]
Implementation
static Int32List correlationLags(
int in1Len,
int in2Len, {
CorrOutMode mode = CorrOutMode.full,
}) {
if (in1Len <= 0 || in2Len <= 0) {
throw ArgumentError('in1Len and in2Len must be > 0');
}
switch (mode) {
case CorrOutMode.full:
{
final start = -(in2Len - 1);
final len = in1Len + in2Len - 1;
return Int32List.fromList(
List<int>.generate(len, (i) => start + i, growable: false),
);
}
case CorrOutMode.valid:
{
if (in1Len >= in2Len) {
final len = in1Len - in2Len + 1;
return Int32List.fromList(
List<int>.generate(len, (i) => i, growable: false),
);
}
final len = in2Len - in1Len + 1;
final start = -(in2Len - in1Len);
return Int32List.fromList(
List<int>.generate(len, (i) => start + i, growable: false),
);
}
case CorrOutMode.same:
{
final len = in1Len;
final start = -(in2Len ~/ 2);
return Int32List.fromList(
List<int>.generate(len, (i) => start + i, growable: false),
);
}
}
}