comparison trunk/matlab/AIMCread.m @ 320:c74acd46121b

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