function signalOut = performPreprocessing(in)
%#codegen
%Resize the signals

targetLengthtest = 5000;
 
sigIn = in;


% Ensure column vector
sigIn = sigIn(:);

    
% Compute the number of targetLength-sample chunks in the signal
numSigs = floor(length(sigIn)/targetLengthtest);


% Truncate to a multiple of targetLength
sigIn = sigIn(1:numSigs*targetLengthtest);

% Create a matrix with as many columns as targetLength signals
sigReshaped= reshape(sigIn,targetLengthtest,numSigs).';


%Pad with zeroes

sigOut = zeros(numSigs,5127,'single');
sigOut(1:numSigs,65:5064)=sigReshaped;

%Perform STFT for feature extraction
 
Fs =250;
sz = size(sigOut);

signalSTFT = cell(1,sz(1));  
signalOut = cell(1,sz(1));
meanValue = zeros(40,sz(1),'single');
stdValue = zeros(40,sz(1),'single');
temp = zeros(40,5000,'single');

for idx = 1:numSigs
   [s,f,~] = stft(sigOut(idx,:),Fs,'Window',kaiser(128),'OverlapLength',127);
   f_indices =  (f > 0.5) & (f < 40);
   signalSTFT{idx}= [real(s(f_indices,:)); imag(s(f_indices,:))]; 
   
   meanValue(:,idx)= mean(signalSTFT{idx},2);
   stdValue(:,idx) = std(signalSTFT{idx},[],2);
end

meanValue = mean(meanValue,2);
stdValue = mean(stdValue,2);

for idx =1:length(signalSTFT)
    
    for idx2 = 1:40
    
     temp(idx2,:)= (signalSTFT{idx}(idx2,:) - meanValue(idx2,1))/stdValue(idx2,1);
 
     end
      
      signalOut{idx} = temp;

    
end

end