function lavaLamp(stimulusDuration, nPeriods, spatialCutoffFreq, temporalCutoffFreq, highWaveColor, randomSeed) HideCursor; [w, screenRect] = Screen(0,'OpenWindow',[0 0 0]); screenHz = Screen(w,'FrameRate'); tic; %% Loads experiment parameters parameter.screenHeight = 31; parameter.screenWidth = 41; parameter.mouseHeight = 7; parameter.mouseDistance = 25; %cm %% generates a mean luminence background [h,s,v] = rgb2hsv(highWaveColor); [r,g,b] = hsv2rgb([h, s, v/2]); backgroundColor = round([r g b]); Screen(w,'FillRect',backgroundColor); %% END OF BACKGROUND SCREEN GENERATION x = linspace(-10,10,100); y = linspace(-10,10,100); [xx,yy] = meshgrid(x,y); azimuthAngle = 180/pi*atan((parameter.screenWidth/2)/parameter.mouseDistance); azimuthSampleRate = (size(xx,2)/2)/azimuthAngle; elevationAngle = 180/pi*atan((parameter.screenHeight-parameter.mouseHeight)/parameter.mouseDistance); elevationSampleRate = size(yy,1)*(parameter.screenHeight-parameter.mouseHeight)/parameter.screenHeight/elevationAngle; disk = ((xx).^2)/(spatialCutoffFreq/(azimuthSampleRate/2)*max(x)) + ((yy).^2)/(spatialCutoffFreq/(elevationSampleRate/2)*max(y)) < 1; rand('seed',randomSeed); video = zeros([size(disk) stimulusDuration*screenHz]); for i = 1:size(video,3) r = randn(size(disk)); rf = fft2(r); video(:,:,i) = real(ifft2(fftshift(disk).*rf)); end [filterNum,filterDen] = butter(4,temporalCutoffFreq/(screenHz/2)); video = filter(filterNum,filterDen,video,[],3); contrastSinusoid = shiftdim(sin(pi*[1:size(video,3)]/size(video,3)),-1); video = video.*repmat(contrastSinusoid,[size(video)./size(contrastSinusoid)]); video = uint8(round(256*(video-min(min(min(video))))/(max(max(max(video)))-min(min(min(video))))-1)); frames = zeros(1,size(video,3)); for i = 1:length(frames) [frames(i),junk] = Screen(0,'OpenOffscreenWindow',backgroundColor,[0 0 size(video,1) size(video,2)]); Screen(frames(i),'PutImage',video(:,:,i)); end j = 0; n = 0; z = 0; %% executes video presentation loop = { 'for j = 1:nPeriods;' 'for n = 1:length(frames);' 'Screen(''CopyWindow'',frames(n),w);' 'Screen(w,''WaitBlanking'');' 'end;' 'end;'}; priorityLevel = MaxPriority(w,'WaitBlanking'); tic Rush(loop,priorityLevel); toc Screen(w,'FillRect',backgroundColor); %% END OF VIDEO PRESENTATION ShowCursor; Screen('CloseAll'); % Closes all screens used to present the stimulus