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: pop_rejspec.m
    path of file: ./repos/eeglab/functions/popfunc
    
    the code of the file until where you have to start completion: % POP_REJSPEC - rejection of artifact in a dataset using 
%                 thresholding of frequencies in the data.
% Usage:
%   >>  pop_rejspec(INEEG, typerej); % pop-up interactive window mode
%   >> [OUTEEG, Indices] = pop_rejspec( INEEG, typerej, 'key', val, ...);
%
% Pop-up window options:
% "Electrode|Component" - [edit box] electrode or component indices to 
%                 take into consideration for rejection. Sets the 'elecrange'
%                 parameter in 
    
function [specdata, Irej, Erej, freqs ] = spectrumthresh( data, specdata, elecrange, srate, negthresh, posthresh, startfreq, endfreq, method);

	% compute the fft if necessary - old version
    if isempty(specdata)
        if strcmpi(method, 'fft')
            sizewin = size(data,2);
            freqs = srate*[1, sizewin]/sizewin/2;
            specdata = fft( data-repmat(mean(data,2), [1 size(data,2) 1]), sizewin, 2);
            specdata = specdata( :, 2:sizewin/2+1, :);
            specdata = 10*log10(abs( specdata ).^2);
            specdata  = specdata - repmat( mean(specdata,3), [1 1 size(data,3)]);
        else
            if ~exist('pmtm')
                error('The signal processing toolbox needs to be installed');
            end