def plotTestPhase(): fig, ax = plt.subplots() N = 256 freq = 1111 I = [0]*N timeList = makeTimeList(I, 0, sm.STEP) phase = 1 amp = 1.2 I = amp*np.sin(2*math.pi*freq*np.array(timeList)+phase) (c0,csin, ccos) = sm.calcSinCosMatrix(I, freq, sm.STEP) (amplitude, fi) = sm.calcFi(csin, ccos) print("c0=", c0) print("phase=", phase, "delta=", fi-phase) print("amplitude=", amplitude) Q = csin*np.sin(2*math.pi*freq*np.array(timeList))+ccos*np.cos(2*math.pi*freq*np.array(timeList))+c0 #freq = 1000 ax.plot(timeList, I, color='red') ax.plot(timeList, Q, color='blue') plt.show()
def scanFreq(): freq = getFreq() IArray = [] QArray = [] FIarray = [] fsin = [] for f in freq: print("f=", f) (ISampes, QSampes) = getSamplesByFreq(f) I = sqrMean(ISampes) Q = sqrMean(QSampes) print("getSqrByFreq=", I, Q) IArray.append(I) QArray.append(Q) # freqDelta = 1 # freqCenter = 1000 freqDelta = 0.5 freqCenter = 999.6 count = 101 (freqArr, Fmath) = sm.arrayFreq(QSampes, freqCenter - freqDelta, freqCenter + freqDelta, sm.STEP, count) fmax = sm.findFreqMax(freqArr, Fmath) fsin.append(fmax) (Ic0, Isin, Icos) = sm.calcSinCosMatrix(ISampes, fmax, sm.STEP) (Qc0, Qsin, Qcos) = sm.calcSinCosMatrix(QSampes, fmax, sm.STEP) (Iamplitude, Ifi) = sm.calcFi(Isin, Icos) (Qamplitude, Qfi) = sm.calcFi(Qsin, Qcos) FIarray.append(Ifi - Qfi) print("fmax=", fmax, "fi=", Ifi - Qfi) pass jout = {} jout["freq"] = freq jout["I"] = IArray jout["Q"] = QArray jout["fsin"] = fsin jout["fi"] = FIarray f = open("freq.json", "wt") f.write(json.dumps(jout)) f.close() pass