当前位置: 首页>>代码示例>>Python>>正文


Python Device.readRMS方法代码示例

本文整理汇总了Python中device.Device.readRMS方法的典型用法代码示例。如果您正苦于以下问题:Python Device.readRMS方法的具体用法?Python Device.readRMS怎么用?Python Device.readRMS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在device.Device的用法示例。


在下文中一共展示了Device.readRMS方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import readRMS [as 别名]
class Waveform:

    def __init__(self, startFreq=0, endFreq=0, numSamples=0):
        if numSamples == 0:
            self.numSamples = numSamples
            self.frequencies = []
            self.voltRms = []
        else:
            self.frequencies = []
            self.voltRms = []
            self.device = Device()
            self.device.enableInput(5)
            self.device.enableOutput(1.41)
            self.numSamples = numSamples

            startl = math.log10(startFreq)
            endl = math.log10(endFreq)

            delta = (endl - startl) / (numSamples - 1)

            for i in range(0, numSamples):
                freq = 10 ** startl
                rms = self.device.readRMS(freq, int(freq * 32))
                if not math.isnan(rms):
                    self.frequencies.append(freq)
                    self.voltRms.append(rms)

                startl += delta

    def writeToFile(self, fileName):
        fHandle = open(fileName, 'w+')
        for freq, vrms in zip(self.frequencies, self.voltRms):
            fHandle.write(str(freq) + ', ' + str(vrms) + '\n')
        fHandle.close()

    def loadFromFile(self, fileName):
        with open(fileName) as f:
            for line in f:  # read rest of lines
                freq, vrms = [float(x) for x in line.split(',')]
                self.frequencies.append(freq)
                self.voltRms.append(vrms)
                self.numSamples += 1

    def dumpData(self):
        for freq, vrms in zip(self.frequencies, self.voltRms):
            print 'Freq:', freq, '\tVrms:', vrms

    def getDeviation(self, w):
        result = Waveform()
        for freq, vrms1, vrms2 in zip(self.frequencies, self.voltRms, w.voltRms):
            result.frequencies.append(freq)
            result.voltRms.append(vrms1-vrms2)
        return result
开发者ID:vthanki,项目名称:MiscCode,代码行数:55,代码来源:waveform.py


注:本文中的device.Device.readRMS方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。