Exemplo n.º 1
0
 def __init__(self,f=None,resp=None):
     """Constructor
     @param f instance of class FrequencyList
     @param resp list of complex values
     @remark
     It is assumed that the frequencies and the response provided were generated from
     the FrequencyResponse() method of the class ImpulseResponse."""
     FrequencyDomain.__init__(self,f,resp)
Exemplo n.º 2
0
    def __init__(self, wf, fd=None):
        """Constructor
        @param wf in instance of class Waveform
        @param fd (optional) an instance of class FrequencyList (defaults to None)
        @remark
        initializes itself internally by computing the frequency content of the waveform.

        If fd is None then the frequency descriptor is simply the frequency descriptor corresponding to the time
        descriptor of the waveform and the frequency content is computed from the DFT.

        Otherwise, the CZT is used to compute the frequency content and the time descriptor corresponds to the
        frequency descriptor.

        the time descriptor and frequency descriptor are retained so a waveform can be obtained from the frequency content.

        @note the frequency content is scaled differently from the raw DFT or CZT outputs in that the absolute value of each
        complex number in the frequency content represents the amplitude of a cosine wave.  This is not true with the raw
        DFT output and scaling things this way helps in the proper interpretation of the frequency content without having
        to think about the vagaries of the DFT.

        @see TimeDescriptor
        @see FrequencyList
        @see ChirpZTransform
        """
        td = wf.td
        if fd is None:
            X = fft.fft(wf.Values())
            K = int(td.K)
            Keven = (K // 2) * 2 == K
            fd = td.FrequencyList()
        else:
            # pragma: silent exclude
            if not fd.EvenlySpaced():
                raise SignalIntegrityExceptionWaveform(
                    'cannot generate frequency content')
            # pragma: include
            K = fd.N * 2
            Keven = True
            X = CZT(wf.Values(), td.Fs, 0, fd.Fe, fd.N, True)
            td = TimeDescriptor(td.H, fd.N * 2, fd.Fe * 2.)
        FrequencyDomain.__init__(self,fd,[X[n]/K*\
            (1. if (n==0 or ((n==fd.N) and Keven)) else 2.)*\
            cmath.exp(-1j*2.*math.pi*fd[n]*td.H) for n in range(fd.N+1)])
        self.td = td
Exemplo n.º 3
0
    def Values(self, unit=None):
        """frequency content values
        @param unit (optional) string containing the unit for the values desired.
        @return a list of complex values representing the frequency content.
        @remark
        Valid frequency content units are:\n
        - 'rms' - the root-mean-squared (rms) value.
        - 'dBm' - the values in decibels were 0 dBm corresponds to the voltage needed to deliver
        1 mW to a 50 ohm load.  It's computed as 20*Log(rms)+13.010.
        - 'dBmPerHz' - the spectral density in dBm/Hz.

        If no unit is specified, the complex frequency content is returned.
        If no valid frequency content units are found, then it defers to the FrequencyDomain base class.

        @see FrequencyDomain.
        """
        if unit == 'rms':
            Keven = (self.td.K / 2) * 2 == self.td.K
            A = FrequencyDomain.Values(self, 'mag')
            return [
                A[n] / (1 if (n == 0 or
                              ((n == self.m_f.N) and Keven)) else math.sqrt(2))
                for n in range(len(A))
            ]
        elif unit == 'dBm':
            return [
                -3000. if r < 1e-15 else 20. * math.log10(r) - self.LogRP10
                for r in self.Values('rms')
            ]
        elif unit == 'dBmPerHz':
            Keven = (self.td.K / 2) * 2 == self.td.K
            Deltaf = self.m_f.Fe / self.m_f.N
            adder = -10 * math.log10(Deltaf)
            dBm = self.Values('dBm')
            return [
                dBm[n] + adder +
                (self.dB3 if (n == 0 or ((n == self.m_f.N) and Keven)) else 0)
                for n in range(len(dBm))
            ]
        else:
            return FrequencyDomain.Values(self, unit)