tomwalters@46: function [data, nFrames, period, nChannels, nSamples, sample_rate] = AIMCread(filename) tomwalters@46: %[data, nFrames, period, nChannels, nSamples ] = AIMCread( filename) tomwalters@46: % tomwalters@46: % data ... matrix (or array) of size [nFrames,nChannels,nSamples] tomwalters@46: % in case vertical/horizontal profiles are read, you should use squeeze tomwalters@46: % nFrames ... number of frames tomwalters@46: % period ... Frame interval in ms tomwalters@46: % nChannels ... points on vertical axis of an auditori image tomwalters@46: % nSamples ... points on horizontal axis of an auditori image tomwalters@46: tomwalters@46: fid = fopen(filename); tomwalters@46: tomwalters@46: debug = 0; tomwalters@46: tomwalters@157: nFrames = fread( fid, 1, 'int32'); tomwalters@46: period = fread( fid, 1, 'float32'); % Frame period in ms tomwalters@157: nChannels = fread( fid, 1, 'int32'); % vertical axis of an AI tomwalters@157: nSamples = fread( fid, 1, 'int32'); % horizontal axis of an AI tomwalters@46: sample_rate = fread(fid, 1, 'float32'); % sample rate of each channel in Hz tomwalters@46: tomwalters@46: if nChannels == 1 % temporal profiles tomwalters@46: data = fread( fid, [nSamples,nFrames], 'float32'); % transposed! tomwalters@46: data = data.'; tomwalters@46: data = reshape( data, [nFrames,1,nSamples]); % to have the same dimensions tomwalters@46: % if a 'squeeze' is used, this line has no effect at all tomwalters@46: if debug tomwalters@46: disp('seems to be temporal profiles') tomwalters@46: end tomwalters@46: elseif nSamples == 1 % spectral profiles tomwalters@46: data = fread( fid, [nChannels,nFrames], 'float32'); % transposed! tomwalters@46: data = data.'; tomwalters@46: %data = reshape( data, [nFrames,nChannels,1]); % has no effect tomwalters@46: if debug tomwalters@46: disp('seems to be spectral profiles') tomwalters@46: end tomwalters@46: else % auditory 2d images tomwalters@46: data = zeros(nFrames,nChannels,nSamples); tomwalters@46: for k=1:nFrames % loop since fread cannot return 3d array tomwalters@46: Image = fread(fid, [nSamples,nChannels], 'float32'); % transposed! tomwalters@46: data(k,:,:) = Image.'; tomwalters@46: end tomwalters@46: if debug tomwalters@46: disp('seems to be 2d images') tomwalters@46: end tomwalters@46: end tomwalters@46: tomwalters@46: fclose(fid);