# Generating a click stimuli

**URL:** <https://psychtoolbox.discourse.group/t/generating-a-click-stimuli/4136>\
**Category:** Programming Help\
**Tags:** audio\
**Created:** [November 22, 2021, 9:39pm UTC](https://psychtoolbox.discourse.group/t/generating-a-click-stimuli/4136 "2021-11-22T21:39:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohadeseh](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/mohadeseh/32/280_2.png) [@Mohadeseh](https://psychtoolbox.discourse.group/u/Mohadeseh)\
**Post date:** [November 22, 2021, 9:39pm UTC](https://psychtoolbox.discourse.group/t/generating-a-click-stimuli/4136/1 "2021-11-22T21:39:37Z")

</div>

Hello everybody

I want to generate a sound (a 5 dB sound) with a specefic charictristics ( frequency=250, I=3.1\*10^(-12), duration=1) when I run this program no sound generate, but this amplitude can generate 5 dB sound and 5 dB is one of the hearing thresholds of people therefore people can hear it. ( if I increase its amplitude (For example I=1) after that I can hear the sound (it is a click),but I want to generate a click stimuli with this amplitude that it can generate a 5 db sound). In your opinion it is related to the click stimuli and we can not hear a click stimuli like a pure tone??

anyone can help me?? I totally stuck it.

Here is the formula of the dB:

I0=10^(-12) %% reference sound intensity

dB=10\*log10(I/I0);

I=3.1\*10^(-12);

dB=10_log10((3.1_10^(-12))/10^(-12) )= 4.9136 dB (=~ 5 dB)

```auto
clc
clear
close all;
f=250;
P=1; 
I=3.1*10^(-12); %% If I increase its amplitude (for example I=1), I can hear but I do not want
%I=1; %% I=1 can generate a audible sound
n=100;
SamplingRate_Hz=44100;
t = 0 :(1/SamplingRate_Hz) : (P/f);
y=I*sin(2*pi*f*t);     
xt_ramped = toneburst(SamplingRate_Hz,y);
sound(xt_ramped,SamplingRate_Hz);
figure; plot(t,xt_ramped)
%% Here is the function that is use in this program.
function xt_ramped = toneburst(SamplingRate_Hz,y)
xt =y;
fs=SamplingRate_Hz;
ramp_dur=0.0025; %ramp duration in seconds
%% Check out this ramp
%setup ramp
rampSamps = floor(fs*ramp_dur);
window=hanning(2*rampSamps)'; %hanning window is cosine^2 this will change depending on the kind of ramp you want
w1=window(1:ceil((length(window))/2)); %use the first half of hanning function for onramp
w2=window(ceil((length(window))/2)+1:end); %use second half of hanning function of off ramp
w_on_xt = [w1 ones(1,length(xt)-length(w1))];
w_off_xt = [ones(1,length(xt)-length(w2)) w2];
xt_ramped = xt.*w_on_xt.*w_off_xt;
end

```

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [December 10, 2021, 5:06pm UTC](https://psychtoolbox.discourse.group/t/generating-a-click-stimuli/4136/2 "2021-12-10T17:06:33Z")

</div>

As nobody answered you, here the reminder that paid support exists:  
`help PsychPaidSupportAndServices`. And this year it is cheaper to get than what it will likely be next year.  
-mario
