nnAudio
nnAudio copied to clipboard
Apply for multi-channel signal
I am working on multi-channel sEMG signal.
Is there possible if the API can be applied on the multi-channel signal in shape (n_channels, n_samples) to produce STFT data in shape (n_channels, n_frequencies, n_frames)?
My current solution is also separate each channel to process and then combine them together, but I wonder an other solution to process all channels in a rows
Thank you.
Although nnAudio does not support an extra channel dimension, there is a quick workaround for it.
Assume that your signal is of the sample (B, C, N), where B, C, and N are the batch size, n_channels, n_samples respectively.
Then you can reshape your signal into the shape of (B*C, N), which results in STFT output of the shape (B*C, F, T), where F is n_frequencies, and T is n_frames. You can simply reshape the STFT back to (B, C, F, T).
The code would be something like this
B, C, N = signal.shape
signal = signal.view(-1, N) # combining B and C dimension
spec = stft_layer(signal) # spec.shape=(B*C, F, T)
_, F, T = spec.shape
spec = spec.view(B, C, F, T) # reshape spec to retrieve the channel dimension
Great! Thank you for your suggestion so much!