try
    f = 1000; % frequency in Hz
    d = 1; % duration in sec
    sr = 44100; % sample rate in Hz
    beep = MakeBeep(f, d, sr); %synthesis of the beep
    InitializePsychSound;
    pahandle = PsychPortAudio('Open', [], [], [], sr, 1);
    PsychPortAudio('FillBuffer', pahandle, beep);
    PsychPortAudio('Start', pahandle);
    PsychPortAudio('Stop', pahandle, d);
catch
    Screen('CloseAll')
    rethrow(lasterror)
end