I have following code which is pretty simple measurement set for an amplifier. What i am ploting is the transfer curve of the amplifier output power vs gain. What i am doint next is i use the numpy package to let python calculate a polynom of 9th order which could describe my measurement data as best as possible.
The idea is when i have the polynom i could calculate for any output power level which i wish what value of gain could be expected.
So i get the coefficients and print them out and make a test run for desired output power of 52dBm what would be the gain and then print it out.
My problems are two:
- i want this calculated Gain value also to be plotted in the same figure so i could see it in the graph compared to the polynomial curve which is already plotted / fitted to the measured points.
this is solved. I added following plot code: plt.plot(52, test, marker = 'P', markersize=7 )
- i would have the coefficients also plotted as a polynom in the legend of the figure like y = c8x8^8 c7x7^7 ... c0.
I would be thankfull if someone could give me a hand. I attach also an image what exactly i have in mind.
import numpy as np
from scipy import interpolate
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib import style
out_pwr_m = np.array([46.95, 48.30, 49.96, 51.74, 53.03, 53.96, 54.85, 55.43, 56.00, 56.51, 56.97, 57.41, 57.80, 58.13, 58.20, 58.27, 58.32, 58.39, 58.47])
gain_m = np.array([74.55, 75.3, 75.66, 76.34, 76.73, 76.96, 77.15, 77.23, 77.3, 77.31, 77.27, 77.11, 76.8, 76.33, 76.196, 75.974, 75.818, 75.593, 75.365])
out_pwr_p = np.linspace(40, 60, 100)
p3 = np.polyfit(out_pwr_m, gain_m, 9)
gain_p = np.polyval(p3, out_pwr_p)
test = np.polyval(p3, 52)
style.use("bmh")
ticks_x = np.arange(46, 60, 0.6)
ticks_y = np.arange(74, 78, 0.25)
plt.figure(figsize=(10,6), dpi=250)
plt.xticks(ticks_x)
plt.yticks(ticks_y)
plt.plot(out_pwr_m, gain_m, 'Dr' )
plt.plot(out_pwr_p, gain_p, color = 'y', linestyle = '--')
plt.plot(test, '*')
plt.legend(['Daten', 'Polynomkurve 9-ter Ordnung'], loc = 'best')
plt.ylim(74, 78)
plt.xlim(46,59)
plt.xlabel("Output Power @ flange [dBm]", fontweight ='bold', size=11)
plt.ylabel("Gain [dB]", fontweight ='bold', size=11)
plt.annotate('y ={:.7g} x\xB8 {:.7g} x\xB7 {:.7g} x\xB6 {:.7g} x\xB5 {:.7g} x\xB4 {:.7g} x\xB3 {:.7g} x\xB2 {:.7g} x {:.7g}'.format(*p3))
print("P3 : \n", p3)
print(test)
CodePudding user response: