Mercurial > hg > aimmat
view aim-mat/tools/@signal/ci_simulate.asv @ 4:537f939baef0 tip
various bug fixes and changed copyright message
author | Stefan Bleeck <bleeck@gmail.com> |
---|---|
date | Tue, 16 Aug 2011 14:37:17 +0100 |
parents | 74dedb26614d |
children |
line wrap: on
line source
% method of class @signal % function sig=ci_simulate(signal) % % INPUT VALUES: % sig: @signal % % RETURN VALUE: % sigresult: @signal ` % % (c) 2003, University of Cambridge, Medical Research Council % Stefan Bleeck (stefan@bleeck.de) % http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual % $Date: 2003/01/20 18:33:51 $ % $Revision: 1.4 $ function sig=ci_simulate(sig) % stolen from AMO.m audio_sample_rate=16000; p.channel_stim_rate=900; p.audio_sample_rate=audio_sample_rate; p.analysis_rate=p.channel_stim_rate; p.num_selected = 10; p.num_bands = 22; p.electrodes=22:-1:1; p=Append_process(p,'FFT_filterbank_proc'); p=Append_process(p,'Power_sum_envelope_proc'); p=Append_process(p,'Reject_smallest_proc'); FTM=Process(p,sig.values); % Parameters for Resynthesis % -------------------------- pre.resynthesis_rate = audio_sample_rate; pre.num_bands = p.num_bands; pre.analysis_rate = p.channel_stim_rate; pre.electrodes=p.electrodes; insertion = 22; % insertion depth in mm cochlength=33 % length of cochlea elecspacing = 0.75; % spacing between electrodes in mm b = 0.3; % space constant in mm % prepare non-overlapping crossover frequencies according to Greenwood % -------------------------------------------------------------------- for i=1:23 %elec_position_base(i)=insertion-elecspacing*(i-1); % position of elec in cochlea from base [mm] crossover_position_base(i)=insertion - (elecspacing*(i-1) - elecspacing*0.5); % position between electrodes from base [mm] end crossover_position_apex=cochlength-crossover_position_base'; % position between electrodes from apex [mm] crossover_freqs_greenwood=Greenwood_x2cf(crossover_position_apex); % corresponding Greenwood frequencies % check if there are frequencies above 1/2 sampling rate, % and remove those bands from FTM, electrodes and crossover freq table toohigh=sum(crossover_freqs_greenwood>0.5*pre.resynthesis_rate); crossover_freqs_greenwood=crossover_freqs_greenwood(1:end-toohigh); % only those < half the sampling rate pre.electrodes=pre.electrodes(1:sum(p.electrodes>toohigh)); FTM=FTM(1:sum(p.electrodes>toohigh),:); num_bands_after=length(pre.electrodes); if pre.num_bands~=num_bands_after msgbox([num2str(pre.num_bands-num_bands_after) ' of the active basal electrodes correspond(s) to frequencies > half the sampling frequency and will be disabled.'],'Disabling electrodes','warn','modal'); end pre.num_bands=num_bands_after; % resynthesize % ------------ %sinusoid pre.resynthesis_carrier = 'sinus'; if get(handles.AnalRadio,'Value') pre.crossover_freqs=p.crossover_freqs; % sinusoids following crossover frequencies as in analysis filename=[filename '_sinus']; else pre.crossover_freqs=crossover_freqs_greenwood; % sinusoids following Greenwood filename=[filename '_sinus_green_' num2str(cochlength) '_' num2str(insertion)]; end else % NOISE pre.resynthesis_carrier = 'noise'; if get(handles.AnalRadio,'Value') pre.crossover_freqs=p.crossover_freqs; % noise bands following analysis freq bands, non-overlapping filename=[filename '_noise']; else if get(handles.OverBox,'Value') % exponentially decaying, overlapping frequency bands, after Greenwood for i=1:22 pre.resynthesis_A(i,:) = 1; pre.resynthesis_B(i,:) = CISimulationFilter(insertion-elecspacing*(i-1),pre.resynthesis_rate,b,cochlength); end filename=[filename '_noise_green_' num2str(cochlength) '_' num2str(insertion) '_olap_' num2str(b)]; else % crossover frequencies after Greenwood, non-overlapping pre.crossover_freqs=crossover_freqs_greenwood; filename=[filename '_noise_green_' num2str(cochlength) '_' num2str(insertion)]; end end end pre = resynthesis(pre); simul = resynthesis(pre,FTM); %Windowing and zeropadding to remove clicks w = risewindow(length(simul),0.01*pre.resynthesis_rate)'; %a 10 ms linear rise and fall simul = [zeros(1,10) w.*simul zeros(1,10)]; if get(handles.NormalizeBox,'Value') % normalize output amp1=sum(handles.audio.^2); amp2=sum(simul.^2); %simul=simul*sqrt(amp1/amp2); % normalize to input level simul=0.9*simul/max(abs(simul)); % normalize to 90 % end return;