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