clear all, close all, clc

TotSeconds = 4; % Quanti secondi voglio registrare
SampleBits = 8;
NChannels = 1; % 1 for mono, 2 for stereo
Fs = 8000;
DBName = 'Dario';
flagSave = 1;
flagRecord = 0;
flagReproduce = 1;
PassMale = 1; % else pass females
FilterOrder = 200;

MaleFrequencyBand = [85 400];
FemaleFrequencyBand = [165 1000];

if(flagRecord)

    RecordObj = audiorecorder(Fs, SampleBits, NChannels);

    disp('Schiaccia quando vuoi partire a registrare')
    pause
    recordblocking(RecordObj, 3);
    disp('Registrato!!!')
    disp('Schiaccia per risentire')
    pause
    disp('Riproduzione in corso dell''originale')
    RecordObj.play

    if(flagSave)
        
        save(DBName, 'RecordObj')
        
    end

else
    
    load(DBName)

end
if(flagReproduce)
    RecordObj.play
end

x = RecordObj.getaudiodata;

if(PassMale)
    
    NormBandPass = MaleFrequencyBand/Fs;
    NormBandStop = FemaleFrequencyBand/Fs;    
    
else
    
    NormBandPass = FemaleFrequencyBand/Fs;
    NormBandStop = MaleFrequencyBand/Fs;    
    
end

% [Num, Den] = butter(FilterOrder, 2*NormBandPass);
Num = fir1(FilterOrder, NormBandPass);
Den = 1;

FilteredX = filter(Num, Den, x);
% FilteredX = FilteredX(1:end);

stem(FilteredX)
pause
FilteredXAudio = audioplayer(FilteredX, Fs);
FilteredXAudio.play;