function lineamp_detcamp(varargin) % LINEAMP_DETCAMP - run lineamp in batch mode for Detector Camp % syntax: lineamp_detcamp(T0,Dur[,frameType]) % T0 - start time (GPS seconds) % Dur - duration (seconds) % frameType [OPTIONAL] Frame type (default is RDS_R_L3) % % ## This version hard-coded to the following % Channel - ADC Channel to process - 'H1:LSC-AS_Q' % f - line frequencies [41.25 151.3 973.3] % NSec - # seconds per segment - 15 % % Saves outputs to MAT file 'Line-H1--.mat' % a line amplitude. Rows correspond to line frequencies. % phi line phase. Rows correspond to line frequencies. % t time stamps for the beginning of the averaging segment % fs sample rate % % Creates plot file 'Line-H1--.eps' % IF wrong number of inputs % CREATE error message % EXIT % ENDIF % GET start time from inputs % IF input is a character string (i.e. command-line input) % SET start time = number converted from string % ELSE (i.e. called from another function) % SET start time = input number % ENDIF % GET duration from inputs % IF frameType was input % SET frame type from input % ELSE % SET frame Type to default % ENDIF % SET hard-coded parameters % SET # segments = Duration / (seconds/seg) errMsg = nargchk(2,3,nargin); if(~isempty(errMsg)) error('Syntax is lineamp_detcamp(T0,Dur[,frameType])'); end inputT0 = varargin{1}; if(ischar(inputT0)) T0 = str2num(inputT0); else T0 = inputT0; end inputDur = varargin{2}; if(ischar(inputDur)) Dur = str2num(inputDur); else Dur = inputDur; end if(nargin > 2) frameType = char(varargin{3}); else frameType = 'RDS_R_L3'; end Channel = 'H1:LSC-AS_Q'; f = [41.25 151.3 973.3]; NSec = 15; NSeg = floor(Dur / NSec); % CREATE arrays for results % CREATE vector of start times for each segment % CREATE channel structure % SET channel structure for correct frame type a = zeros([length(f),NSeg]); phi = a; t = T0 + (0:(NSeg-1))*NSec; dataStruct = chanstruct(Channel); dataStruct.type = frameType; % LOOP over segments % GET time-series data for segment % CREATE Hanning window to cover segment % IF first segment % INITIALIZE local oscillators % SET phase = 0 % ENDIF % LOOP over line frequencies % CREATE local oscillator % CREATE phasor for segment and line frequency % ENDLOOP % ENDLOOP f = f(:); nFreq = length(f); for j = 1:NSeg GPS = t(j); fprintf('Segment %d - GPS %d for %d sec\n',j,GPS,NSec); [data,fs,errCode] = chanvector(dataStruct, GPS, NSec); segLength = length(data); if (1 == j) k0 = 0:(fs*NSec-1); k0 = f(:)*k0/fs; k0 = exp(2*pi*i*k0); end if(segLength > 0) window = hann(segLength); for l = 1:nFreq k = k0(l,:)*exp(2*pi*i*GPS*f(l)); data = data(:) .* window; z(l,j) = sum(k(:).*data); end end end % SCALE the integral % GET amplitudes of integral % GET phases of integral z=z*2/(fs*NSec); a = abs(z); phi = angle(z); % CREATE x-axis scale % CREATE legend text % CREATE Amplitude plot xl = sprintf('Time (s) from GPS %d',T0); tt = zeros([length(f),length(t)]); lgnd = cell([1,length(f)]); for k = 1:length(f) tt(k,:) = t; lgnd{k} = sprintf('%8.2f Hz',f(k)); end tt = tt - T0 + NSec/2; subplot(2,1,1); semilogy(tt',a'); grid; xlabel(xl); ylabel('Amplitude (counts)'); legend(lgnd); title(sprintf('%s %ds from %d',Channel(1:3),Dur,T0)); % CREATE Phase plot % SET Legend on plot % SET Title on plot % CREATE plot file name % SAVE plot to file hold on; subplot(2,1,2); plot(tt',phi'); xlabel(xl); ylabel('Phase (radians)'); legend(lgnd); plotFile = sprintf('Line-%s-%d-%d',Channel(1:2),T0,Dur); print(gcf,'-depsc2',plotFile); % save MATLAB results to file ff = f; clear data; clear window; clear k0; matFile = sprintf('Line-%s-%d-%d-results',Channel(1:2),T0,Dur); save(matFile); return