示例#1
0
文件: stage.go 项目: GeoNet/delta
func (s Stage) fir(f resp.FIR) stationxml.ResponseStage {

	var coeffs []stationxml.NumeratorCoefficient
	for j, c := range f.Factors {
		coeffs = append(coeffs, stationxml.NumeratorCoefficient{
			Coefficient: int32(j + 1),
			Value:       c,
		})
	}

	fir := stationxml.FIR{
		BaseFilter: stationxml.BaseFilter{
			ResourceId:  "FIR#" + s.id,
			Name:        s.responseStage.Lookup,
			InputUnits:  stationxml.Units{Name: s.responseStage.InputUnits},
			OutputUnits: stationxml.Units{Name: s.responseStage.OutputUnits},
		},
		Symmetry: stationxml.Symmetry(f.Symmetry),
		/*
			func() stationxml.Symmetry {
				switch strings.ToUpper(f.Symmetry) {
				case "EVEN":
					return stationxml.SymmetryEven
				case "ODD":
					return stationxml.SymmetryOdd
				default:
					return stationxml.SymmetryNone
				}
			}(),
		*/
		NumeratorCoefficients: coeffs,
	}

	return stationxml.ResponseStage{
		Number: stationxml.Counter(uint32(s.count)),
		FIR:    &fir,
		//TODO: check we may need to adjust gain for different frequency
		StageGain: stationxml.Gain{
			Value: func() float64 {
				if s.responseStage.Gain != 0.0 {
					return s.responseStage.Gain
				}
				return 1.0
			}(),
			//Frequency: stage.Frequency,
			Frequency: s.frequency,
		},
		Decimation: &stationxml.Decimation{
			InputSampleRate: stationxml.Frequency{stationxml.Float{Value: f.Decimation * s.responseStage.SampleRate}},
			Factor: func() int32 {
				if s.responseStage.Decimate != 0 {
					return s.responseStage.Decimate
				}
				return int32(f.Decimation)
			}(),
			Delay:      stationxml.Float{Value: s.responseStage.Delay},
			Correction: stationxml.Float{Value: s.responseStage.Correction},
		},
	}
}
示例#2
0
文件: response.go 项目: GeoNet/delta
func firResponseStage(filter resp.FIR, stage Stage) stationxml.ResponseStage {
	var coeffs []stationxml.NumeratorCoefficient
	for j, c := range filter.Factors {
		coeffs = append(coeffs, stationxml.NumeratorCoefficient{
			Coefficient: int32(j + 1),
			Value:       c,
		})
	}

	fir := stationxml.FIR{
		BaseFilter: stationxml.BaseFilter{
			ResourceId:  "FIR#" + stage.id,
			Name:        filter.Name,
			InputUnits:  stationxml.Units{Name: stage.responseStage.InputUnits},
			OutputUnits: stationxml.Units{Name: stage.responseStage.OutputUnits},
		},
		Symmetry:              stationxml.Symmetry(filter.Symmetry),
		NumeratorCoefficients: coeffs,
	}

	return stationxml.ResponseStage{
		Number: stationxml.Counter(uint32(stage.count)),
		FIR:    &fir,
		//TODO: check we may need to adjust gain for different frequency
		StageGain: stationxml.Gain{
			Value: func() float64 {
				if stage.responseStage.Gain != 0.0 {
					return stage.responseStage.Gain
				}
				return 1.0
			}(),
			Frequency: stage.frequency,
		},
		Decimation: &stationxml.Decimation{
			InputSampleRate: stationxml.Frequency{stationxml.Float{Value: filter.Decimation * stage.responseStage.SampleRate}},
			Factor: func() int32 {
				if stage.responseStage.Decimate != 0 {
					return stage.responseStage.Decimate
				}
				return int32(filter.Decimation)
			}(),
			Delay:      stationxml.Float{Value: stage.responseStage.Delay},
			Correction: stationxml.Float{Value: stage.responseStage.Correction},
		},
	}
}