@@ -675,7 +675,102 @@ function testMarkerTimeunits(testCase, nFiles)
675675
676676end
677677
678+ function testZscoreNormalization(testCase )
678679
680+ sr = 10 ;
681+ duration = 50 ;
682+ window = 5 ;
683+
684+ t = (0 : 1 / sr : window - 1 / sr )' ;
685+ response = exp(-((t - 2 ).^2 ) / (2 * 0.5 ^ 2 ));
686+
687+ onsets = [10 20 30 ];
688+
689+ y = zeros(duration * sr , 1 );
690+
691+ for iTrial = 1 : numel(onsets )
692+ startSample = round(onsets(iTrial ) * sr ) + 1 ;
693+ stopSample = startSample + numel(response ) - 1 ;
694+
695+ y(startSample : stopSample ) = ...
696+ y(startSample : stopSample ) + response ;
697+ end
698+
699+ timing.names = {' condition_1' };
700+ timing.onsets = {onsets };
701+ timing.durations = {zeros(size(onsets ))};
702+
703+ data = cell(1 ,1 );
704+
705+ data{1 }.header = struct( ...
706+ ' chantype' , ' pupil' , ...
707+ ' sr' , sr , ...
708+ ' units' , ' a.u.' );
709+
710+ data{1 }.data = y(: );
711+
712+ infos.duration = duration ;
713+ infos.durationinfo = ' Duration in seconds' ;
714+ infos.source = struct();
715+
716+ datafile = [tempname ' .mat' ];
717+ save(datafile , ' data' , ' infos' );
718+ testCase .addTeardown(@() deleteIfExists(datafile ));
719+
720+ % ----
721+ modelfile = [tempname ' .mat' ];
722+ testCase .addTeardown(@() deleteIfExists(modelfile ));
723+
724+ model = struct();
725+
726+ model.modelfile = modelfile ;
727+ model.datafile = {datafile };
728+ model.timing = {timing };
729+
730+ model.timeunits = ' seconds' ;
731+ model.window = window ;
732+
733+ model.modelspec = ' dilation' ;
734+ model.modality = ' pupil' ;
735+ model.channel = ' pupil' ;
736+
737+ % This is what we are testing
738+ model.norm = 1 ;
739+
740+ model.baseline = 0 ;
741+ model.norm_max = 0 ;
742+
743+ model.filter = struct( ...
744+ ' lpfreq' , ' none' , ...
745+ ' lporder' , 1 , ...
746+ ' hpfreq' , ' none' , ...
747+ ' hporder' , 1 , ...
748+ ' down' , ' none' , ...
749+ ' direction' , ' bi' );
750+
751+ options.overwrite = 1 ;
752+
753+ [sts , tam ] = pspm_tam(model , options );
754+
755+ testCase .verifyEqual(sts , 1 );
756+
757+ % Expected z-scoring of the COMPLETE continuous time series
758+ mu = mean(y , ' omitnan' );
759+ sigma = std(y , 0 , ' omitnan' );
760+
761+ expected = (response - mu ) / sigma ;
762+
763+ % TAM subsequently baselines against the first point
764+ expected = expected - expected(1 );
765+
766+ testCase .verifyEqual( ...
767+ tam.data.Y{1 }, ...
768+ expected(: ), ...
769+ ' AbsTol' , 1e- 10 );
770+
771+ testCase .verifyEqual(tam .data.norm, 1 );
772+
773+ end
679774
680775
681776
0 commit comments