<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def resample(self, rate, window='hamming', ftype='fir', n=None):
 """Resample this Series to a new rate Parameters rate : `float` rate to which to resample this `Series` window : `str`, `numpy.ndarray`, optional window function to apply to signal in the Fourier domain, see :func:`scipy.signal.get_window` for details on acceptable formats, only used for `ftype='fir'` or irregular downsampling ftype : `str`, optional type of filter, either 'fir' or 'iir', defaults to 'fir' n : `int`, optional if `ftype='fir'` the number of taps in the filter, otherwise the order of the Chebyshev type I IIR filter Returns ------- Series a new Series with the resampling applied, and the same metadata """

        if n is None and ftype == 'iir':
            n = 8
        elif n is None:
            n = 60

        if isinstance(rate, units.Quantity):
            rate = rate.value
        factor = (self.sample_rate.value / rate)
        # NOTE: use math.isclose when python >= 3.5
        if numpy.isclose(factor, 1., rtol=1e-09, atol=0.):
            warnings.warn(
                "resample() rate matches current sample_rate ({}), returning "
                "input data unmodified; please double-check your "
                "parameters".format(self.sample_rate),
                UserWarning,
            )
            return self
        # if integer down-sampling, use decimate
        if factor.is_integer():
            if ftype == 'iir':
                filt = signal.cheby1(n, 0.05, 0.8/factor, output='zpk')
            else:
                filt = signal.firwin(n+1, 1./factor, window=window)
            return self.filter(filt, filtfilt=True)[::int(factor)]
        # otherwise use Fourier filtering
        else:
            nsamp = int(self.shape[0] * self.dx.value * rate)
            new = signal.resample(self.value, nsamp,
                                  window=window).view(self.__class__)
            new.__metadata_finalize__(self)
            new._unit = self.unit
            new.sample_rate = rate
            return new