1
+ function test_issue2085
2
+
3
+ % MEM 1gb
4
+ % WALLTIME 00:10:00
5
+ % DEPENDENCY ft_resampledata ft_specest_irasa
6
+
7
+ % test function to evaluate the reported scale difference when resampling
8
+ % with the drop in compat replacement of the resample function (and lower
9
+ % level dependencies).
10
+
11
+ global ft_default
12
+ [ftver , ftpath ] = ft_version ;
13
+
14
+
15
+ % simulate data
16
+ t = (1 : 1000 )/1000 ;
17
+ fn = cumsum(randn(1 ,length(t )));
18
+ in_dat = fn + cos(2 * pi * 10 * t ) + cos(2 * pi * 60 * t );
19
+
20
+ in_dat = in_dat - mean(in_dat );
21
+
22
+ % resample, using a variety of p/q ratios
23
+ p = [1 : 50 1 : 50 ]; q = [10 * ones(1 ,50 ) 11 * ones(1 ,50 )];
24
+
25
+ restoredefaultpath
26
+ addpath(ftpath );
27
+ ft_default.toolbox.signal = ' compat' ;
28
+ ft_defaults ;
29
+ fprintf(sprintf(' resampling with: %s\n ' , which(' resample' )));
30
+ for k = 1 : numel(p )
31
+ out_ft_rspu{k ,1 } = resample(in_dat , p(k ), q(k ));
32
+ out_ft_rspd{k ,1 } = resample(in_dat , q(k ), p(k ));
33
+ end
34
+
35
+ restoredefaultpath
36
+ addpath(ftpath );
37
+ ft_default.toolbox.signal = ' matlab' ;
38
+ ft_defaults ;
39
+ fprintf(sprintf(' resampling with: %s\n ' , which(' resample' )));
40
+ for k = 1 : numel(p )
41
+ out_mat_rspu{k ,1 } = resample(in_dat , p(k ), q(k ));
42
+ out_mat_rspd{k ,1 } = resample(in_dat , q(k ), p(k ));
43
+ end
44
+
45
+ for k = 1 : numel(p )
46
+ bd(k ,1 ) = out_ft_rspd{k }/out_mat_rspd{k };
47
+ bu(k ,1 ) = out_ft_rspu{k }/out_mat_rspu{k };
48
+ end
49
+ figure ;plot(bu );hold on ;plot(bd );
50
+
51
+ assert(all(bu > 0.999) && all(bd > 0.999));
52
+ % there's a tiny scale difference between the legacy matlab and the compat
53
+ % version, which could be titrated to be closer to 1, but that would not be
54
+ % based on a mathematically informed choice, so I think we may accept this <0.1% amplitude diff.
55
+
56
+
57
+ % figure(); hold on;
58
+ % plot(in_dat, '-b');
59
+ % plot(out_ft_rspu, '-r');
60
+ % plot(out_mat_rspu, '-g');
61
+ % legend({'original data', 'ft resampled', 'mat resampled'});
62
+ % title('upsample')
63
+ % hold off;
64
+ %
65
+ % figure(); hold on;
66
+ % plot(in_dat, '-b');
67
+ % plot(out_ft_rspd, '-r');
68
+ % plot(out_mat_rspd, '-g');
69
+ % legend({'original data', 'ft resampled', 'mat resampled'});
70
+ % title('downsample');
71
+ % hold off;
0 commit comments