# Generating pure tone and noise

99 views (last 30 days)
Parisa on 5 Aug 2020
Commented: Parisa on 31 Aug 2020
Hi, I want to generate 200 ms 950- 1050 Hz noise with rise/ fall time of 10 ms and a 1000 Hz , 25 ms pure tone with 10 ms rise/ fall time with 10 dB SNR and ISI of 20 ms
and fs= 44100
can any one help me please

Shae Morgan on 7 Aug 2020
Edited: Shae Morgan on 7 Aug 2020
See here for an excellent solution to generating your noise from one of your previous questions:
You can use the code from the previous answer I gave you to add a rise-fall time for 10 ms and the other stimulus.
the 10 dB SNR should also be the same. Example below.
%set-up parameters
fs=44100; %CD quality - also conveniently divisible by 30 and 25
stim_dur=.025; %duration of puretone in seconds
noise_dur=.200; %duration of noise in seconds
ISI_dur=.020; %ISI duration in seconds
ramp_dur=.010; %ramp duration in seconds
t=0:1/fs:stim_dur-1/fs;
f=1000;
%create noise
nsamples = floor(noise_dur*fs);
noise_all_Hz = randn(nsamples,1);
noise = bandpass(noise_all_Hz,[950 1050],fs);
noise=noise';
%create 1000 Hz tone
xt=sin(2*pi*f*t);
%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];
w_on_noise = [w1 ones(1,length(noise)-length(w1))];
w_off_noise = [ones(1,length(noise)-length(w2)) w2];
%ramp stimuli
noise_ramped = noise.*w_on_noise.*w_off_noise;
xt_ramped = xt.*w_on_xt.*w_off_xt;
% scale
rms_xt_ramped=rms(xt_ramped); %check the average intensity of the ramped 500 Hz signal
amp_10dB=10^(-10/20)*rms_xt_ramped; %find the new amplitude that is 10 dB lower
%normalize the xt2_ramped stimulus and then scale to -10 dB
noise_ramped_norm=noise_ramped./rms(noise_ramped);
noise_ramped_10dB=noise_ramped_norm.*amp_10dB;
%check
rms_noise_ramped=rms(noise_ramped_10dB);
20*log10(rms_xt_ramped/rms_noise_ramped)
%generate ISI
ISI=zeros(ISI_dur*fs,1);
%final stimulus
out=[noise_ramped_10dB';ISI;xt_ramped'];
plot(out)
sound(out,fs)

Parisa on 10 Aug 2020
Ok, I did it, thanks for your time
Parisa on 10 Aug 2020
simultaneous noise and pure tone
Equation for Amplitude difference between two tones
Parisa on 31 Aug 2020
Hi dear Shae
I'm sorry but I asked another question and can you please see if you can help me.
I thought we can't determine intensity in matlab but some one said we we can
Intensity of a noise