Skip to content

Commit

Permalink
feat: add discard channel argument
Browse files Browse the repository at this point in the history
  • Loading branch information
danfke committed Jun 13, 2022
1 parent 1d844a3 commit 532fde3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/emgdecompy/decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ def refinement(

def decomposition(
x,
discard=None,
R=16,
M=64,
peel=False,
Expand All @@ -551,6 +552,8 @@ def decomposition(
----------
x: numpy.ndarray
Raw EMG signal.
discard: slice, int, or array of ints
Indices of channels to discard.
R: int
How far to extend x.
M: int
Expand Down Expand Up @@ -605,6 +608,10 @@ def decomposition(

# Flatten
x = flatten_signal(x)

# Discard unwanted channels
if discard != None:
x = np.delete(x, discard, axis=0)

# Center
x = center_matrix(x)
Expand All @@ -626,15 +633,15 @@ def decomposition(
B = np.zeros((z.shape[0], z.shape[0])) # Initialize separation matrix

z_peak_indices, z_peak_heights = initial_w_matrix(z) # Find highest activity columns in z
z_peaks = z[:, z_peak_indices]
z_peaks = z[:, z_peak_indices] # Index the highest activity columns in z

MUPulses = []
sils = []
pnrs = []

for i in range(M):

# If using peel-off then finding highest activity regions of z must happen every iteration
# If using peel-off then indexing into z must happen every iteration, since z is changing
if peel:
z_peaks = z[:, z_peak_indices]

Expand All @@ -660,7 +667,8 @@ def decomposition(
w_i, z, i, l, sil_pnr, thresh, max_iter_ref, random_seed, verbose
)
except:
break # If refinement fails end decomposition
print("Ending decomposition.")
break # If refinement fails because peel-off causes sources to become noise, end decomposition

B[:, i] = w_i # Update i-th column of separation matrix

Expand Down

0 comments on commit 532fde3

Please sign in to comment.