-
Notifications
You must be signed in to change notification settings - Fork 0
/
spks_kernel.m
48 lines (29 loc) · 988 Bytes
/
spks_kernel.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
43
44
45
46
47
48
function krnl = spks_kernel( kType, kWidth )
if exist( 'kType', 'var' ) == false || isempty( kType ) == true
kType = 'psp';
end
if exist( 'kWidth', 'var' ) == false || isempty( kWidth ) == true
kWidth = 20;
end
switch lower( kType )
case 'gauss'
Half_BW = round( 4 * kWidth );
x = -Half_BW : Half_BW;
krnl = ( 1 / ( sqrt( 2 * pi ) * kWidth ) ) * ...
exp( -1 * ( ( x.^2 ) / ( 2 * kWidth^2 ) ) );
case 'psp'
if length( kWidth ) == 2
tg = kWidth( 2 );
kWidth( 2 ) = [];
else
tg = 1;
end
Half_BW = ceil( kWidth * 8 );
x = 0 : Half_BW;
krnl = [ zeros( 1, Half_BW ), ...
( 1 - ( exp( -( x ./ tg ) ) ) ) .* ( exp( -( x ./ kWidth) ) ) ];
end
krnl = krnl - krnl( end );
krnl( krnl < 0 ) = 0;
krnl = krnl / sum( krnl );
end