
function data=readdata(path,name,sel,filtdata,prefs)
%syntax: data=readdata(filename, which data)

filename=strcat(prefs.proj_dir,'seg_data_',strrep(name,'.wav',''))
load(filename);
n_s=size(seg_data.reg_arr,1);

if isempty(sel)
    data=zeros(13,n_s);
    return
end

data=zeros(13,n_s);
for n=1:n_s
    [wave.wf,wave.fs]=wavread(strcat(path,name),[seg_data.reg_arr(n,1) seg_data.reg_arr(n,2)]);
    wave.spec=abs(specgram(wave.wf));
    threshold=prefs.threshold;
    cd(prefs.func_dir)
    wave.spec=butt_filt(wave,prefs.cutoff,12);
    pthresh_med=(2*median(wave.spec(:)));
    [wave.spec, threshold]=filt_spec(wave,filtdata);
    
    if pthresh_med>threshold
        threshold=pthresh_med;
        wave.spec=wave.spec.*(wave.spec>=pthresh_med);
    else
        wave.spec=wave.spec.*(wave.spec>=threshold);
    end
    data(:,n) = featurext_wk(wave,sel,seg_data.timeint,prefs)';
    
end    