0001
0002
0003
0004
0005
0006 clear all;
0007
0008 gram = 0 ;
0009 chronux = 0;
0010 line = 0;
0011
0012 nSamples = 4210;
0013 nChannels = 1;
0014 nSegments = 1;
0015 movingwin = [50, 50];
0016
0017
0018
0019
0020 params.fpass = [ 0 0.5 ];
0021 params.pad = 2;
0022 params.err = [1 0.85];
0023 params.trialave = 1;
0024 params.Fs = 1;
0025
0026
0027
0028
0029 halfBandWidth = 2.5;
0030 kCap = 2*halfBandWidth - 1;
0031
0032 params.tapers = [ halfBandWidth, 1 ];
0033
0034
0035
0036
0037 if (gram==1) && (nChannels < 2), error( 'Coherence requires at least 2 channels...' ); end
0038 if (nSegments==1) && (params.err(1)==2), error( 'Jacknife requires more than 1 segment'); end
0039
0040
0041
0042
0043
0044 if ~chronux
0045
0046 sMarkers = reshape( sort( myrandint( 2*nSegments, 1, [ 1 : nSamples ], 'noreplace' ) )', 2, nSegments )';
0047 else
0048
0049 sMarkers = ones( nSegments, 2 );
0050 sMarkers( :, 2 ) = round( nSamples/2 );
0051 end
0052
0053
0054
0055
0056 fulldata = randn( nSamples, nChannels );
0057 if line
0058 f1 = 0.45; a1 = 0.20;
0059 f2 = 0.25; a2 = 0.15;
0060 for c=1:size(fulldata,2)
0061 mx = max(fulldata(:,c));
0062 fulldata(:,c) = fulldata(:,c) + a1*mx*sin( f1*2*pi*[1:size(fulldata,1)]') + a2*mx*sin( f2*2*pi*[1:size(fulldata,1)]') ;
0063 end
0064 end
0065
0066
0067
0068
0069 chIndices = sort( myrandint( ceil(nChannels/1.5), 1, [ 1 : nChannels ], 'noreplace' ) );
0070
0071
0072
0073
0074
0075 totalSegmentLength = sum( sMarkers(:,2) - sMarkers(:,1) + 1 );
0076 data = zeros( totalSegmentLength, length(chIndices) );
0077 newMarkers(1,1) = 1;
0078 newMarkers(1,2) = sMarkers(1,2) - sMarkers(1,1) + 1;
0079 data( newMarkers(1,1):newMarkers(1,2), : ) = fulldata( sMarkers(1,1):sMarkers(1,2), chIndices(:));
0080 for sg = 2:size( sMarkers, 1 )
0081 newMarkers(sg,1) = newMarkers(sg-1,2) + 1;
0082 newMarkers(sg,2) = newMarkers(sg,1) + sMarkers(sg,2) - sMarkers(sg,1);
0083 data( newMarkers(sg,1):newMarkers(sg,2), : ) = fulldata( sMarkers(sg,1):sMarkers(sg,2), chIndices(:));
0084 end
0085
0086
0087 if nChannels > 1
0088 ix = sort( myrandint( 1, 2, [1:length(chIndices)], 'noreplace' ) );
0089 i1=ix(1); i2=ix(2);
0090
0091 iC = ix(1) + (ix(2)-1)*(ix(2)-2)/2;
0092 else
0093 ix = sort( myrandint( 1, 1, [1:length(chIndices)], 'noreplace' ) );
0094 i1=ix(1);
0095 end
0096
0097
0098
0099
0100 if gram==0
0101 [ S, f, Serr ] = ueSpectrogram( data, movingwin, params, newMarkers );
0102 figure; plotvector( S(:,i1), f, 'l', squeeze(Serr(:,:,i1)) );
0103
0104 elseif gram==1
0105 [Cmn,Phimn,Smn,Smm,f,I,ConfC,PhiStd,Cerr] = ueCoherence( data, params, newMarkers );
0106
0107 figure; plot( f, 10*log10( Cmn(:,iC) ) ); title('Avg. Routine:: Coherence-Magnitude');
0108
0109 disp( ['Confidence levelfor C (confC) at (1-p) level: ' num2str( ConfC(iC)) ] );
0110 end
0111
0112
0113
0114
0115 if chronux
0116 cdata = repmat( fulldata( sMarkers(1,1):sMarkers(1,2), chIndices(i1) ), 1, nSegments );
0117 params.trialave = 1;
0118 if gram==0
0119 [ cS, cf, cSerr ] = mtspectrumc( cdata, params );
0120 figure; plot( cf, 10*log10( cS )); title('Chronux:: Spectrum');
0121 figure; plot( cf, 10*log10(cSerr(1,:)), cf, 10*log10(cSerr(2,:)) ); title('Chronux Error-Bar Computations');
0122 figure; plot( cf, 10*log10( cS ) - 10*log10( S(:,i1) )); title('Error in Spectrum = |New Routines - Chronux|');
0123 figure; plot( cf, 10*log10(cSerr(1,:)) - 10*log10(Serr(1,:,i1)), cf, 10*log10(cSerr(2,:)) - 10*log10(Serr(2,:,i1)) );title('Error in Error-Bar Computations = |New Routines - Chronux| ');
0124 elseif gram==1
0125 cdata2 = repmat( fulldata( sMarkers(1,1):sMarkers(1,2), chIndices(i2) ), 1, nSegments );
0126 params.trialave = 1;
0127
0128 [cC,cphi,cS12,cS1,cS2,cf,cconfC,cphistd,cCerr]=coherencyc( cdata, cdata2, params );
0129
0130 figure; plot( cf, 10*log10( cC(:,1) ) ); title('Chronux:: Coherence-Magnitude');
0131 figure; plot( cf, 10*log10( cC(:,1) ) - 10*log10( Cmn(:,iC) ) ); title('Error in Coherence = |New Routines - Chronux|');
0132
0133 figure; plot( cf, cphi(:,1) - Phimn(:,iC) ); title('Error in Phase = |New Routines - Chronux|');
0134
0135
0136
0137
0138 if 1
0139 figure; plot( cf, 10*log10( cS1(:,1) ) - 10*log10( Smm(:,ix(1)) ) ); title('Error in Power Spectrogram-1 = |New Routines - Chronux|');
0140 figure; plot( cf, 10*log10( cS2(:,1) ) - 10*log10( Smm(:,ix(2)) ) ); title('Error in Power Spectrogram-2 = |New Routines - Chronux|');
0141 end
0142
0143
0144 disp( ['Confidence levelfor C (confC) at (1-p) level: ' num2str( cconfC) ' (Chronux)' ] );
0145 disp( ['Error in confidence level, confC: ' num2str( ConfC(iC) - cconfC ) ] );
0146
0147 figure; plot( cf, cphistd(1,:,1) - PhiStd(1,:,iC) ); title('Error in PhiStd-1');
0148 figure; plot( cf, cphistd(2,:,1) - PhiStd(2,:,iC) ); title('Error in PhiStd-2');
0149 figure; plot( cf, abs(cCerr(1,:,1) - Cerr(1,:,iC)), cf, abs(cCerr(2,:,1) - Cerr(2,:,iC)) ); title('Error in Abs(Coherence)-Error-Bar Computations = |New Routines - Chronux|');
0150 end
0151 end
0152
0153
0154
0155
0156