-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpspm_bf_data.m
42 lines (41 loc) · 1.35 KB
/
pspm_bf_data.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function [bf, x] = pspm_bf_data(td)
% ● Description
% pspm_bf_data provides a generic interface for creating a user-defined
% response function from a data vector saved in a *.mat file. To use this
% function, the variables 'datafile' and 'sr' need to be hard-coded. GLM
% can then be called with the optional argument model.bf = 'pspm_bf_data'.
% ● Format
% [bf, x] = pspm_bf_data(td)
% ● Arguments
% td: the time interval in points for sampling
% ● History
% Introduced in PsPM 5.1.1
% Written in 2021 by Dominik R Bach (University College London)
% Maintained in 2022 by Teddy Chao (UCL)
%% Constants
% CHANGE THIS TO CREATE YOUR FUNCTION
datafile = 'pspm_bf_data_sample.mat';
% this should be a *.mat file that contains a variable named 'data' with
% the data vector
sr = 10;
% this should be the sampling rate of your data vector, default to be 10
%% Check input arguments
if nargin==0
errmsg='No sampling interval stated'; warning('ID:invalid_input', errmsg); return;
end
%% Load data
if isempty(datafile)
return
end
[~,~,indata,] = pspm_load_data(datafile, 1);
data = indata{1,1}.data;
%% Processing
% determine original sampling points
x_old = - 1/(2*sr) + (1:numel(data))/sr;
% determine new sampling points
x = (td:td:(numel(data)/sr));
% resample
bf = interp1(x_old, data, x, 'nearest', 'extrap');
bf = [0; bf(:)];
x = [0; x(:)];
return