%   MoveScads

%   This software is protected by german copyright and international treaties.             
%   Copyright 2004 Markus Junghöfer & Peter Peyk. All Rights Reserved.                     
%                                                                                          
%   THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE        
%   NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,    
%   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE    
%   OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
%   TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT,       
%   INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE      
%   OR DOCUMENTATION.  

FileMat=char('Rudi:Data:EEG:AlterPix:AP1Hz.fl20.at1.000')
FileMat=char(FileMat,'Rudi:Data:EEG:AlterPix:AP1Hz.fl20.at0.000');
m=240
f=1000./((250-m).*4)
%m=250-f/250
[NFiles,FileMat]=ReadFileNames(FileMat,'*.at*','Choose file:')

[File1,Path1,FilePath1]=GetFileNameOfMat(FileMat,1);
[AvgMat1,File1,Path1,FilePath1,NTrialAvgVec,StdChanTimeMat,SampRate,AvgRef,...
Version,MedMedRawVec,MedMedAvgVec,EegMegStatus,NChanExtra]=ReadAvgFile(FilePath1);
[NChan,NPoints]=size(AvgMat1)
AvgMat1=CalcBaseline(AvgMat1,1,NPoints);

[File2,Path2,FilePath2]=GetFileNameOfMat(FileMat,2);
[AvgMat2,File2,Path2,FilePath2,NTrialAvgVec,StdChanTimeMat,SampRate,AvgRef,...
Version,MedMedRawVec,MedMedAvgVec,EegMegStatus,NChanExtra]=ReadAvgFile(FilePath2);
AvgMat2=CalcBaseline(AvgMat2,1,NPoints);

AvgMat11=AvgMat1;
AvgMat11(:,1:m)=AvgMat11(:,1:m)+AvgMat1(:,NPoints-m+1:NPoints);
SaveAvgFile(['Rudi:Data:EEG:AlterPix:AP1Hz.fl20.at1.',int2str(m)],AvgMat11,NTrialAvgVec,StdChanTimeMat,SampRate,MedMedRawVec,MedMedAvgVec);

AvgMat00=AvgMat2;
AvgMat00(:,1:m)=AvgMat00(:,1:m)+AvgMat2(:,NPoints-m+1:NPoints);
SaveAvgFile(['Rudi:Data:EEG:AlterPix:AP1Hz.fl20.at0.',int2str(m)],AvgMat00,NTrialAvgVec,StdChanTimeMat,SampRate,MedMedRawVec,MedMedAvgVec);

SaveAvgFile(['Rudi:Data:EEG:AlterPix:AP1Hz.fl20.at1-0.',int2str(m)],AvgMat00-AvgMat11,NTrialAvgVec,StdChanTimeMat,SampRate,MedMedRawVec,MedMedAvgVec);
%SaveAvgFile(['Rudi:Data:EEG:AlterPix:AP1Hz.fl20.at1-0.000'],AvgMat2-AvgMat1,NTrialAvgVec,StdChanTimeMat,SampRate,MedMedRawVec,MedMedAvgVec);
