<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def welch(timeseries, segmentlength, noverlap=None, scheme=None, **kwargs):
 """Calculate a PSD using Welch's method with a mean average Parameters timeseries : `~gwpy.timeseries.TimeSeries` input `TimeSeries` data. segmentlength : `int` number of samples in single average. noverlap : `int` number of samples to overlap between segments, defaults to 50%. scheme : `pycbc.scheme.Scheme`, optional processing scheme in which to execute FFT, default: `None` **kwargs other keyword arguments to pass to :func:`pycbc.psd.welch` Returns ------- spectrum : `~gwpy.frequencyseries.FrequencySeries` average power `FrequencySeries` See also -------- pycbc.psd.welch """

    from pycbc.psd import welch as pycbc_welch

    # default to 'standard' welch
    kwargs.setdefault('avg_method', 'mean')

    # get scheme
    if scheme is None:
        scheme = null_context()

    # generate pycbc FrequencySeries
    with scheme:
        pycbc_fseries = pycbc_welch(timeseries.to_pycbc(copy=False),
                                    seg_len=segmentlength,
                                    seg_stride=segmentlength-noverlap,
                                    **kwargs)

    # return GWpy FrequencySeries
    fseries = FrequencySeries.from_pycbc(pycbc_fseries, copy=False)
    fseries.name = timeseries.name
    fseries.override_unit(scale_timeseries_unit(
        timeseries.unit, scaling='density'))
    return fseries