python – Is there a way to filter out a frequency?
np.argmax()
gives you the indices of the maximum values along some axis, see the documentation.
You subtract the indices from the values with:
frequency1 = frequencies - np.argmax(frequencies)
Instead, you wanted to remove the values at these indices, and the obtain the maximum value in the remaining data:
import numpy as np
data_fft = np.random.random(100) # I don't have your data, so generating some
frequencies = np.abs(data_fft)
print("The highest frequency is at position {}".format(np.argmax(frequencies)))
new_frequencies = np.delete(frequencies, np.argmax(frequencies))
print("The 2nd highest frequency is at position {}".format(np.argmax(new_frequencies)))
print("And its value is {}".format(np.max(new_frequencies)))
Although it’s a matter of style, the default string delimiter for Python is a single quote '
and you may find f-strings more readable:
import numpy as np
data_fft = np.random.random(100)
frequencies = np.abs(data_fft)
print(f'The highest frequency is at position {np.argmax(frequencies)}')
new_frequencies = np.delete(frequencies, np.argmax(frequencies))
print(f'The 2nd highest frequency is at position {np.argmax(new_frequencies)}')
print(f'And its value is {np.max(new_frequencies)}')
Read more here: Source link