function y = featureExtraction(x,Fs)
% FEATUREEXTRACTION computes the Fourier synchrosqueezed transform of the
% ECG signal frames over the frequency range of interest, [0.5, 40] Hz, and
% standardizes the resulting transforms by subtracting the mean and
% dividing by the standard deviation.

% Copyright 2020 The MathWorks, Inc.

meanTrain = cell(1,length(x));
stdTrain = cell(1,length(x));
for idx = 1:length(x)
   [s,f] = fsst(x{idx},Fs,kaiser(128));

   f_indices = (f > 0.5) & (f < 40);
   x{idx}= [real(s(f_indices,:)); imag(s(f_indices,:))];

   meanTrain{idx} = mean(x{idx},2);
   stdTrain{idx} = std(x{idx},[],2);
end
standardizeFun = @(x) (x - mean(cell2mat(meanTrain),2))./mean(cell2mat(stdTrain),2);
y = cellfun(standardizeFun,x,'UniformOutput',false);

end