function [Tfeat, Bfeat] = fExtract_TEMP(record_name)
%CHALLENGE Summary of this function goes here
%   Detailed explanation goes here
Tfeat=[]; Bfeat=[];

t = load_tape_audio_FULL(record_name);

if isvector(t)
    t = t(1);
end

% normalize
[~,~,~,pcg]=Find_outliers(t.pcg,2);

if(~isnan(pcg))
	t.pcg=pcg; 
else
	display('found a wierd PCG');
end

deubachis = 'db8';
level = 8;
levelnum = 2^level;
Wavelet_Nodes = ([1:levelnum] );
Wavelet_Nodes = ([3 4 6 21 24 27 29 30 31 32 81 256] );

T = wpdec(pcg ,level,deubachis);
    E = wenergy(T);
feats = (E(: , Wavelet_Nodes));


% init calculator handler with default config
c = get_default_config();
c_handler = CalculationHandler(c);

% segmentation of tape
t = c_handler.segment_tape(t, 'springer', 0);

% extracting features
c_handler.config.N_mean_win = floor(t.beat_len*5);

tic
% warning off;
 t_features = c_handler.extract_features(t, 0);
 feat2 = t_features.get_tot_tape_feature_matrix(c.N_important_ssa_decomp);

% warning on;
 toc
