bleeck@3: % This external file is included as part of the 'aim-mat' distribution package bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org tomwalters@0: function [target_signal,flanking_signal,only_regular_clicktrain,only_irregular_clicktrain]= ... tomwalters@0: gen_jittered_clicktrains(orgsig,jitter,delay,target_fre,flanker_fre,Gain,FlankerMode,FlankerDelay,grafix) tomwalters@0: % tomwalters@0: % this funtion produces the stimuli needed in Krumbholz et al 2003 and tomwalters@0: % many other regular and irregular filted click trains tomwalters@0: % the clicktrain can be pure when TargetFrequency is =0 otherwise the tomwalters@0: % click train filted with a band pass filter around the given frequency tomwalters@0: % tomwalters@0: % input: tomwalters@0: % orgsig: original signal. Determines length and samperate. SR must be 25000! tomwalters@0: % jitter: tomwalters@0: % the amount of jitter in % (0=regular, 100= maximal jitter) tomwalters@0: % delay: tomwalters@0: % the repetition rate of the signal in ms tomwalters@0: % target_fre: tomwalters@0: % one of the following: tomwalters@0: % 0 0.4 0.5657 0.8 1.1314 1.6 2.2627 3.2 4.5255 6.4 tomwalters@0: % if not precice, the nearest one will be taken tomwalters@0: % if 0, then no target will be generated tomwalters@0: % flanker_fre: tomwalters@0: % one of the following: tomwalters@0: % 0 0.4 0.5657 0.8 1.1314 1.6 2.2627 3.2 4.5255 6.4 tomwalters@0: % if not precice, the nearest one will be taken tomwalters@0: % if 0, then no flanker will be generated tomwalters@0: tomwalters@0: % flanker_mode: tomwalters@0: % one of the following: tomwalters@0: % m: Flanker band synchronous and irregular (highest threshold) tomwalters@0: % t: Flanker band synchronous and regular (medium threshold) tomwalters@0: % td5: Flanker band synchronous and regular shifted in timepoints (lowest threshold) tomwalters@0: % sb1: Masker regular, flanker band irregular (Ranjnas Experiment) tomwalters@0: % sb2: Masker regular, flanker band regular, but time shifted (Ranjnas other stimulus) tomwalters@0: % sb3: Masker irregular, flanker band regular, tomwalters@0: % sb4: NO masker, flanker band regular (returned in target_signal) tomwalters@0: tomwalters@0: % flanker delay: tomwalters@0: % the delay of the synchronous clicks in ms tomwalters@0: % Gain: tomwalters@0: % the gain of the signal against the masker positiv direction: more signal tomwalters@0: % grafix says, if we want to see a plot of the signal or not tomwalters@0: tomwalters@0: % possible usage: tomwalters@0: % produce the stimulus as in the paper: tomwalters@0: % gen_jittered_clicktrains(signal(1,25000),0,10,1.6,3.2,10,'td5',5,1); tomwalters@0: % play(gen_jittered_clicktrains(signal(1,25000),0,10,3.2,0.8,3,'td5',5)) tomwalters@0: % tomwalters@0: % to generate regular clicktrains use tomwalters@0: % [a,b,c,d]=gen_jittered_clicktrains(signal(1,25000),0,10); play(c); tomwalters@0: % tomwalters@0: % to generate 20 % jitter use: tomwalters@0: % [a,b,c,d]=gen_jittered_clicktrains(signal(1,25000),0.2,10); play(d); tomwalters@0: % tomwalters@0: % to filter at 3.2 Khz generate 20 % jitter use: tomwalters@0: % [a,b,c,d]=gen_jittered_clicktrains(signal(1,25000),0.2,10,3.2); play(d); tomwalters@0: % tomwalters@0: % to generate one of Ranjnas stimuli (regular masker at first frequency and irregular target tomwalters@0: % in a different frequency band use) here: regular 40 dB louder then irregular tomwalters@0: % play(gen_jittered_clicktrains(signal(1,25000),1,10,1.6,3.2,40,'sb1',NaN,1)/20) tomwalters@0: % the shift parameter is here ignored tomwalters@0: % tomwalters@0: % tomwalters@0: % to generate one of Ranjnas stimuli (regular masker at first frequency and shifted target tomwalters@0: % in a different frequency band use) here: regular 40 dB louder the shifted tomwalters@0: % play(gen_jittered_clicktrains(signal(1,25000),NaN,10,1.6,3.2,40,'sb2',5,1)) tomwalters@0: % in this case the jitter is ignored tomwalters@0: tomwalters@0: % return signals: tomwalters@0: % target_signal is the target band with regular clicks plus irregular clicks with the ratio of "gain" tomwalters@0: % flanking_signal is the flanking band which can be either regular or irregular tomwalters@0: % only_regular_clicktrain is the regular clicks alone tomwalters@0: % only_irregular_clicktrain is the irrregular clicks alone tomwalters@0: % tomwalters@0: % % no random please! tomwalters@0: % rand('state',0); tomwalters@0: tomwalters@0: % input variables: tomwalters@0: % 1 2 3 4 5 6 7 8 tomwalters@0: %(orgsig,jitter,delay,flanker_fre,Gain,FlankerMode,FlankerDelay,grafix); tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: if nargin <9 grafix=0;end tomwalters@0: if nargin <8 FlankerDelay=5; end tomwalters@0: if nargin <7 FlankerMode='td5';end tomwalters@0: if nargin <6 Gain=0;end tomwalters@0: if nargin <5 flanker_fre=3.2;end tomwalters@0: if nargin <4 target_fre=0;end tomwalters@0: if nargin <3 delay=10;end tomwalters@0: if nargin <2 tomwalters@0: jitter=1; % 100 % jitter tomwalters@0: end tomwalters@0: tomwalters@0: if jitter >1 tomwalters@0: disp('jitter must be smaller then 1 (100%)') tomwalters@0: jitter=1; tomwalters@0: end tomwalters@0: tomwalters@0: % possible Target and Flanker frequencies: tomwalters@0: f(1)=0.4; tomwalters@0: f(2)=0.5657; tomwalters@0: f(3)=0.8; tomwalters@0: f(4)=1.1314; tomwalters@0: f(5)=1.6; tomwalters@0: f(6)=2.2627; tomwalters@0: f(7)=3.2; tomwalters@0: f(8)=4.5255; tomwalters@0: f(9)=6.4; tomwalters@0: tomwalters@0: % TargetFrq = 1.6; % fixed tomwalters@0: % change into the directory with the filter coeffiencs in tomwalters@0: orgdira=which('signal'); tomwalters@0: orgdir=fileparts(orgdira); tomwalters@0: od=cd(fullfile(orgdir,'FIR filter coefficients')); tomwalters@0: tomwalters@0: % load filter for Target tomwalters@0: if target_fre==0 tomwalters@0: TargetFrq=0; tomwalters@0: else tomwalters@0: % load the filter file for the appropriate frequency for the target tomwalters@0: p=polyfit(1:9,log(f),1); tomwalters@0: targ=round(solve(p,log(target_fre))); tomwalters@0: TargetFrq = f(targ); tomwalters@0: targetFIRFile = sprintf('bp%gw%g',TargetFrq,0.2); tomwalters@0: targetFIRFile(findstr(targetFIRFile,'.')) = '_'; tomwalters@0: FId = fopen([targetFIRFile '.txt'],'rt'); tomwalters@0: fgetl(FId); tomwalters@0: targetFIR = fscanf(FId,'%g',151)'; tomwalters@0: fclose(FId); tomwalters@0: end tomwalters@0: tomwalters@0: % load filter for Flanker tomwalters@0: if flanker_fre==0 tomwalters@0: FlankerFrq=0; tomwalters@0: else tomwalters@0: % load the filter file for the appropriate frequency for the flanker tomwalters@0: p=polyfit(1:9,log(f),1); tomwalters@0: flank=round(solve(p,log(flanker_fre))); tomwalters@0: FlankerFrq = f(flank); tomwalters@0: flankerFIRFile = sprintf('bp%gw%g',FlankerFrq,0.2); tomwalters@0: flankerFIRFile(findstr(flankerFIRFile,'.')) = '_'; tomwalters@0: FId = fopen([flankerFIRFile '.txt'],'rt'); tomwalters@0: fgetl(FId); tomwalters@0: flankerFIR = fscanf(FId,'%g',151)'; tomwalters@0: fclose(FId); tomwalters@0: end tomwalters@0: cd(od); % go back to the old directory tomwalters@0: tomwalters@0: SR = 1000/getsr(orgsig);% all in ms tomwalters@0: sig_length =getlength(orgsig)*1000; tomwalters@0: % the filter coefficients only work when the sr is 25000! tomwalters@0: if getsr(orgsig)~=25000 && target_fre>0 tomwalters@0: disp('gen_jittered_clicktrains::warning: filtering only works for a sample rate of 25000') tomwalters@0: end tomwalters@0: tomwalters@0: rise_time = 25; tomwalters@0: timepoints = 0:SR:sig_length; tomwalters@0: TPts = max(size(timepoints)); tomwalters@0: DigAmp = 1; tomwalters@0: SDelay = round(delay/SR); tomwalters@0: tomwalters@0: regular_clickstream = zeros(1,TPts); tomwalters@0: regular_clickstream(1:SDelay:TPts) = DigAmp; tomwalters@0: tomwalters@0: % RANDOMISE THE TARGET tomwalters@0: irregular_clickstream = zeros(1,TPts); tomwalters@0: % randomisation in the range of the jitter boundary tomwalters@0: jitter_time=SDelay*jitter; tomwalters@0: % Idx = ceil(rand*SDelay*2); tomwalters@0: idx = [];count=1; tomwalters@0: while isempty(idx)|| max(idx)0 && strcmp(FlankerMode,'td5') tomwalters@0: flanker = [zeros(1,round(FlankerDelay/SR)) flanker(1:TPts-round(FlankerDelay/SR))]; tomwalters@0: end tomwalters@0: else tomwalters@0: flanker = zeros(1,TPts); tomwalters@0: end tomwalters@0: flanker = envelope_signal(flanker,rise_time,SR); tomwalters@0: tomwalters@0: tomwalters@0: % filter the resulting streams in the right frequency bands tomwalters@0: if FlankerFrq~=0 tomwalters@0: f_flanker=filter(flankerFIR,1,flanker); tomwalters@0: else tomwalters@0: f_flanker=flanker; tomwalters@0: end tomwalters@0: if target_fre>0 % only filter, when neccessary tomwalters@0: f_targetReg=filter(targetFIR,1,targetReg); tomwalters@0: f_targetIrr=filter(targetFIR,1,targetIrr); tomwalters@0: else tomwalters@0: f_targetReg=targetReg; tomwalters@0: f_targetIrr=targetIrr; tomwalters@0: end tomwalters@0: tomwalters@0: signal_flank=signal(f_flanker); tomwalters@0: signal_flank=setsr(signal_flank,1000/SR); tomwalters@0: target_signal=signal(f_targetReg); tomwalters@0: flanking_signal=signal(f_targetIrr); tomwalters@0: target_signal=setsr(target_signal,1000/SR); tomwalters@0: flanking_signal=setsr(flanking_signal,1000/SR); tomwalters@0: if strcmp(FlankerMode,'sb1') || strcmp(FlankerMode,'sb2') tomwalters@0: % in this case, the target is the signal plus the flanker: tomwalters@0: target_signal=target_signal+signal_flank; tomwalters@0: else tomwalters@0: % Signal zu Flanker addieren (stimmt von der Amplitude her wohl nicht, aber tomwalters@0: % für den Moment wirds tun) tomwalters@0: target_signal=target_signal+signal_flank; tomwalters@0: flanking_signal=flanking_signal+signal_flank; tomwalters@0: end tomwalters@0: tomwalters@0: %generate the pure random and regular click trains as well tomwalters@0: only_regular_clickstream=envelope_signal(min(max(DigAmp*10^(Gain/20),DigAmp),regular_clickstream*10^(Gain/20)),rise_time,SR); tomwalters@0: if target_fre>0 % only filter, when neccessary tomwalters@0: only_regular_clickstream=filter(targetFIR,1,only_regular_clickstream); tomwalters@0: end tomwalters@0: only_regular_clicktrain=signal(only_regular_clickstream); tomwalters@0: only_regular_clicktrain=setsr(only_regular_clicktrain,1000/SR); tomwalters@0: only_irregular_clickstream=envelope_signal(min(max(DigAmp*10^(Gain/20),DigAmp),irregular_clickstream*10^(Gain/20)),rise_time,SR); tomwalters@0: if target_fre>0 % only filter, when neccessary tomwalters@0: only_irregular_clickstream=filter(targetFIR,1,only_irregular_clickstream); tomwalters@0: end tomwalters@0: only_irregular_clicktrain=signal(only_irregular_clickstream); tomwalters@0: only_irregular_clicktrain=setsr(only_irregular_clicktrain,1000/SR); tomwalters@0: tomwalters@0: % plotte ein paar hübsche Bilder dazu tomwalters@0: % figure(4) tomwalters@0: % subplot(2,2,1) tomwalters@0: % plot(target_signal); tomwalters@0: % subplot(2,2,2) tomwalters@0: % plot(powerspectrum(target_signal)); tomwalters@0: % subplot(2,2,3) tomwalters@0: % plot(flanking_signal); tomwalters@0: % subplot(2,2,4) tomwalters@0: % plot(powerspectrum(flanking_signal)); tomwalters@0: % savewave(target_signal,'regular'); tomwalters@0: % savewave(flanking_signal,'irregular'); tomwalters@0: tomwalters@0: % savewave(target_signal,'stimulus'); tomwalters@0: tomwalters@0: if grafix tomwalters@0: figure(4) tomwalters@0: subplot(2,1,1) tomwalters@0: plot(target_signal); tomwalters@0: subplot(2,1,2) tomwalters@0: plot(powerspectrum(target_signal)); tomwalters@0: end tomwalters@0: tomwalters@0: % ********** envelope_signal ********** tomwalters@0: function out = envelope_signal(in,rise_time,SR) tomwalters@0: APts = length(in); tomwalters@0: GPts = round(rise_time/SR); tomwalters@0: if APts<2*GPts tomwalters@0: error('==> Signal must be loger than gate!') tomwalters@0: end tomwalters@0: env = cos(pi*(0:GPts-1)/(2*(GPts-1))).^2; tomwalters@0: out = [1-env ones(1,APts-2*GPts) env].*in;