void ARThread::OnPreflight( const SignalProperties& Input, SignalProperties& Output ) const { if( Input.Elements() < Parameter( "ModelOrder" ) ) bcierr << "WindowLength parameter must be large enough" << " for the number of samples to exceed the model order" << endl; if( Parameter( "OutputType" ) == Coefficients ) { Output = Input; Output.SetName( "AR Coefficients" ); Output.SetElements( Parameter( "ModelOrder" ) ); Output.ElementUnit().SetSymbol( "" ) .SetOffset( 0 ) .SetGain( 1 ) .SetRawMin( 0 ) .SetRawMax( Output.Elements() - 1 ); } else { SpectrumThread::OnPreflight( Input, Output ); Output.SetName( "AR " + Output.Name() ); } }
void TSWFilter::Preflight( const SignalProperties& Input, SignalProperties& Output ) const { #if 0 if( Parameter( "YMean" ) != 0 ) bciout << "YMean should be set to zero for Slow Waves" << endl; if( Parameter( "YGain" ) < 300 || Parameter( "YGain" ) > 400 ) bciout << "YGain should be set to 327.68 for Slow Waves" << endl; #endif Parameter( "FeedbackEnd" ); State( itiStateName ); if( Parameter( "SWOutChList" )->NumValues() != Parameter( "SWInChList" )->NumValues() ) bcierr << "The number of entries in SWOutChList must match that in SWInChList" << endl; for( int i = 0; i < Parameter( "SWInChList" )->NumValues(); ++i ) PreflightCondition( Parameter( "SWInChList" )( i ) > 0 && Parameter( "SWInChList" )( i ) <= Input.Channels() ); for( int i = 0; i < Parameter( "SWOutChList" )->NumValues(); ++i ) PreflightCondition( Parameter( "SWOutChList" )( i ) > 0 && Parameter( "SWOutChList" )( i ) <= Input.Channels() ); PreflightCondition( Parameter( "Tc" ).InSampleBlocks() >= 0.0 ); PreflightCondition( Parameter( "SpatialFilteredChannels" ) == Input.Channels() ); Output = SignalProperties( Input.Channels(), 1 ); Output.SetName( "SWFiltered" ); }
void FFTFilter::DetermineSignalProperties( SignalProperties& ioProperties, int inFFTType ) const { int numChannels = Parameter( "FFTInputChannels" )->NumValues(), fftWindowLength = static_cast<int>( ioProperties.Elements() * Parameter( "FFTWindowLength" ).InSampleBlocks() ); if( numChannels > 0 && fftWindowLength == 0 ) bcierr << "FFTWindowLength must exceed a single sample's duration" << endl; double freqRange = ioProperties.SamplingRate() / 2.0; switch( inFFTType ) { case eInput: break; case ePower: { ioProperties.SetName( "FFT Power Spectrum" ) .SetChannels( numChannels ) .SetElements( fftWindowLength / 2 + 1 ); ioProperties.ElementUnit().SetOffset( 0.0 ) .SetGain( freqRange / ( ioProperties.Elements() - 1 ) ) .SetSymbol( "Hz" ); double amplitude = ioProperties.ValueUnit().RawMax() - ioProperties.ValueUnit().RawMin(); ioProperties.ValueUnit().SetRawMin( 0 ) .SetRawMax( amplitude * amplitude ); ioProperties.ElementUnit().SetRawMin( 0 ) .SetRawMax( ioProperties.Elements() - 1 ); } break; case eHalfcomplex: ioProperties.SetName( "FFT Coefficients" ) .SetChannels( numChannels ) .SetElements( fftWindowLength ); ioProperties.ElementUnit().SetRawMin( 0 ) .SetRawMax( fftWindowLength - 1 ) .SetOffset( 0 ) .SetGain( 1 ) .SetSymbol( "" ); break; default: throw std_logic_error( "Unknown value of FFT type" ); } }
void TFBArteCorrection::Preflight( const SignalProperties& inSignalProperties, SignalProperties& outSignalProperties ) const { for( int i = 0; i < Parameter( "ArteChList" )->NumValues(); ++i ) { PreflightCondition( Parameter( "ArteChList" )( i ) >= 0 ); PreflightCondition( Parameter( "ArteChList" )( i ) <= inSignalProperties.Channels() ); } outSignalProperties = inSignalProperties; outSignalProperties.SetName( "Artifact Filtered" ); }
void FFTFilter::DetermineSignalProperties( SignalProperties& ioProperties, int inFFTType ) const { int numChannels = Parameter( "FFTInputChannels" )->NumValues(), fftWindowLength = Parameter( "SampleBlockSize" ) * MeasurementUnits::ReadAsTime( Parameter( "FFTWindowLength" ) ); if( numChannels > 0 && fftWindowLength == 0 ) bcierr << "FFTWindowLength must exceed a single sample's duration" << endl; switch( inFFTType ) { case eInput: break; case ePower: { ioProperties.SetName( "FFT Power Spectrum" ) .SetChannels( numChannels ) .SetElements( fftWindowLength / 2 + 1 ); float freqScale = Parameter( "SamplingRate" ) / 2.0 / ioProperties.Elements(); ioProperties.ElementUnit().SetOffset( freqScale / 2 ) .SetGain( freqScale ) .SetSymbol( "Hz" ); float amplitude = ioProperties.ValueUnit().RawMax() - ioProperties.ValueUnit().RawMin(); ioProperties.ValueUnit().SetRawMin( 0 ) .SetRawMax( amplitude * amplitude ); } break; case eHalfcomplex: ioProperties.SetName( "FFT Coefficients" ) .SetChannels( numChannels ) .SetElements( fftWindowLength ); break; default: assert( false ); } }
void ARFilter::Preflight( const SignalProperties& Input, SignalProperties& Output ) const { // Parameter consistency checks. float windowLength = MeasurementUnits::ReadAsTime( Parameter( "WindowLength" ) ); int samplesInWindow = windowLength * Parameter( "SampleBlockSize" ); if( samplesInWindow < Parameter( "ModelOrder" ) ) bcierr << "WindowLength parameter must be large enough" << " for the number of samples to exceed the model order" << endl; Output = Input; switch( int( Parameter( "OutputType" ) ) ) { case SpectralAmplitude: case SpectralPower: { float firstBinCenter = MeasurementUnits::ReadAsFreq( Parameter( "FirstBinCenter" ) ), lastBinCenter = MeasurementUnits::ReadAsFreq( Parameter( "LastBinCenter" ) ), binWidth = MeasurementUnits::ReadAsFreq( Parameter( "BinWidth" ) ); if( firstBinCenter > 0.5 || firstBinCenter < 0 || lastBinCenter > 0.5 || lastBinCenter < 0 ) bcierr << "FirstBinCenter and LastBinCenter must be greater zero and" << " less than half the sampling rate" << endl; if( firstBinCenter >= lastBinCenter ) bcierr << "FirstBinCenter must be less than LastBinCenter" << endl; if( binWidth <= 0 ) bcierr << "BinWidth must be greater zero" << endl; else { int numBins = ::floor( ( lastBinCenter - firstBinCenter + eps ) / binWidth + 1 ); Output.SetElements( numBins ); } Output.ElementUnit().SetOffset( firstBinCenter / binWidth ) .SetGain( binWidth * Parameter( "SamplingRate" ) ) .SetSymbol( "Hz" ); Output.ValueUnit().SetRawMin( 0 ); float inputAmplitude = Input.ValueUnit().RawMax() - Input.ValueUnit().RawMin(), whiteNoisePowerPerBin = inputAmplitude * inputAmplitude / binWidth / 10; switch( int( Parameter( "OutputType" ) ) ) { case SpectralAmplitude: Output.SetName( "AR Amplitude Spectrum" ); Output.ValueUnit().SetOffset( 0 ) .SetGain( 1e-6 ) .SetSymbol( "V/sqrt(Hz)" ) .SetRawMax( ::sqrt( whiteNoisePowerPerBin ) ); break; case SpectralPower: { Output.SetName( "AR Power Spectrum" ); Output.ValueUnit().SetOffset( 0 ) .SetGain( 1 ) .SetSymbol( "(muV)^2/Hz" ) .SetRawMax( whiteNoisePowerPerBin ); } break; } } break; case ARCoefficients: Output.SetName( "AR Coefficients" ); Output.SetElements( Parameter( "ModelOrder" ) ); Output.ElementUnit().SetOffset( 0 ) .SetGain( 1 ) .SetSymbol( "" ); Output.ValueUnit().SetOffset( 0 ) .SetGain( 1 ) .SetSymbol( "" ) .SetRawMin( -1 ) .SetRawMax( 1 ); break; default: bcierr << "Unknown OutputType" << endl; } Output.ElementUnit().SetRawMin( 0 ) .SetRawMax( Output.Elements() - 1 ); }