To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at git://github.com/rmeddis/MAP.git .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Revision:

root / multithreshold 1.46 / psychometricFunction.m @ 0:f233164f4c86

History | View | Annotate | Download (1.51 KB)

1
% ------------------------------------------------------- psychometricFunction
2
function [psy, levelsBinVector, binFrequencies, nNo, nYes]=...
3
    psychometricFunction(levels, responses, psyBinWidth)
4
% computes a psychometric function from rwo vectors (levels and responses)
5
% responses is a binary vectory (1=yes)
6
% psyBinWidth is the bin width (dB) of the output psychometric function
7
% this function is called by both fitPsychometricFunction and subjGUI
8
% for this reason it should notbe bundled with fitPsychometricFunction
9

    
10
binFrequencies=[]; nNo=[]; nYes=[];
11
if min(levels)+abs(psyBinWidth) < max(levels)
12
    % create a set of bins for the psychometric function
13
    levelsBinVector= min(levels): abs(psyBinWidth): max(levels);
14
else
15
    psy=[]; levelsBinVector=[];
16
    return
17
end
18

    
19
idx0=find(responses==0);	% isolate 'no'
20
z=levels(idx0);
21
nNo=hist(z, levelsBinVector);
22

    
23
idx1=find(responses>0);	% isolate 'yes'
24
y=levels(idx1);
25
nYes=hist(y, levelsBinVector);
26

    
27
if sum(nNo)==0 | sum(nYes)==0
28
        psy=[]; levelsBinVector=[];
29
    return             % yesses and nos required for a function
30
end
31

    
32
binFrequencies=nNo+nYes;
33

    
34
warning off MATLAB:divideByZero
35
psy=nYes./binFrequencies;        % psy is the proportion of 'yes' responses
36
warning on MATLAB:divideByZero
37
lastwarn('');
38

    
39
idx=~isnan(psy);	%remove empty bins
40
idx=(nYes>0) |(nNo>0);	%remove empty bins
41
psy=psy(idx);
42
levelsBinVector=levelsBinVector(idx);
43
binFrequencies=binFrequencies(idx);
44
nNo=nNo(idx);
45
nYes=nYes(idx);
46

    
47
% [nNo' nYes']
48
% [levelsBinVector' psy']
49
% plot(levelsBinVector,psy,['o'])