%  Tfeat = [feat2' feats];

    % Extract beat features
    Bfeat_no=70;
    Bfeat=zeros(length(t.seg_ind) -2,Bfeat_no);
    for i = 1 : length(t.seg_ind) -2
        bfeat1=sum(t.pcg(t.seg_ind(i):t.s1_end(i)).^2)/numel(t.seg_ind(i):t.s1_end(i));
        bfeat2=sum(t.pcg(t.seg_ind(i):t.s2_beg(i)).^2)/numel(t.seg_ind(i):t.s2_beg(i));
        bfeat3=sum(t.pcg(t.seg_ind(i):t.s2_end(i)).^2)/numel(t.seg_ind(i):t.s2_end(i));
        bfeat4=sum(t.pcg(t.seg_ind(i):t.seg_ind(i+1)).^2)/numel(t.seg_ind(i):t.seg_ind(i+1));           
        bfeat5=sum(t.pcg(t.s1_end(i):t.s2_beg(i)).^2)/numel(t.s1_end(i):t.s2_beg(i));       
        bfeat6=sum(t.pcg(t.s1_end(i):t.s2_end(i)).^2)/numel(t.s1_end(i):t.s2_end(i));       
        bfeat7=sum(t.pcg(t.s1_end(i):t.seg_ind(i+1)).^2)/numel(t.s1_end(i):t.seg_ind(i+1));
        bfeat8=sum(t.pcg(t.s2_beg(i):t.s2_end(i)).^2)/numel(t.s2_beg(i):t.s2_end(i));        
        bfeat9=sum(t.pcg(t.s2_beg(i):t.seg_ind(i+1)).^2)/numel(t.s2_beg(i):t.seg_ind(i+1));
        bfeat10=sum(t.pcg(t.s2_end(i):t.seg_ind(i+1)).^2)/numel(t.s2_end(i):t.seg_ind(i+1));
        %max min std mean median 
                bfeatm1=median(t.pcg(t.seg_ind(i):t.s1_end(i)));
                bfeatm2=median(t.pcg(t.seg_ind(i):t.s2_beg(i)));
                bfeatm3=median(t.pcg(t.seg_ind(i):t.s2_end(i)));
                bfeatm4=median(t.pcg(t.seg_ind(i):t.seg_ind(i+1)));           
                bfeatm5=median(t.pcg(t.s1_end(i):t.s2_beg(i)));       
                bfeatm6=median(t.pcg(t.s1_end(i):t.s2_end(i)));       
                bfeatm7=median(t.pcg(t.s1_end(i):t.seg_ind(i+1)));
                bfeatm8=median(t.pcg(t.s2_beg(i):t.s2_end(i)));
                bfeatm9=median(t.pcg(t.s2_beg(i):t.seg_ind(i+1)));
                bfeatm10=median(t.pcg(t.s2_end(i):t.seg_ind(i+1)));
                
                bfeatm11=mean(t.pcg(t.seg_ind(i):t.s1_end(i)));
                bfeatm12=mean(t.pcg(t.seg_ind(i):t.s2_beg(i)));
                bfeatm13=mean(t.pcg(t.seg_ind(i):t.s2_end(i)));
                bfeatm14=mean(t.pcg(t.seg_ind(i):t.seg_ind(i+1)));           
                bfeatm15=mean(t.pcg(t.s1_end(i):t.s2_beg(i)));       
                bfeatm16=mean(t.pcg(t.s1_end(i):t.s2_end(i)));       
                bfeatm17=mean(t.pcg(t.s1_end(i):t.seg_ind(i+1)));
                bfeatm18=mean(t.pcg(t.s2_beg(i):t.s2_end(i)));
                bfeatm19=mean(t.pcg(t.s2_beg(i):t.seg_ind(i+1)));
                bfeatm20=mean(t.pcg(t.s2_end(i):t.seg_ind(i+1)));
                
                bfeatm21=min(t.pcg(t.seg_ind(i):t.s1_end(i)));
                bfeatm22=min(t.pcg(t.seg_ind(i):t.s2_beg(i)));
                bfeatm23=min(t.pcg(t.seg_ind(i):t.s2_end(i)));
                bfeatm24=min(t.pcg(t.seg_ind(i):t.seg_ind(i+1)));           
                bfeatm25=min(t.pcg(t.s1_end(i):t.s2_beg(i)));       
                bfeatm26=min(t.pcg(t.s1_end(i):t.s2_end(i)));    
                bfeatm27=min(t.pcg(t.s1_end(i):t.seg_ind(i+1)));
                bfeatm28=min(t.pcg(t.s2_beg(i):t.s2_end(i)));
                bfeatm29=min(t.pcg(t.s2_beg(i):t.seg_ind(i+1)));
                bfeatm30=min(t.pcg(t.s2_end(i):t.seg_ind(i+1)));
                
                bfeatm31=max(t.pcg(t.seg_ind(i):t.s1_end(i)));
                bfeatm32=max(t.pcg(t.seg_ind(i):t.s2_beg(i)));
                bfeatm33=max(t.pcg(t.seg_ind(i):t.s2_end(i)));
                bfeatm34=max(t.pcg(t.seg_ind(i):t.seg_ind(i+1)));           
                bfeatm35=max(t.pcg(t.s1_end(i):t.s2_beg(i)));       
                bfeatm36=max(t.pcg(t.s1_end(i):t.s2_end(i)));       
                bfeatm37=max(t.pcg(t.s1_end(i):t.seg_ind(i+1)));
                bfeatm38=max(t.pcg(t.s2_beg(i):t.s2_end(i)));
                bfeatm39=max(t.pcg(t.s2_beg(i):t.seg_ind(i+1)));
                bfeatm40=max(t.pcg(t.s2_end(i):t.seg_ind(i+1)));
                
                bfeatm41=std(t.pcg(t.seg_ind(i):t.s1_end(i)));
                bfeatm42=std(t.pcg(t.seg_ind(i):t.s2_beg(i)));
                bfeatm43=std(t.pcg(t.seg_ind(i):t.s2_end(i)));
                bfeatm44=std(t.pcg(t.seg_ind(i):t.seg_ind(i+1)));           
                bfeatm45=std(t.pcg(t.s1_end(i):t.s2_beg(i)));       
                bfeatm46=std(t.pcg(t.s1_end(i):t.s2_end(i)));       
                bfeatm47=std(t.pcg(t.s1_end(i):t.seg_ind(i+1)));
                bfeatm48=std(t.pcg(t.s2_beg(i):t.s2_end(i)));
                bfeatm49=std(t.pcg(t.s2_beg(i):t.seg_ind(i+1)));
                bfeatm50=std(t.pcg(t.s2_end(i):t.seg_ind(i+1)));
                
        bfeat11=numel(t.seg_ind(i):t.s1_end(i));
        bfeat12=numel(t.seg_ind(i):t.s2_beg(i));
        bfeat13=numel(t.seg_ind(i):t.s2_end(i));
        bfeat14=numel(t.seg_ind(i):t.seg_ind(i+1)); 
        bfeat15=numel(t.s1_end(i):t.s2_beg(i)); 
        bfeat16=numel(t.s1_end(i):t.s2_end(i));
        bfeat17=numel(t.s1_end(i):t.seg_ind(i+1));
        bfeat18=numel(t.s2_beg(i):t.s2_end(i));   
        bfeat19=numel(t.s2_beg(i):t.seg_ind(i+1)); 
        bfeat20=numel(t.s2_end(i):t.seg_ind(i+1));
        Bfeat (i , :) = [bfeat1 bfeat2 bfeat3 bfeat4 bfeat5 bfeat6 bfeat7 bfeat8 bfeat9 bfeat10 ...
                         bfeatm1 bfeatm2 bfeatm3 bfeatm4 bfeatm5 bfeatm6 bfeatm7 bfeatm8 bfeatm9 bfeatm10 ...
                         bfeatm11 bfeatm12 bfeatm13 bfeatm14 bfeatm15 bfeatm16 bfeatm17 bfeatm18 bfeatm19 bfeatm20 ...
                         bfeatm21 bfeatm22 bfeatm23 bfeatm24 bfeatm25 bfeatm26 bfeatm27 bfeatm28 bfeatm29 bfeatm30 ...
                         bfeatm31 bfeatm32 bfeatm33 bfeatm34 bfeatm35 bfeatm36 bfeatm37 bfeatm38 bfeatm39 bfeatm40 ...
                         bfeatm41 bfeatm42 bfeatm43 bfeatm44 bfeatm45 bfeatm46 bfeatm47 bfeatm48 bfeatm49 bfeatm50 ...
                         bfeat11 bfeat12 bfeat13 bfeat14 bfeat15 bfeat16 bfeat17 bfeat18 bfeat19 bfeat20]; 
        
   
    end
%     Bfeat=[Bfeat; t_features.fm_b(1:end-1)'];
Bfeat=vertcat(Bfeat',t_features.fm_b(:,1:end-1))';
    
    Tfeat_no=10;
    faux=zeros(1,Tfeat_no*Bfeat_no);
    for i=1:Bfeat_no
        faux(Tfeat_no*(i-1)+1)=mean(Bfeat(:,i));
        faux(Tfeat_no*(i-1)+2)=std(Bfeat(:,i));
        faux(Tfeat_no*(i-1)+3)=min(Bfeat(:,i));
        faux(Tfeat_no*(i-1)+4)=max(Bfeat(:,i));
        faux(Tfeat_no*(i-1)+5)=median(Bfeat(:,i));
        faux(Tfeat_no*(i-1)+6)=mean(diff(Bfeat(:,i)));
        faux(Tfeat_no*(i-1)+7)=std(diff(Bfeat(:,i)));
        faux(Tfeat_no*(i-1)+8)=min(diff(Bfeat(:,i)));
        faux(Tfeat_no*(i-1)+9)=max(diff(Bfeat(:,i)));
        faux(Tfeat_no*i)=median(diff(Bfeat(:,i)));
    end
Tfeat = [feat2' feats faux];
% Tfeat = [faux];
toc

end

