annotate trunk/matlab/AIMCread.m @ 706:f8e90b5d85fd tip

Delete CARFAC code from this repository. It has been moved to https://github.com/google/carfac Please email me with your github username to get access. I've also created a new mailing list to discuss CARFAC development: https://groups.google.com/forum/#!forum/carfac-dev
author ronw@google.com
date Thu, 18 Jul 2013 20:56:51 +0000
parents b5dca605c3d5
children
rev   line source
tomwalters@614 1 function [data, nFrames, period, nChannels, nSamples, sample_rate] = ...
tomwalters@614 2 AIMCread(filename, strobes_filename)
tomwalters@320 3 %[data, nFrames, period, nChannels, nSamples ] = AIMCread( filename)
tomwalters@320 4 %
tomwalters@320 5 % data ... matrix (or array) of size [nFrames,nChannels,nSamples]
tomwalters@320 6 % in case vertical/horizontal profiles are read, you should use squeeze
tomwalters@320 7 % nFrames ... number of frames
tomwalters@320 8 % period ... Frame interval in ms
tomwalters@614 9 % nChannels ... points on vertical axis of an auditory image
tomwalters@614 10 % nSamples ... points on horizontal axis of an auditory image
tomwalters@320 11
tomwalters@320 12 fid = fopen(filename);
tomwalters@320 13
tomwalters@614 14 strobes_fid = -1;
tomwalters@614 15 if nargin > 1
tomwalters@614 16 strobes_fid = fopen(strobes_filename);
tomwalters@614 17 strobes_raw = fread(strobes_fid, [], 'int32');
tomwalters@614 18 end
tomwalters@614 19
tomwalters@320 20 debug = 0;
tomwalters@320 21
tom@440 22 nFrames = fread( fid, 1, 'uint32');
tomwalters@320 23 period = fread( fid, 1, 'float32'); % Frame period in ms
tom@440 24 nChannels = fread( fid, 1, 'uint32'); % vertical axis of an AI
tom@440 25 nSamples = fread( fid, 1, 'uint32'); % horizontal axis of an AI
tomwalters@320 26 sample_rate = fread(fid, 1, 'float32'); % sample rate of each channel in Hz
tomwalters@320 27
tomwalters@320 28 if nChannels == 1 % temporal profiles
tomwalters@320 29 data = fread( fid, [nSamples,nFrames], 'float32'); % transposed!
tomwalters@320 30 data = data.';
tomwalters@320 31 data = reshape( data, [nFrames,1,nSamples]); % to have the same dimensions
tomwalters@320 32 % if a 'squeeze' is used, this line has no effect at all
tomwalters@320 33 if debug
tomwalters@320 34 disp('seems to be temporal profiles')
tomwalters@320 35 end
tomwalters@320 36 elseif nSamples == 1 % spectral profiles
tomwalters@320 37 data = fread( fid, [nChannels,nFrames], 'float32'); % transposed!
tomwalters@320 38 data = data.';
tomwalters@320 39 %data = reshape( data, [nFrames,nChannels,1]); % has no effect
tomwalters@320 40 if debug
tomwalters@320 41 disp('seems to be spectral profiles')
tomwalters@320 42 end
tomwalters@320 43 else % auditory 2d images
tomwalters@320 44 data = zeros(nFrames,nChannels,nSamples);
tomwalters@320 45 for k=1:nFrames % loop since fread cannot return 3d array
tomwalters@320 46 Image = fread(fid, [nSamples,nChannels], 'float32'); % transposed!
tomwalters@320 47 data(k,:,:) = Image.';
tomwalters@320 48 end
tomwalters@320 49 if debug
tomwalters@320 50 disp('seems to be 2d images')
tomwalters@320 51 end
tomwalters@320 52 end
tomwalters@320 53
tomwalters@320 54 fclose(fid);