annotate matlab/AIMCread.m @ 603:087f3b3c36d3

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