I am doing some processing with a matrix of shape 1536 x 16 x 48. Here are some details about this dimensions:
- 1536: data collected in 6 seconds
- 16: number of collectors (or electrodes in my case)
- 48: number of samples
So, i have 48 samples of 1536 values (representing 6 seconds of data) from the perspective of 16 different collectors.
My goal is to do some processing with this matrix, but to do so some transformations are needed first.
Since 6 seconds is a large sequence, i want to split each of those samples into smaller sequences, specially 3 or 2 seconds. For instance, 1 sample of 6 seconds (1536) can be split into 2 samples of 3 seconds (768) or 3 samples of 2 seconds (512). The shape of this transformed matrix would go from
1536x16x48to768x16x96(for 3 seconds) or512x16x144(for 2 seconds).Once i have this new matrix, i want to reshape it so i get one 2d matrix per observer and all values organized in columns instead of rows (e.g. for 2 seconds split:
512x16x144=>144x512x16).Finally, i can now loop through 3rd dimension (
16), do some computations (i.e. fast fourier transform) with each 2d matrix and reduce (sum) them all into a single one to get a final144 x 512matrix (in 2 seconds-split scenario).
The following code is what i made with numpy, but it is clearly wrong for me when i plot samples generated from this method.
def generate_fft_data(data,labels, n_seconds_split=3):
x = 256 * n_seconds_split
y = 16
z = 48 * int(6/n_seconds_split)
data = data.transpose(2,0,1).reshape(x,y,z).transpose(2,0,1)
fft_data = []
for electrode in range(data.shape[2]):
y_t = fft(data[:,:,electrode])
fft_data.append(np.abs(y_t))
sum_of_ffts = np.add.reduce(fft_data)
return sum_of_ffts
I can provide more details if needed. Thanks in advance.