I would like to get the frequency value of the second highest peak from the graph. I tried getting the frequencies which are nonzero, then sorting them in a descending order and getting the second value from that list. But it does not work that way. Below is the code for it. The file for replicating can be found here.
n = len(time)
fhat_A = np.fft.fft(channelA, n)
PSD_A = fhat_A * np.conj(fhat_A)/n
freq_A = (1/(0.0001*n)) * np.arange(n)
L_A = np.arange(1,np.floor(n/2),dtype='int')
plt.plot(freq_A[L_A], PSD_A[L_A], 'k', label='Noise_A')
plt.xlabel('Frequency [Hz]')
plt.ylabel('PSD [G^2/Hz]')
plt.title('Noise in Channel A Pipe03_2')
plt.legend(bbox_to_anchor=(0.6, -0.2), ncol=4)
plt.rcParams["figure.dpi"] = 300
plt.show()
The plot looks like below and I would like to know the PSD value of the red marked line. Is there a better way to do it? Only the real values are enough.
EDIT: Following is the code and result on using find_peaks. I do not understand why there are so many peaks shown on the x-axis.
from scipy.signal import find_peaks
peaks, _ = find_peaks(PSD_A[L_A], distance=30)
plt.plot(freq_A[L_A], PSD_A[L_A], 'k', label='Noise_A')
plt.plot(peaks, PSD_A[L_A][peaks], 'xr')