# a beta cycle with a sharp trough.
#
# One thing to explore is how these results change by changing the random seed.
#
# Using more data and increasing the number of iterations helps the robustness of the algorithm.
#

###################################################################################################

# Define window length & minimum window spacing, both in seconds
win_len = .055
win_spacing = .2

# Apply the sliding window matching algorithm to the time series
avg_window, window_starts, J = sliding_window_matching(sig,
                                                       fs,
                                                       win_len,
                                                       win_spacing,
                                                       max_iterations=500)

###################################################################################################

# Plot the discovered pattern
plot_swm_pattern(avg_window)

###################################################################################################
#
# Sphinx settings:
# sphinx_gallery_thumbnail_number = 2
#
# For our purposes, we will define the window length to be about 1 cycle of a beta oscillation,
# which should help the algorithm to find the waveform shape of the neural oscillation.
#

###################################################################################################

# Define window length & minimum window spacing, both in seconds
win_len = .055
win_spacing = .055

###################################################################################################

# Apply the sliding window matching algorithm to the time series
windows, window_starts = sliding_window_matching(sig,
                                                 fs,
                                                 win_len,
                                                 win_spacing,
                                                 var_thresh=.5)

###################################################################################################
# Examine the Results
# ~~~~~~~~~~~~~~~~~~~
#
# What we got back from the SWM function are the calculate average window, the list
# of indices in the data of the windows, and the calculated costs for each iteration of
# the algorithm run.
#
# In order to visualize the resulting pattern, we can use
# :func:`~.plot_swm_pattern`.
#