I want to find two values of x
that intersect a certain value of y
on a x-y
plot of a resonance curve. However, as I have few data points I will need to interpolate to find these values of x
.
The curve I am looking at can be seen below:
How do I find the two values of x
that equal a y
value (shown in red)?
I have tried np.interpolate
by splitting the data into two arrays: first with gradient(y)>0
and another with gradient(y)<0
, however this yielded incorrect values. However, this approach is far from elegant and I seek a simple solution. Cheers in advance for any help.
Additional information: Code used thus far:
from numpy import *
import pylab as pl
import numpy as np
import scipy as scipy
from scipy import optimize
#Get data
fn = '4K_peak_hiresGhz.txt'
F_values, S_values, P_values = loadtxt(fn, unpack=True, usecols=[1, 2, 3])
#Select Frequency range of peak
lower = 4.995
upper = 5.002
F_values_2 = F_values[(F_values>lower) & (F_values<upper)]
S_values_2 = S_values[(F_values>lower) & (F_values<upper)]
P_values_2 = P_values[(F_values>lower) & (F_values<upper)]
#Calculate Q-value of selected peak
S_Peak = max(S_values_2)
print('S21 peak (dB):')
print(S_Peak)
print
F_Peak = F_values_2[S_values_2.argmax()]
print('Freq at S21 peak (GHz)')
print(F_Peak)
print
width_S = S_Peak - 3
print('S21 peak - 3dB (dB)')
print(width_S)
print
f, axarr = pl.subplots(2, sharex=False)
axarr[0].set_xlabel('Frequency (GHz)')
axarr[0].plot(F_values_2,S_values_2)
axarr[0].plot(F_values_2,S_values_2,'.')
axarr[0].set_ylabel('S21 (dB)')
axarr[0].axhline(y=width_S, linewidth='0.7', ls='dashed',color='red')
axarr[0].axhline(y=S_Peak, linewidth='1', ls='dashed', color='black')
axarr[0].axvline(x=F_Peak, linewidth='1', ls='dashed', color='black')
axarr[1].scatter(F_values_2, P_values_2)
axarr[1].set_ylabel('Phase (deg)')
axarr[1].set_xlabel('Frequency (GHz)')
pl.show()
Also, the data analysed in this program is found in this dpaste: http://dpaste.com/13AMJ92/