% Generates Risset Scale (an analog of Escher's ever % descending stairs) for auditory illusion. f is the % minimum frequency used, n is the number of harmonics % used, sigma is a measure of the width of the % (unnormalized) gaussian distribution that % envelopes the harmonics. It repeatedly plays the same % unit sound pattern the give an illusion of ever- % descending frequency. sp=0; %look at the end of this code and at the beginning of anim=0; % risset_helper.m %%%%%%%%%%%% controls for frequency %%%%%%%%%%%%%%%%%%% f=27.5; fund=uicontrol(...% the fundemental frequency in the illusion 'Style','slider',... 'Units','normalized',... 'Position',[.025 .87 .17 .04],... 'Min',20,'Max',200,... 'Value',f,... 'Callback',[... 'f=get(gcbo,''Value'');'... 'set(fund,''String'',num2str(f));']); uicontrol('Style','text',...%label for frequency slider 'Units','normalized',... 'Position',[.05 .92 .12 .04],... 'String','frequency'); fundtext = uicontrol(... %textbox for frequency 'Style','edit',... 'Units','normalized',... 'Position',[.07 .82 .08 .04],... 'Min',20,'Max',200,... 'String',num2str(f),... 'Callback',[... 'f=str2num(get(gcbo,''String''));'... 'set(fund,''Value'',f);'... ]); %%%%%%%%%%%% controls for width %%%%%%%%%%%%%%%%%%%%% width_coeff=1/6; w_c=uicontrol(...%a coefficient determining the width of the envelope curve 'Style','slider',... 'Units','normalized',... 'Position',[.025 .69 .17 .04],... 'Min',0.1,'Max',1,... 'Value',width_coeff,... 'Callback',[... 'width_coeff=get(gcbo,''Value'');'... 'set(w_c,''String'',num2str(width_coeff));']); uicontrol('Style','text',...% label for width_coefficienf slider 'Units','normalized',... 'position',[.075 .74 .07 .04],... 'String','width'); widthtext=uicontrol('Style','edit',...%textbox for width coeffficient 'Units','normalized',... 'Position',[.075 .64 .07 .04],... 'Min',0.1,'Max',1,... 'String',num2str(width_coeff),... 'Callback',[... 'width_coeff=str2num(get(gcbo,''String''));'... 'set(w_c,''Value'',width_coeff);'... ]); %%%%%%%%%%% controls for number of harmonics %%%%%%%%%%%%%%%%%%%%%%%% for k=1:10; %adjusts the # of harmonics to the optimum value n_0=k; %which can be later changed on GUI if desired if f*2^n_0>10000, break, end end n_harmonics=n_0; %starting value for # of harmonics num_har=uicontrol(...% slider for the number of harmonics 'Style','slider',... 'Units','normalized',... 'Position',[.025 .48 .17 .04],... 'Min',1,'Max',11,... 'SliderStep',[0.1 0.1],... 'Value',n_harmonics,... 'Callback',[... 'n_harmonics=get(gcbo,''Value'');'... 'set(num_har,''String'',num2str(n_harmonics));']); uicontrol('Style','text',...%label for # of harmonics 'Units','normalized',... 'Position',[.05 .53 .12 .07],... 'String','# of harmonics'); numtext = uicontrol(... %textbox for frequency 'Style','edit',... 'Units','normalized',... 'Position',[.075 .43 .07 .04],... 'Min',1,'Max',12,... 'String',num2str(n_harmonics),... 'Callback',[... 'n_harmonics=str2num(get(gcbo,''String''));'... 'set(num_har,''Value'',n_harmonics);'... ]); %%%%%%%%% control to start the demo %%%%%%%%%%%%%%%%%%%%%% uicontrol('Style','pushbutton',...%button to start the demo 'Units','normalized',... 'Position',[.04 .08 .12 .10],... 'Callback','risset_helper',... 'String','Start Demo'); %%%%%%%%%%%%%%%% button to optimize # of harmonics %%%%%%%%%%%% uicontrol(...%pushbutton to optimize the # of frequency 'Style','pushbutton',... 'Units','Normalized',... 'Position',[.05 .38 .12 .04],... 'Callback',[... 'for k=1:10;'... % adjusts the # of harmonics to the optimum value 'n_opt=k;'... % which can be later changed on GUI if desired 'if f*2^n_opt>10000;'... % here optimum is the maximum # without violating 'break;'... % the constraints from sampling rate. 'end;'... 'end;'... 'n_harmonics=n_opt;'... 'set(num_har,''Value'',n_harmonics);'],... 'String','optimize #'); %%%%%%%%%%%%%% spectrogram button %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% uicontrol(...%pushbuttton for displaying the spectrogram 'Style','pushbutton',... 'Units','Normalized',... 'Position',[.02 .25 .18 .06],... 'Callback',[... 'axes(''position'',[.30 .08 .60 .32]);'... 'specgram(temp,[],44100);'... 'title(''Spectrogram of the Sound'');'... 'sp=gca;'... % this will later be used to delete the graph in the ],... % beginning of risset_helper. Each time we Start Demo, 'String','Display Specgram');% ols specgram will be deleted