I'm trying to find the peaks of and EMG signal which i converted into the frequency domain with the use of FFT. My problem is that when I try to use the command Find_peaks from the scipy.signal libraries it gives me a warning of ValueError: x
must be a 1D array. could someone please point me in the right path because I am having a hard time of understanding how I could find the peaks of my signal in the frequency domain, should I convert it back to the time domain or should I find a way to compress the array. (P.S. I am still a newbie, all the help is much appreciated).This is what I was able to code
Asked
Active
Viewed 422 times
0

Aaron Sy
- 3
- 2
-
By peak, do you mean intensity peak through time, or do you mean frequency peak ? I can't see your code, but maybe you should verify if x is indeed a 1D array first – Victor Deleau Nov 10 '19 at 16:52
-
Welcome to StackOverflow! If you nest your copy-pasted code in triple-backticks (`), you can render it with syntax-highlighting inline in your question. That way, in the future, other viewers will be able to see it even if that image hosting goes down. – j6m8 Nov 10 '19 at 16:54
-
That's a really bad practice to name your data pd, when you import pandas as pd. Probably the problem is when you say ```y = pd```. – Péter Leéh Nov 10 '19 at 17:09
-
@Péter Leéh, j6m8 was correct the problem was I was trying to use find_peaks which was 1D while my output from fft was a multi-dimensional array. For now I am totally clueless what I am gonna do. I am trying to search for other libraries that I could use. – Aaron Sy Nov 10 '19 at 17:14
-
You have to show us a little part of your dataframe, this way we can't really help. – Péter Leéh Nov 10 '19 at 17:20
1 Answers
1
The results of scipy's FFT is a multi-dimensional array that includes complex-number results of the transform, represented as a 2-element vector. The find_peaks
call can only accept a 1D array. You may need to either convert these to a scalar (perhaps take the absolute value of the tuples), or you can use a peak detector that operates in more domains. Check out this related question for some options.
If you convert to 1D, peakutil is a package that may help you (though it doesn't appear to be dramatically more powerful than find_peaks
for your needs).
For more details, you can also see some of the answers to the questions here, a related question.

j6m8
- 2,261
- 2
- 26
- 34
-
I already have tried peakutils. However I have no clue how to unpack the data because it gave a too many values to unpack error – Aaron Sy Nov 10 '19 at 16:58
-
Can you share where you're getting that error message? I'd definitely recommend converting that data into a 1D array; numpy has some great utilities to reduce the dimensions of an array. You most likely want to take the absolute value of the array with [`np.absolute` (docs)](https://docs.scipy.org/doc/numpy/reference/generated/numpy.absolute.html), which should perform the reduction you want. But you can also simply _only_ take the _real_ portion of your FFT output, using numpy indexing (e.g. `data[:, 0]`) – j6m8 Nov 10 '19 at 22:11
-
1thanks alot I finished the code last night i used the ravel command to convert it to a 1D array I will post the picture of the graph – Aaron Sy Nov 11 '19 at 01:51