% Catie % playshepard.m %% Main code %% % appears in shepardtones.m % initializes parameters max_time = 2; max_repeat = 3; num_harm = 5; A = 440; fs = 8192; % the sampling rate dt = 1/fs; t = [0:dt:max_time]; k = -2:2; m = 2^(1/12); % semitones sigmasq = 1; rep = []; % for j = 0:11 %y = zeros(size(t)); % initialize the tone vector % for i = 1:5 % use each harmonic in k % f_ij = 2^k(i)*(A*(m^j)); % the frequency of this component % amp = exp((-1/2*sigmasq)*(log2(f_ij/A))^2); % y = y + amp*cos(2*pi*f_ij*t); % end; %rep = [rep y]; % append the finished tone to the tone vector %end; % rep = repmat(rep,1,max_repeat); % repeat max_repeat times % soundsc(rep,fs); % play it %% Demox %% % play the demo uicontrol('Style','pushbutton',...%button to start the demo 'Units','normalized',... 'Position',[.01 .40 .24 .10],... 'Callback','shepardtones',... 'String','Play Shepard Tones'); % adjust number of repetitions uicontrol('Style','text',...% label for # of repetitions 'Units','normalized',... 'position',[.27 .45 .18 .04],... 'String','# repetitions'); numrepbox=uicontrol('Style','edit',... % text box, base frequency (A) 'Units','normalized',... 'Position',[.48 .45 .07 .04],... 'Min',0.1,'Max',1,... 'String',num2str(max_repeat),... 'Callback',[... 'max_repeat = str2num(get(gcbo,''String''));'... 'set(numrepbox,''Value'', max_repeat);'... ]); % adjust duration of tones uicontrol('Style','text',...% label for duration of tones 'Units','normalized',... 'position',[.27 .40 .18 .04],... 'String','tone duration'); tonedurslider=uicontrol(... 'Style','slider',... 'Units','normalized',... 'Position',[.48 .40 .17 .04],... 'Min',.2,'Max',4,... 'Value',max_time,... 'Callback',[... 'max_time=get(gcbo,''Value'');'... 'set(tonedurslider,''String'',num2str(max_time));']); % show the envelope, adjust sigma: x = -10:.01:10; G = exp((-1/2*sigmasq)*x.^2); subplot(3,1,1); plot(x,G); title('Envelope'); uicontrol('Style','text',...% label for sigma_squared 'Units','normalized',... 'position',[.01 .61 .18 .04],... 'String','sigma_squared'); sigmatextbox=uicontrol('Style','edit',... % text box, sigma 'Units','normalized',... 'Position',[.20 .61 .07 .04],... 'Min',0.1,'Max',1,... 'String',num2str(sigmasq),... 'Callback',[... 'sigmasq = str2num(get(gcbo,''String''));'... 'set(sigmatextbox,''Value'',sigmasq);'... 'drawsigma;'... ]); % adjust the base frequency (A) uicontrol('Style','text',...% label for base frequency 'Units','normalized',... 'position',[.01 .55 .18 .04],... 'String','base frequency'); basefreqbox=uicontrol('Style','edit',... % text box, base frequency (A) 'Units','normalized',... 'Position',[.20 .55 .07 .04],... 'Min',0.1,'Max',1,... 'String',num2str(A),... 'Callback',[... 'A = str2num(get(gcbo,''String''));'... 'set(basefreqbox,''Value'', A);'... ]); % adjust the number of harmonics uicontrol('Style','text',...% label for # of repetitions 'Units','normalized',... 'position',[.27 .30 .18 .04],... 'String','# harmonics'); numharmbox=uicontrol('Style','edit',... % text box, base frequency (A) 'Units','normalized',... 'Position',[.48 .30 .07 .04],... 'Min',2,'Max',10,... 'String',num2str(num_harm),... 'Callback',[... 'num_harm = str2num(get(gcbo,''String''));'... 'set(numharmbox,''Value'', num_harm);'... ]);