Generating pure tone and noise

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

 Accepted Answer

Shae Morgan
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)

11 Comments

Thanks, but there is an error:
Undefined function 'bandpass' for input arguments of type 'double'.
Error in Untitled (line 11)
noise = bandpass(noise_all_Hz,[950 1050],fs);
you likely don't have th signal procesing toolbox installed you can either install it or use the following workaround:
%create noise
nsamples = floor(noise_dur*fs);
noise_all_Hz=randn(nsamples,1);
% Take fft of the noise
noise_fft = fft(noise_all_Hz);
freqs= [0:size(noise_fft,1)-1]/size(noise_fft,1)*fs;
% Get index for your Frequencies
[~,idx_950] = min(abs(freqs-950));
[~,idx_1050] = min(abs(freqs-1050));
% "zero out" all other bins
noise_fft(1:idx_950) = randn(idx_950,1)*1e-3;
noise_fft(idx_1050:end) = randn(size(noise_fft,1)-idx_1050+1,1)*1e-3;
% Get back time signal
noise = ifft(noise_fft,'symmetric');
noise=noise';
The linked response above also details this procedure as well. It "creates" a rectangular bandpass filter if you want any sort of slope, you'll have to adust the amplitudes of the bins in the frequency domain accordingly.
Put this code in to the above answer in place of the section that makes the noise and it should work without the SP toolbox.
answer edited should work now.
thanks! It worked
I am sorry but I have another question
for 10dB snr you used: 10^(-10/20)
I was wondering what are -10 and 20 because I want to use different SNRs (like 20, 30,40 dB)
Thanks & Regards
And what if I want to nise and tone be simultaneous, I mean the tone be in center of noise
I deleted ISI but tone and noise are comming immediately after each other not simultaneous
I am sorry for my multiple questions!
If these are separate, new questions, please make separate, new posts so that they can be answered and more easily viewed by others in the community. Feel free to link your new questions here after you make them and I'll be happy to answer!
E.g.,
"I have an equation ____________ to find an amplitude that is -10 dB lower than a reference, what do I change in the formula to make it 20, 30, or 40 dB?"
"I have a noise stimulus and a tone stimulus. How do I center the tone in the noise?"
Ok, I did it, thanks for your time
simultaneous noise and pure tone
Equation for Amplitude difference between two tones
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

Sign in to comment.

More Answers (0)

Categories

Find more on Signal Generation, Manipulation, and Analysis in Help Center and File Exchange

Asked:

on 5 Aug 2020

Commented:

on 31 Aug 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!