The DSP block in edge impulse calculates processing like in flatten it does average only for X axis or y axis. is there a way i can access a list or np array of X,Y,Z after separating? so that i can apply correlation between the two or another function before appending to features
in the following way
i want to access the split data and apply fuction like np.corr() to X and Y
split out the data from all axes
for ax in range(0, len(axes)):
X = []
for ix in range(0, raw_data.shape[0]):
X.append(float(raw_data[ix][ax]))
# X now contains only the current axis
fx = np.array(X)
# process the signal here
fx = fx * scale_axes
# we need to return a 1D array again, so flatten here again
for f in fx:
features.append(f)
import numpy as np
def norm_data(data):
mean_data=np.mean(data)
std_data=np.std(data, ddof=1)
#return (data-mean_data)/(std_data*np.sqrt(data.size-1))
return (data-mean_data)/(std_data)
def _ncc(data0, data1):
"""
normalized cross-correlation coefficient between two data sets
Parameters
----------
data0, data1 : numpy arrays of same size
"""
return (1.0/(data0.size-1)) * np.sum(norm_data(data0)*norm_data(data1))
features = []
labels = []
an_array=[]
def generate_features(implementation_version, draw_graphs, raw_data, axes, sampling_freq, scale_axes):
# features is a 1D array, reshape so we have a matrix
raw_data = raw_data.reshape(int(len(raw_data) / len(axes)), len(axes))
# split out the data from all axes
for ax in range(0, len(axes)):
X = []
for ix in range(0, raw_data.shape[0]):
X.append(float(raw_data[ix][ax]))
# X now contains only the current axis
if ax=1:
fx = np.array(X)
fx = fx * scale_axes
if ax=2:
fy=np.array(Y)
fy = fy * scale_axes
if ax=3:
fz=np.array(Z)
fz = fz * scale_axes
X_1=norm_data(X)
Y_1=norm_data(Y)
Z_1=norm_data(Z)
X_2=norm_data(X2)
Y_2=norm_data(Y2)
Z_2=norm_data(Z2)
for i in range(0, len(axes)):
x__ncc=_ncc(X_1,X_2)
y__ncc=_ncc(Y_1,Y_2)
z__ncc=_ncc(Z_1,Z_2)
x1-y2__ncc=_ncc(X_1,Z_2)
x1-y2__ncc=_ncc(X_1,Y_2)
y1-x2__ncc=_ncc(Y_1,X_2)
y1-z2__ncc=_ncc(Y_1,Z_2)
z1-x2__ncc=_ncc(Z_1,X_2)
z1-y2__ncc=_ncc(Z_1,Y_2)
# we need to return a 1D array again, so flatten here again
features.append(x__ncc)
features.append(y__ncc)
features.append(z__ncc)
features.append(x1-y2__ncc)
features.append(y1-x2__ncc)
features.append(y1-z2__ncc)
features.append(z1-x2__ncc)
features.append(z1-y2__ncc)
features.append(f)
labels.append('Correlation')
return {
'features': features,
'graphs': [],
'labels': labels,
'output_config': { 'type': 'flat', 'shape': { 'width': len(features) } }
}
Hi @marvin, actually you can just get rid of the for ax in range(0, len(axes)) and write features directly. So similar to what you do in your second post.