Пример #1
0
 def __init__(self, fl):
     td = fl.TimeDescriptor()
     resp = [0 for _ in range(td.K)]
     resp[td.K // 2] = td.Fs
     resp[td.K // 2 + 1] = -resp[td.K // 2]
     ir = ImpulseResponse(td, resp)
     fr = ir.FrequencyResponse()
     FrequencyResponse.__init__(self, fl, fr.Response())
Пример #2
0
 def __init__(self, fl):
     """Constructor  
     Constructs the frequency response of a differentiator.
     @param fl instance of class EvenlySpacedFrequencyList containing list of frequencies for the differentiator
     @remark The resulting frequency response of a differentiator can be directly multiplied by another instance
     of FrequencyResponse such that the filter corresponding to the original frequency response now also differentiates
     the applied frequency content.
     """
     td = fl.TimeDescriptor()
     resp = [0 for _ in range(td.K)]
     resp[td.K // 2] = td.Fs
     resp[td.K // 2 + 1] = -resp[td.K // 2]
     ir = ImpulseResponse(td, resp)
     fr = ir.FrequencyResponse()
     FrequencyResponse.__init__(self, fl, fr.Response())
Пример #3
0
 def FrequencyResponse(self, ToP, FromP):
     """FrequencyResponse
     @param ToP integer receive port
     @param FromP integer driven port
     @return instance of class FrequencyResponse as the frequency response at port ToP due to waves driven at FromP.
     """
     return FrequencyResponse(self.f(), self.Response(ToP, FromP))
 def GetFrequencyResponseResult(self, fileName):
     #path=os.getcwd()
     #os.chdir(os.path.dirname(os.path.realpath(__file__)))
     if not os.path.exists(fileName):
         return None
     regression = FrequencyResponse().ReadFromFile(fileName)
     #os.chdir(path)
     return regression
 def CheckFrequencyResponseResult(self, fr, fileName, text):
     #path=os.getcwd()
     #os.chdir(os.path.dirname(os.path.realpath(__file__)))
     if not os.path.exists(fileName):
         fr.WriteToFile(fileName)
         self.assertTrue(False, fileName + ' not found')
     regression = FrequencyResponse().ReadFromFile(fileName)
     #os.chdir(path)
     self.assertTrue(regression == fr, text + ' incorrect')
Пример #6
0
    def FrequencyResponse(self, fd=None, adjustLength=True):
        """produces the frequency response

        impulse responses and frequency responses are equivalent and can be converted back
        and forth into each other.  This method converts the impulse response to its corresponding
        frequency domain equivalent.

        @attention users of this function should only either supply the fd argument or not.  Not
        supplying the argument provides the generic frequency response associated with this impulse
        response such that self.FrequencyResponse().ImpulseResponse() provides the same answer.

        Supplying fd supplies the resulting frequency response resampled onto another frequency scale.

        @param fd (optional) instance of class FrequencyList (defaults to None).
        @param adjustLength (optional) bool whether to adjust the length. (defaults to True).

        @note All impulse responses are evenly spaced

        @note whether a frequency descriptor is specified and whether to adjust length determines
        all possibilities of what can happen:

        | fd        | adjustLength | Generates:                              |
        |:---------:|:------------:|:---------------------------------------:|
        | None      |   False      | generic frequency response              |
        | None      |   True       | frequency response with length adjusted |
        | provided  |   don't care | CZT resamples to fd (adjusts length)    |

        The frequency descriptor, if provided, provides the frequency points to resample to, otherwise
        the frequency descriptor associated with the internal time descriptor inherent to the impulse
        response is used.

        Length adjustment means that although the impulse response may start at time zero, or some
        other time, the assumption is that there are an equal number of points for negative and positve
        time and that time zero is in the center of these points.

        This assumption for length adjustment is what allows an impulse response to be filled in with
        positive only times, but allow an equality to exist between all frequency responses and impulse
        responses.

        Basically, the time adjustment can be seen as calculating the number of points before time zero
        and the number of points after time zero and calculating the total number of points in the waveform
        (for the purposes of frequency response calculation) as the max of these two numbers multiplied by two.
        """
        # pragma: silent exclude
        from SignalIntegrity.Lib.FrequencyDomain.FrequencyResponse import FrequencyResponse
        # pragma: include
        if not fd and not adjustLength:
            X = fft.fft(self.Values())
            fd = self.td.FrequencyList()
            return FrequencyResponse(fd,[X[n] for n in range(fd.N+1)]).\
                _DelayBy(self.td.H)
        if not fd and adjustLength:
            return self._AdjustLength().FrequencyResponse(None,
                                                          adjustLength=False)
        if fd:
            return self.FrequencyResponse().Resample(fd)
Пример #7
0
 def FrequencyResponse(self, o, i):
     """frequency response of one filter
     @param o integer index of output
     @param i integer index of input
     @return instance of class FrequencyResponse corresponding to the frequency response of
     a filter used to convert input i to output o.
     """
     # pragma: silent exclude
     from SignalIntegrity.Lib.FrequencyDomain.FrequencyResponse import FrequencyResponse
     # pragma: include
     return FrequencyResponse(self.f,
                              [Matrix[o - 1][i - 1] for Matrix in self])
Пример #8
0
 def Resample(self, fl):
     """Resamples the s-parameters onto a new frequency scale
     @param fl list of frequencies to resample to.
     @return instance of class SParameters containing resampled s-parameters
     """
     if self.m_d is None:
         self.m_f = fl
         copy.deepcopy(self)
     fl = FrequencyList(fl)
     f = FrequencyList(self.f())
     f.CheckEvenlySpaced()
     SR = [empty((self.m_P, self.m_P)).tolist() for n in range(fl.N + 1)]
     for o in range(self.m_P):
         for i in range(self.m_P):
             res = FrequencyResponse(f, self.Response(o + 1,
                                                      i + 1)).Resample(fl)
             for n in range(len(fl)):
                 SR[n][o][i] = res[n]
     return SParameters(fl, SR, self.m_Z0)