You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: perceptualCentroid.m
    path of file: ./repos/CellExplorer/toolboxes/+iosr/+auditory
    
    the code of the file until where you have to start completion: function [PCmean,PCstd,PCmax,PCmin,N] = perceptualCentroid(x,fs,varargin)
%PERCEPTUALCENTROID Perceptual spectral centroid
% 
%   PCMEAN = IOSR.AUDITORY.PERCEPTUALCENTROID(X,FS) calculates the spectral
%   centroid of signal X, sampled at FS, with respect to mel-frequency.
%   
%   The algorithm first calculates the spectrogram of X; each segment has
%   the maximum of length(X)/8 or 2048 samples, calculated with 50% overlap
%   and windowed with a hamming window. The spectrogram function is the
%   built-in Matlab function SPECTROGRAM. The centroid is calculated with
%   respect to mels by converting the FFT bin frequencies to mels. PCMEAN
%   is the mean of the perceptual spectral centroids calculated for each
%   segment. The perceptual spectral centroid can also be calculated using
%   ERBs, cents, or hertz (see below).
% 
%   X can be a vector, matrix, or multidimensional array;
%   PERCEPTUALCENTROID will operate along the first non-signleton
%   dimension, and return a value for each corresponding row/column/etc.
% 
%   PCMEAN = IOSR.AUDITORY.PERCEPTUALCENTROID(X,FS,'PARAMETER',VALUE)
%   allows numerous parameters to be specified. These parameters are:-
%       'cref'     : {27.5} | scalar
%           Specifies the reference frequency when calulating the centroid
%           in terms of cents.
%       'dim'      : {first non-singleton dimension} | integer
%           Specify the dimension over which to calculate the perceptual
%           spectral centroid.
%       'loudness' : {'none'} | 'A' | 'B' | 'C' | 'D' | 'ISO-226'
%           Specifies whether loudness weighting is applied to the spectrum
%           prior to the centroid calculation. The default is for no
%           weighting to be applied. 'A', 'B', 'C', and 'D'  correspond to
%           frequency weighting curves defined in IEC 61672:2003; 'ISO-226'
%           applies loudness weighting derived from ISO 226:2003.
%       'nfft'     : {max([length(x)/2, 2048])} | integer
%           Specifies SPECTROGRAM's FFT size.
%       'noverlap' : {nfft/2} | integer
%           Specifies the number of samples over which SPECTROGRAM's
%           segments overlap.
%       'output'   : {'units'} | 'hz'
%           Specifies whether the output data are in Hz ('hz') or in units
%           determined by the 'scale' option ('units') (default).
%       'phon'     : {65} | scalar
%           Specifies the loudness level if using ISO 226:2003-based
%           loudness weighting.
%       'scale'    : {'mel'} | 'linear' | 'erb' | 'cents'
%           Specifies frequency scale use to calculate the centroid. 'mel'
%           uses the mel-frequency scale, 'linear' uses a linear frequency
%           scale (corresponding to the traditional spectral centroid
%           measure), 'erb' uses the equivalent-rectangular-bandwidth-rate
%           scale, and cents uses a scale based on musical cents with
%           respect to A-1 (27.5 Hz).
%       'window'   : {hamming(nfft)} | vector
%           Specifies the window applied to each SPECTROGRAM segment.
% 
%   [PCMEAN,PCSTD,PCMAX,PCMIN,N] = ... returns additional information:-
%       PCMEAN : as described above.
%       PCSTD  : the standard deviation of the perceptual spectral
%                centroids.
%       PCMAX  : the maximum of the perceptual spectral centroids.
%       PCMIN  : the minimum of the perceptual spectral centroids.

    
function [PCmean,PCstd,PCmax,PCmin,N] = perceptualCentroid(x,fs,varargin)
%PERCEPTUALCENTROID Perceptual spectral centroid
% 
%   PCMEAN = IOSR.AUDITORY.PERCEPTUALCENTROID(X,FS) calculates the spectral
%   centroid of signal X, sampled at FS, with respect to mel-frequency.
%   
%   The algorithm first calculates the spectrogram of X; each segment has
%   the maximum of length(X)/8 or 2048 samples, calculated with 50% overlap
%   and windowed with a hamming window. The spectrogram function is the
%   built-in Matlab function SPECTROGRAM. The centroid is calculated with
%   respect to mels by converting the FFT bin frequencies to mels. PCMEAN
%   is the mean of the perceptual spectral centroids calculated for each
%   segment. The perceptual spectral centroid can also be calculated using
%   ERBs, cents, or hertz (see below).
% 
%   X can be a vector, matrix, or multidimensional array;
%   PERCEPTUALCENTROID will operate along the first non-signleton
%   dimension, and return a value for each corresponding row/column/etc.
% 
%   PCMEAN = IOSR.AUDITORY.PERCEPTUALCENTROID(X,FS,'PARAMETER',VALUE)
%   allows numerous parameters to be specified. These parameters are:-
%       'cref'     : {27.5} | scalar
%           Specifies the reference frequency when calulating the centroid
%           in terms of cents.
%       'dim'      : {first non-singleton dimension} | integer
%           Specify the dimension over which to calculate the perceptual
%           spectral centroid.
%       'loudness' : {'none'} | 'A' | 'B' | 'C' | 'D' | 'ISO-226'
%           Specifies whether loudness weighting is applied to the spectrum
%           prior to the centroid calculation. The default is for no
%           weighting to be applied. 'A', 'B', 'C', and 'D'  correspond to
%           frequency weighting curves defined in IEC 61672:2003; 'ISO-226'
%           applies loudness weighting derived from ISO 226:2003.
%       'nfft'     : {max([length(x)/2, 2048])} | integer
%           Specifies SPECTROGRAM's FFT size.
%       'noverlap' : {nfft/2} | integer
%           Specifies the number of samples over which SPECTROGRAM's
%           segments overlap.
%       'output'   : {'units'} | 'hz'
%           Specifies whether the output data are in Hz ('hz') or in units
%           determined by the 'scale' option ('units') (default).
%       'phon'     : {65} | scalar
%           Specifies the loudness level if using ISO 226:2003-based
%           loudness weighting.
%       'scale'    : {'mel'} | 'linear' | 'erb' | 'cents'
%           Specifies frequency scale use to calculate the centroid. 'mel'
%           uses the mel-frequency scale, 'linear' uses a linear frequency
%           scale (corresponding to the traditional spectral centroid
%           measure), 'erb' uses the equivalent-rectangular-bandwidth-rate
%           scale, and cents uses a scale based on musical cents with
%           respect to A-1 (27.5 Hz).
%       'window'   : {hamming(nfft)} | vector
%           Specifies the window applied to each SPECTROGRAM segment.
% 
%   [PCMEAN,PCSTD,PCMAX,PCMIN,N] = ... returns additional information:-
%       PCMEAN : as described above.
%       PCSTD  : the standard deviation of the perceptual spectral
%                centroids.
%       PCMAX  : the maximum of the perceptual spectral centroids.
%       PCMIN  : the minimum of the perceptual spectral centroids.
%       N      : the sample size for each statistic.
% 
%   For more information about the FFT calculation and its options, consult
%   the SPECTROGRAM documentation.
% 
%   Examples
% 
%     Example 1: Calculate the mel-frequency spectral centroid of random
%       noise:
% 
%       fs = 44100;
%       x = randn(fs,1);
%       PC = iosr.auditory.perceptualCentroid(x,fs);
% 
%     Example 2: Calculate the ERB-spaced spectral centroid of random
%       noise with the output in Hertz:
% 
%       PC = iosr.auditory.perceptualCentroid(x,fs,...
%           'scale','erb','output','hz');
% 
%     Example 3: Calculate the musically-spaced spectral centroid of
%       random noise using a 4096-point Hann window:
% 
%       PC = iosr.auditory.perceptualCentroid(x,fs,...
%           'scale','cents','window',hann(4096));
% 
%   Authors: Chris Hummersone & Kirsten Hermes, 2014
%   
%   See also SPECTROGRAM.

%   Copyright 2016 University of Surrey.

    %% read inputs and make default assignments

    assert(~isscalar(x), 'iosr:perceptualCentroid:invalidX', '''X'' cannot be a scalar')

    dims = size(x);

    propNames = {'dim','nfft','noverlap','window','scale','output','cref','loudness','phon'}; % permitted prop names

    options = struct;
    % read parameter/value options
    if nargin>2 % if parameters are specified
        % count arguments
        nArgs = length(varargin);
        if round(nArgs/2)~=nArgs/2
           error('iosr:perceptualCentroid:nameValuePairs','PERCEPTUALCENTROID needs propertyName/propertyValue pairs following the x and fs arguments.')
        end