pb_vCreateSignal.m 3 KB
Newer Older
Jesse Heckman's avatar
Jesse Heckman committed
1
function D = pb_vCreateSignal(N, dur, SR, freq, type, varargin)
2
% PB_VCREATESIGNAL
Jesse Heckman's avatar
Jesse Heckman committed
3
%
4
% PB_VCREATESIGNAL(N, dur, SR, freq, type, varargin) creates an unscaled
5
% signal for the vestibular chair.
Jesse Heckman's avatar
Jesse Heckman committed
6
%
7
% See also PB_VPRIME, PB_VPRIMEGUI, PB_VRUNEXP, PB_VSIGNALVC.
Jesse Heckman's avatar
Jesse Heckman committed
8
9

% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
Jesse Heckman's avatar
Jesse Heckman committed
10
   
Jesse Heckman's avatar
Jesse Heckman committed
11
   dshow = pb_keyval('dshow',varargin,false);
Jesse Heckman's avatar
Jesse Heckman committed
12
13
   
   D(N) = struct;
14
   for i = 1:N
Jesse Heckman's avatar
Jesse Heckman committed
15
      switch type
Jesse Heckman's avatar
Jesse Heckman committed
16
17
18
         case 'none'
            [D(i).x,D(i).t] = VC_turnsignal(dur, SR);
            D(i).x = D(i).x .* 0;
Jesse Heckman's avatar
Jesse Heckman committed
19
20
21
22
23
24
25
26
         case 'noise' 
            [D(i).x,D(i).t] = VC_noisesignal(0, dur, SR);
         case 'sine'
            [D(i).x,D(i).t] = VC_sinesignal(dur, SR, freq);
         case 'predictsine'
            [D(i).x,D(i).t] = VC_predictedsine(dur, SR, freq);
         case 'turn'
            [D(i).x,D(i).t] = VC_turnsignal(dur, SR);
27
28
         case 'vor'
            [D(i).x,D(i).t] = VC_VOR(dur, SR);
Jesse Heckman's avatar
Jesse Heckman committed
29
30
31
32
         otherwise
            error('False type specification');
      end
   end
33
   if dshow; figure; hold on; for i=1:N; plot(D(i).t,D(i).x); pb_nicegraph; end; end
Jesse Heckman's avatar
Jesse Heckman committed
34
35
end

36
%-- Specific signal functions --%
Jesse Heckman's avatar
Jesse Heckman committed
37
38
39
40
41
42
43
44
45
46
function [x,t] = VC_noisesignal(mu, dur, SR)
    % function generates a noise signal with mean mu, length dur and frequency freq.
    
    % noise signal
    sigma   =   0;
    t       =   0:1/SR:dur;
    x       =   mu+sigma;
    x       =   x+randn(length(t),1);

    % cheby filtered signal
47
    n       =   10; 
Jesse Heckman's avatar
Jesse Heckman committed
48
49
50
51
52
    Ws      =   1;
    Rs      =   80; 
    LPfil   =   designfilt('lowpassiir', 'FilterOrder', n,...
                           'StopbandFrequency', Ws,...
                           'StopbandAttenuation', Rs,...
53
                           'SampleRate', SR);                   
Jesse Heckman's avatar
Jesse Heckman committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    x  =   filtfilt(LPfil,x);

    % tukey window 
    L       =   length(t);
    x       =   x.* tukeywin(L,0.25);
end

function [x,t] = VC_sinesignal(dur, SR, freq)
    % function generates a sine signal

    w = freq*2*pi;
    t = 0:1/SR:dur;
    x = sin(w*t);
    
Jesse Heckman's avatar
Jesse Heckman committed
68
69
    tsz    	=   length(t);
    x       =   x .* tukeywin(tsz,0.25)';
Jesse Heckman's avatar
Jesse Heckman committed
70
71
end

72
73
function [x,t] = VC_predictedsine(dur, SR, freq) %%% <--- TO DO: FIX THE TRANSFER FUNCTION!!
    % function generates a perfect sine output
Jesse Heckman's avatar
Jesse Heckman committed
74
75
    
    t = 0:1/SR:dur;
Jesse Heckman's avatar
Jesse Heckman committed
76
    xfun       = pb_y2x();
Jesse Heckman's avatar
Jesse Heckman committed
77
    
Jesse Heckman's avatar
Jesse Heckman committed
78
79
    tsz        =   length(t);
    x          =   xfun(1,freq,t) .* tukeywin(tsz,0.25)';
Jesse Heckman's avatar
Jesse Heckman committed
80
81
82
83
84
85
end

function [x,t]  = VC_turnsignal(dur, SR)
    % function will create turn signal of length dur
    
    t = 0:1/SR:dur;
Jesse Heckman's avatar
Jesse Heckman committed
86
    x = t;
87
88
89
90
91
92
93
end

function [x,t]  = VC_VOR(dur, SR)
    % function will create turn signal of length dur
    
    t = 0:1/SR:dur;
    x = t;
Jesse Heckman's avatar
Jesse Heckman committed
94
    
95
96
97
    tsz = length(t);
    ind = floor(tsz/2);
    x(ind+1:end) = x(ind);
Jesse Heckman's avatar
Jesse Heckman committed
98
end
Jesse Heckman's avatar
Jesse Heckman committed
99

Jesse Heckman's avatar
Jesse Heckman committed
100
101
102
103
104
105
106
107
 
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
%                                                           %
%       Part of Programmeer Beer Toolbox (PBToolbox)        %
%       Written by: Jesse J. Heckman (2018)                 %
%                                                           %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %