comparing time series data

40 views (last 30 days)
Tihana
Tihana on 28 Jan 2015
Commented: Yuchen Chen on 22 Aug 2023
I'd like to compare two time series data sets. These data sets measure behavior in response to a stimulation in test and control animals. I'd like to test wether my test line is statistically different from a control line at which time point. Do you have any suggestions of the best way of doing this?
  1 Comment
Yuchen Chen
Yuchen Chen on 22 Aug 2023
simulinktest.constraints.TimeseriesSignalComparator
TimeseriesSignalComparator - Compares Timeseries signals or arrays of
Timeseries signals
By default the TimeseriesSignalComparator compares two Timeseries
signals or Timeseries signal arrays for numerical equality. The signal
numerical equality is qualified by comparing 'Time' and 'Data' fields of
the objects (or arrays of objects). In order to compare all displayed
fields, set 'ComparingAllFields' option to true as shown in 'Example 2:
Comparing all displayed fields'.
For regular comparison of two timeseries objects, use IsEqualTo without
any comparator specification. Refer to help on
matlab.unittest.constraints.IsEqualTo for more information on comparing two
objects in general.
TimeseriesSignalComparator performs the following preliminary checks
prior to signal value comparison:
* Both actual and expected values are Timeseries objects
* Both actual and expected have the same number of Timeseries objects
* Start and stop times of actual and expected Timeseries signals are
the same
* The actual signal's time vector contains at least all time points
contained in the expected signal's time vector
Failing to satisfy any of these requirements will prevent signal value
comparison from happening and will result in an early termination with
the appropriate qualification failure message.
Signals are assumed continuous by default and thus will be compared at
all time points in the expected time vector. If signals are
discontinuous and comparisons around zero crossings need to be ignored,
set 'IgnoringSignalValuesAtZeroCrossings' option to true as shown in
'Example 3: Ignoring comparison around signal discontinuities'.
See 'IgnoreSignalValuesAtZeroCrossings' property for information on how
signal discontinuities are determined.
To compare signal values with a tolerance, specify the kind of
tolerance desired as shown in 'Example 4: Comparison using tolerance'.
Refer to documentation on MATLABUnit Qualification API to obtain a list
of supported tolerance types.
TimeseriesSignalComparator properties:
CompareAllFields - Boolean indicating whether or not to compare all displayed fields to prove equality
IgnoreSignalValuesAtZeroCrossings - Boolean indicating whether or not to ignore comparison around points of signal discontinuity
TimeseriesSignalComparator methods:
TimeseriesSignalComparator - Class constructor
Usage:
testcase.verifyThat(actual, IsEqualTo(expected, 'Using', TimeseriesSignalComparator))
Examples:
To use any example, first execute the following statements
import simulinktest.constraints.TimeseriesSignalComparator
import matlab.unittest.constraints.AbsoluteTolerance
import matlab.unittest.constraints.IsEqualTo
%%% 1. Simple equality check %%%
testcase.verifyThat(timeseries(1:10, 1:10), IsEqualTo(timeseries(1:10, 1:10), 'Using', TimeseriesSignalComparator));
%%% 2. Comparing all displayed fields (Failing Example)%%%
exp = timeseries(1:10,'Name', 'expected');
act = timeseries(1:10,'Name', 'actual');
testcase.verifyThat(act, IsEqualTo(exp, 'Using', TimeseriesSignalComparator('ComparingAllFields', true));
%%% 3. Ignoring comparison around signal discontinuities %%%
testcase.verifyThat(timeseries(1), IsEqualTo(timeseries(1), 'Using', TimeseriesSignalComparator('IgnoringSignalValuesAtZeroCrossings', true)))
%%% 4. Comparison using tolerance %%%
testcase.verifyThat(timeseries(1), IsEqualTo(timeseries(1.01), 'Using', TimeseriesSignalComparator, 'Within', AbsoluteTolerance(0.1)));
See also
simulinktest.constraints.SimulinkOutputComparator matlab.unittest.constraints.IsEqualTo matlab.unittest.constraints.Tolerance
NOTE
If ignoring time points of discontinuity produces an empty resultant time vector, comparison will result in a qualification failure.
Class Details
Superclasses matlab.unittest.internal.constraints.ContainerComparator, simulinktest.internal.mixin.IgnoreSignalValuesAtZCMixin, simulinktest.internal.mixin.SignalValueAlignmentMixin, simulinktest.internal.mixin.TimeseriesMinerMixin, simulinktest.internal.mixin.CompareAllFieldsMixin, simulinktest.internal.mixin.HasTimeTolerance, simulinktest.internal.mixin.WithinRecorderMixin
Sealed false
Construct on load false
Constructor Summary
TimeseriesSignalComparator
Property Summary
CompareAllFields Indicates whether to compare all fields of a
IgnoreSignalValuesAtZeroCrossings Indicates whether to ignore
IsStateful
Recursive Boolean indicating whether the instance operates recursively
SignalAlignment Indicates how to align two signals that need to
TimeTolerance Adds a TimeTolerance property that can be used by
Method Summary
protected Static extractSignalValues Extracts signal values from a Timeseries formatted Simulink
protected Sealed getComparatorsForElements
protected isStateful

Sign in to comment.

Answers (1)

Chad Greene
Chad Greene on 28 Jan 2015
[R,P] = corrcoef(testData,controlData); will return a correlation between your two data sets and the probability that such a correlation coefficient could be obtained by chance.

Categories

Find more on Time Series in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!