def freqResp(start=100, end=2400, delta=50, repeat=10,powerlevel=7): """ Runs adc5g.get_psd for a range of frequenciesi in MHz. The actual frequencies are picked to have an odd number of cycles in the 16384 point snapshot. (This part is copied from multifreq()). Writes out freq and max() of spectrum to freqResponse.dat file. """ set_pwr(powerlevel) frfile = open('freqResponse.dat', 'a') f = samp_freq / numpoints nstart = int(0.5+start/f) nend = int(0.5+end/f) nstep = int(0.5+delta/f) for n in range(nstart, nend, nstep): freq = f*n set_freq(freq) # dopsd(rpt=3) for i in range(repeat): power, freqs = adc5g.get_psd(roach2, snap_name, samp_freq*1e6, 8, numpoints) if i == 0: sp = power else: sp += power sp /= repeat power=10*log10(sp) # step(freqs, power) peakpower=max(power) print freq,peakpower output="%f %f\n" % (freq,peakpower) frfile.write(output) frfile.close()
def freqResp(start=100, end=2400, delta=50, repeat=10, powerlevel=7): """ Runs adc5g.get_psd for a range of frequenciesi in MHz. The actual frequencies are picked to have an odd number of cycles in the 16384 point snapshot. (This part is copied from multifreq()). Writes out freq and max() of spectrum to freqResponse.dat file. """ set_pwr(powerlevel) frfile = open('freqResponse.dat', 'a') f = samp_freq / numpoints nstart = int(0.5 + start / f) nend = int(0.5 + end / f) nstep = int(0.5 + delta / f) for n in range(nstart, nend, nstep): freq = f * n set_freq(freq) # dopsd(rpt=3) for i in range(repeat): power, freqs = adc5g.get_psd(roach2, snap_name, samp_freq * 1e6, 8, numpoints) if i == 0: sp = power else: sp += power sp /= repeat power = 10 * log10(sp) # step(freqs, power) peakpower = max(power) print freq, peakpower output = "%f %f\n" % (freq, peakpower) frfile.write(output) frfile.close()
def dopsd(nfft=None, rpt=10, plotdB=True): """ Takes a snapshot, then computes, plots and writes out the Power Spectral Density functions. The psd function is written into a file named "psd". This file will be overwritten with each call. Arguments: nfft The number of points in the psd function. Defaults to the number of points in a snapshot, the maximum which should be used. rpt The numper of mesurements to be averaged for the plot and output file. Defaults to 10. plotdB controls whether the plot is linear in power or in dB """ if nfft == None: nfft = numpoints for i in range(rpt): power, freqs = adc5g.get_psd(roach2, snap_name, samp_freq * 1e6, 8, nfft) if i == 0: sp = power else: sp += power sp /= rpt if plotdB: plt.step(freqs, 10 * np.log10(sp)) else: plt.step(freqs, (sp)) plt.show(block=False) data = np.column_stack((freqs / 1e6, 10 * np.log10(sp))) np.savetxt("psd", data, fmt=('%7.2f', '%6.1f'))
def dopsd(nfft = None, rpt = 10, plotdB=True): """ Takes a snapshot, then computes, plots and writes out the Power Spectral Density functions. The psd function is written into a file named "psd". This file will be overwritten with each call. Arguments: nfft The number of points in the psd function. Defaults to the number of points in a snapshot, the maximum which should be used. rpt The numper of mesurements to be averaged for the plot and output file. Defaults to 10. plotdB controls whether the plot is linear in power or in dB """ if nfft == None: nfft = numpoints for i in range(rpt): power, freqs = adc5g.get_psd(roach2, snap_name, samp_freq*1e6, 8, nfft) if i == 0: sp = power else: sp += power sp /= rpt if plotdB: plt.step(freqs, 10*np.log10(sp)) else: plt.step(freqs, (sp)) plt.show(block = False) data = np.column_stack((freqs/1e6, 10*np.log10(sp))) np.savetxt("psd", data, fmt=('%7.2f', '%6.1f'))
def dopsd(nfft = numpoints, rpt = 10): """ Takes a snapshot, then computes, plots and writes out the Power Spectral Density functions. The psd function is written into a file named "psd". This file will be overwritten with each call. Arguments: nfft The number of points in the psd function. Defaults to 16384. Since a snapshot has 16384 points, this is the maximum which should be used rpt The numper of mesurements to be averaged for the plot and output file. """ for i in range(rpt): power, freqs = adc5g.get_psd(roach2, snap_name, samp_freq*1e6, 8, nfft) if i == 0: sp = power else: sp += power sp /= rpt plt.step(freqs, 10*np.log10(sp)) data = np.column_stack((freqs/1e6, 10*np.log10(sp))) np.savetxt("psd", data, fmt=('%7.2f', '%6.1f'))
def dopsd(nfft=numpoints, rpt=10): """ Takes a snapshot, then computes, plots and writes out the Power Spectral Density functions. The psd function is written into a file named "psd". This file will be overwritten with each call. Arguments: nfft The number of points in the psd function. Defaults to 16384. Since a snapshot has 16384 points, this is the maximum which should be used rpt The numper of mesurements to be averaged for the plot and output file. """ for i in range(rpt): power, freqs = adc5g.get_psd(roach2, snap_name, samp_freq * 1e6, 8, nfft) if i == 0: sp = power else: sp += power sp /= rpt plt.step(freqs, 10 * np.log10(sp)) data = np.column_stack((freqs / 1e6, 10 * np.log10(sp))) np.savetxt("psd", data, fmt=('%7.2f', '%6.1f'))