~ubuntu-branches/ubuntu/trusty/psychtoolbox-3/trusty-proposed

« back to all changes in this revision

Viewing changes to Psychtoolbox/PsychHardware/PR670Toolbox/PR670parsespdstr.m

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2013-11-19 23:34:50 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20131119233450-f7nf92vb8qavjmk8
Tags: 3.0.11.20131017.dfsg1-3
Upload to unsable since fresh glew has arrived to sid!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function spd = PR670parsespdstr(readStr, S)
 
2
% PR670parsespdstr - Parses the  spectral power distribution string returned by the PR-670.
 
3
%
 
4
% Syntax:
 
5
% spd = PR670parsespdstr(readStr)
 
6
% spd = PR670parsespdstr(readStr, S);
 
7
%
 
8
% Description:
 
9
% Parse the spectral power distribution string returned by the PR-670.  The
 
10
% results are splined to the desired wavelength sampling defined by the 'S'
 
11
% input parameter.
 
12
%
 
13
% Input:
 
14
% readStr (1xN char) - Raw data returned from a meter measurment.
 
15
% S (1x3) - Wavelength sampling.  Default: [380 5 81]
 
16
 
 
17
if nargin < 2 || isempty(S)
 
18
        S = [380 5 81];
 
19
end
 
20
 
 
21
% Split up the data delimited by newline characters.
 
22
C = textscan(readStr, '%s', 'Delimiter', '\n');
 
23
C = C{1};
 
24
 
 
25
% Loop over all the data lines and pull out the spectral info.  Note that
 
26
% the first line doesn't contain wavelength data so we toss it.
 
27
C = C(2:end);
 
28
numWavelengths = length(C);
 
29
if (numWavelengths ~= 201)
 
30
    error('Unexpected native number of wavelength samples for PR-670');
 
31
end
 
32
spd = zeros(numWavelengths, 1);
 
33
wavelengths = spd;
 
34
for i = 1:length(C)
 
35
        % Parse the wavelength measurement line.  The first element of the
 
36
        % returned cell array will be the wavelength, the second element the
 
37
        % measurement.
 
38
        D = textscan(C{i}, '%d,%f');
 
39
        
 
40
        wavelengths(i) = D{1};
 
41
        spd(i) = D{2};
 
42
end
 
43
 
 
44
% Convert to our units standard.
 
45
spd = 2 * spd;
 
46
if (wavelengths(2)-wavelengths(1) ~= 2)
 
47
    error('Unexpected native wavelength sampling for PR-670');
 
48
end
 
49
 
 
50
% Spline to desired wavelength sampling.
 
51
startWavelength = wavelengths(1);
 
52
spacing = wavelengths(2) - wavelengths(1);
 
53
S0 = [startWavelength, spacing, numWavelengths];
 
54
spd = SplineSpd(S0, spd, S);