def CheckWaveformResult(self, wf, fileName, text):
        #path=os.getcwd()
        #os.chdir(os.path.dirname(os.path.realpath(__file__)))
        if not os.path.exists(fileName):
            wf.WriteToFile(fileName)
            self.assertTrue(False, fileName + ' not found')
        regression = Waveform().ReadFromFile(fileName)
        wfsAreEqual = (regression == wf)
        if not wfsAreEqual:
            if ResponseTesterHelper.plotErrors:
                import matplotlib.pyplot as plt
                plt.clf()
                plt.title(fileName)
                plt.xlabel('time (s)')
                plt.ylabel('amplitude')
                plt.semilogy(regression.Times(), [
                    abs(wf[k] - regression[k]) for k in range(len(regression))
                ])
                plt.grid(True)
                plt.show()

                plt.clf()
                plt.title(fileName)
                plt.xlabel('time (s)')
                plt.ylabel('amplitude')
                plt.plot(wf.Times(), wf.Values(), label='calculated')
                plt.plot(regression.Times(),
                         regression.Values(),
                         label='regression')
                plt.legend(loc='upper right')
                plt.grid(True)
                plt.show()
        #os.chdir(path)
        self.assertTrue(wfsAreEqual, text + ' incorrect')
Ejemplo n.º 2
0
    def __init__(self,
                 td,
                 Amplitude=1.,
                 Frequency=1e6,
                 Phase=0.,
                 StartTime=-100.,
                 StopTime=100.):
        """Constructor

        constructs a sinewave waveform.

        @param td instance of class TimeDescriptor containing time axis of waveform.
        @param Amplitude (optional) float amplitude of sine wave (defaults to unity).
        @param Frequency (optional) float frequency of sine wave (defaults to 1 MHz).
        @param Phase (optional) float phase of sine wave in degrees (defaults to zero).
        @param StartTime (optional) float start time of sine wave (defaults to -100 s).
        @param StopTime (optional) float stop time of the sine wave (defaults to 100 s).
        """
        x = [
            Amplitude *
            math.sin(2. * math.pi * Frequency * t + Phase / 180. * math.pi)
            for t in td.Times()
        ]
        sw = Waveform(td, x) * PulseWaveform(
            td,
            Amplitude=1.,
            StartTime=StartTime,
            PulseWidth=max(StartTime, StopTime) - min(StartTime, StopTime),
            Risetime=0.)
        Waveform.__init__(self, sw.td, sw.Values())