private void parseDataRecordStream(StreamReader sr) { //set the seek position in the file stream to the beginning of the data records. sr.BaseStream.Seek((256 + this.Header.NumberOfSignalsInDataRecord * 256), SeekOrigin.Begin); int dataRecordSize = 0; foreach (EDFSignal signal in this.Header.Signals) { signal.SamplePeriodWithinDataRecord = this.Header.DurationOfDataRecordInSeconds / signal.NumberOfSamplesPerDataRecord; dataRecordSize += signal.NumberOfSamplesPerDataRecord; } byte[] dataRecordBytes = new byte[dataRecordSize * 2]; while (sr.BaseStream.Read(dataRecordBytes, 0, dataRecordSize * 2) > 0) { EDFDataRecord dataRecord = new EDFDataRecord(); int j = 0; int samplesWritten = 0; foreach (EDFSignal signal in this.Header.Signals) { List <float> samples = new List <float>(); for (int l = 0; l < signal.NumberOfSamplesPerDataRecord; l++) { float value = (float)(((BitConverter.ToInt16(dataRecordBytes, (samplesWritten * 2)) + (int)signal.Offset)) * signal.AmplifierGain); samples.Add(value); samplesWritten++; } dataRecord.Add(signal.IndexNumberWithLabel, samples); j++; } _dataRecords.Add(dataRecord); } }
/// <summary> /// 解析数据 /// </summary> /// <param name="sr"></param> private void parseDataRecordStream(StreamReader sr) { //set the seek position in the file stream to the beginning of the data records. sr.BaseStream.Seek((256 + this.Header.NumberOfSignalsInDataRecord * 256), SeekOrigin.Begin); int dataRecordSize = 0; foreach (EDFSignal signal in this.Header.Signals) { signal.SamplePeriodWithinDataRecord = (float)(this.Header.DurationOfDataRecordInSeconds / signal.NumberOfSamplesPerDataRecord); dataRecordSize += signal.NumberOfSamplesPerDataRecord; } byte[] dataRecordBytes = new byte[dataRecordSize * 2]; while (sr.BaseStream.Read(dataRecordBytes, 0, dataRecordSize * 2) > 0) { EDFDataRecord dataRecord = new EDFDataRecord(); int j = 0; int samplesWritten = 0; foreach (EDFSignal signal in this.Header.Signals) { float refVoltage = signal.PhysicalMaximum; List <float> samples = new List <float>(); for (int l = 0; l < signal.NumberOfSamplesPerDataRecord; l++) { // float value = (float)(((BitConverter.ToInt16(dataRecordBytes, (samplesWritten * 2)) + (int)signal.Offset)) * signal.AmplifierGain); float value = (float)BitConverter.ToInt16(dataRecordBytes, (samplesWritten * 2)); if (this.Header.Version.Equals(NEURO_BOND_FLAG)) { if (value >= 0 && value <= Math.Pow(2, 19) - 1) { value = refVoltage * value / (float)(Math.Pow(2, 19) - 1); } else { //value = refVoltage * ((value - (float)Math.Pow(2, 20)) / (float)(Math.Pow(2, 19) - 1)); value = refVoltage * value / (float)Math.Pow(2, 19); } } value /= multiplyingPower; samples.Add(value); samplesWritten++; } dataRecord.Add(signal.IndexNumberWithLabel, samples); j++; } _dataRecords.Add(dataRecord); } }