fs=44100;
stim_dur=.025;
noise_dur=.200;
ISI_dur=.020;
ramp_dur=.010;
t=0:1/fs:stim_dur-1/fs;
f=1000;
nsamples = floor(noise_dur*fs);
noise_all_Hz = randn(nsamples,1);
noise = bandpass(noise_all_Hz,[950 1050],fs);
noise=noise';
xt=sin(2*pi*f*t);
rampSamps = floor(fs*ramp_dur);
window=hanning(2*rampSamps)';
w1=window(1:ceil((length(window))/2));
w2=window(ceil((length(window))/2)+1:end);
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];
noise_ramped = noise.*w_on_noise.*w_off_noise;
xt_ramped = xt.*w_on_xt.*w_off_xt;
rms_xt_ramped=rms(xt_ramped);
amp_10dB=10^(-10/20)*rms_xt_ramped;
noise_ramped_norm=noise_ramped./rms(noise_ramped);
noise_ramped_10dB=noise_ramped_norm.*amp_10dB;
rms_noise_ramped=rms(noise_ramped_10dB);
20*log10(rms_xt_ramped/rms_noise_ramped)
ISI=zeros(ISI_dur*fs,1);
out=[noise_ramped_10dB';ISI;xt_ramped'];
plot(out)
sound(out,fs)
Best Answer