annotate matlab/AIMCread.m @ 59:b990812568d2

- AWS scripts update (path 2)
author tomwalters
date Wed, 11 Aug 2010 09:09:38 +0000
parents c8024714e13e
children f03d4455b262
rev   line source
tomwalters@46 1 function [data, nFrames, period, nChannels, nSamples, sample_rate] = AIMCread(filename)
tomwalters@46 2 %[data, nFrames, period, nChannels, nSamples ] = AIMCread( filename)
tomwalters@46 3 %
tomwalters@46 4 % data ... matrix (or array) of size [nFrames,nChannels,nSamples]
tomwalters@46 5 % in case vertical/horizontal profiles are read, you should use squeeze
tomwalters@46 6 % nFrames ... number of frames
tomwalters@46 7 % period ... Frame interval in ms
tomwalters@46 8 % nChannels ... points on vertical axis of an auditori image
tomwalters@46 9 % nSamples ... points on horizontal axis of an auditori image
tomwalters@46 10
tomwalters@46 11 fid = fopen(filename);
tomwalters@46 12
tomwalters@46 13 debug = 0;
tomwalters@46 14
tomwalters@46 15 nFrames = fread( fid, 1, 'int32');
tomwalters@46 16 period = fread( fid, 1, 'float32'); % Frame period in ms
tomwalters@46 17 nChannels = fread( fid, 1, 'int32'); % vertical axis of an AI
tomwalters@46 18 nSamples = fread( fid, 1, 'int32'); % horizontal axis of an AI
tomwalters@46 19 sample_rate = fread(fid, 1, 'float32'); % sample rate of each channel in Hz
tomwalters@46 20
tomwalters@46 21 if nChannels == 1 % temporal profiles
tomwalters@46 22 data = fread( fid, [nSamples,nFrames], 'float32'); % transposed!
tomwalters@46 23 data = data.';
tomwalters@46 24 data = reshape( data, [nFrames,1,nSamples]); % to have the same dimensions
tomwalters@46 25 % if a 'squeeze' is used, this line has no effect at all
tomwalters@46 26 if debug
tomwalters@46 27 disp('seems to be temporal profiles')
tomwalters@46 28 end
tomwalters@46 29 elseif nSamples == 1 % spectral profiles
tomwalters@46 30 data = fread( fid, [nChannels,nFrames], 'float32'); % transposed!
tomwalters@46 31 data = data.';
tomwalters@46 32 %data = reshape( data, [nFrames,nChannels,1]); % has no effect
tomwalters@46 33 if debug
tomwalters@46 34 disp('seems to be spectral profiles')
tomwalters@46 35 end
tomwalters@46 36 else % auditory 2d images
tomwalters@46 37 data = zeros(nFrames,nChannels,nSamples);
tomwalters@46 38 for k=1:nFrames % loop since fread cannot return 3d array
tomwalters@46 39 Image = fread(fid, [nSamples,nChannels], 'float32'); % transposed!
tomwalters@46 40 data(k,:,:) = Image.';
tomwalters@46 41 end
tomwalters@46 42 if debug
tomwalters@46 43 disp('seems to be 2d images')
tomwalters@46 44 end
tomwalters@46 45 end
tomwalters@46 46
tomwalters@46 47 fclose(fid);