Ejemplo n.º 1
0
        public static float[] GetWaveFromFile(AnalogChannel channel, uint waveLength, double samplePeriod, double timeOffset)
        {
            if (readChannel == null || readTime == null)
            {
                String     filename    = Path.GetTempFileName();
                FileStream f           = new FileStream(filename, FileMode.Create, FileAccess.Write);
                byte[]     i2cSequence = Resources.Load("i2c_sequence.mat");
                f.Write(i2cSequence, 0, i2cSequence.Length);
                f.Close();

                MatfileReader matfileReader = new MatlabFileIO.MatfileReader(filename);
                readChannel = new Dictionary <AnalogChannel, float[]>()
                {
                    { AnalogChannel.ChA, Utils.CastArray <double, float>(matfileReader.Variables["chA"].data as double[]) },
                    { AnalogChannel.ChB, Utils.CastArray <double, float>(matfileReader.Variables["chB"].data as double[]) },
                };
                readTime             = matfileReader.Variables["time"].data as double[];
                samplePeriodOriginal = readTime[1] - readTime[0];
                sequenceLength       = readChannel[AnalogChannel.ChA].Length;
                matfileReader.Close();
            }

            if (samplePeriod / samplePeriodOriginal % 1.0 != 0.0)
            {
                throw new Exception("Data from file doesn't suit the dummy scope sampling frequency");
            }

            uint decimation = (uint)Math.Ceiling(samplePeriod / samplePeriodOriginal);

            float[] wave = Utils.DecimateArray(readChannel[channel], decimation);

            int sampleOffset = (int)Math.Ceiling(timeOffset / samplePeriodOriginal % sequenceLength);

            int requiredRepetitions = (int)Math.Ceiling(waveLength / (double)wave.Length);

            if (requiredRepetitions > 1)
            {
                List <float> concat = new List <float>();
                for (int i = 0; i < requiredRepetitions; i++)
                {
                    concat.AddRange(wave);
                }
                wave = concat.Take((int)waveLength).ToArray();
            }
            return(wave);
        }
Ejemplo n.º 2
0
        public static float[] GetWaveFromFile(AnalogChannel channel, uint waveLength, double samplePeriod, double timeOffset)
        {
            if(readChannel == null || readTime == null)
            {
                String filename = Path.GetTempFileName();
                FileStream f = new FileStream(filename, FileMode.Create, FileAccess.Write);
                byte[] i2cSequence = Resources.Load ("i2c_sequence.mat");
                f.Write(i2cSequence, 0, i2cSequence.Length);
                f.Close();

                MatfileReader matfileReader = new MatlabFileIO.MatfileReader(filename);
                readChannel = new Dictionary<AnalogChannel, float[]>() {
                    { AnalogChannel.ChA, Utils.CastArray<double, float>(matfileReader.Variables["chA"].data as double[]) },
                    { AnalogChannel.ChB, Utils.CastArray<double, float>(matfileReader.Variables["chB"].data as double[]) },
                };
                readTime = matfileReader.Variables["time"].data as double[];
                samplePeriodOriginal = readTime[1] - readTime[0];
                sequenceLength = readChannel[AnalogChannel.ChA].Length;
                matfileReader.Close();
            }

            if (samplePeriod / samplePeriodOriginal % 1.0 != 0.0)
                throw new Exception("Data from file doesn't suit the dummy scope sampling frequency");

            uint decimation = (uint)Math.Ceiling(samplePeriod / samplePeriodOriginal);
            float[] wave = Utils.DecimateArray(readChannel[channel], decimation);

            int sampleOffset = (int)Math.Ceiling(timeOffset / samplePeriodOriginal % sequenceLength);

            int requiredRepetitions = (int)Math.Ceiling(waveLength / (double)wave.Length);
            if (requiredRepetitions > 1)
            {
                List<float> concat = new List<float>();
                for(int i = 0; i < requiredRepetitions; i++)
                    concat.AddRange(wave);
                wave = concat.Take((int)waveLength).ToArray();
            }
            return wave;
        }
Ejemplo n.º 3
0
        private void LoadDataFromFile(string filename)
        {
            MatfileReader matfileReader = new MatlabFileIO.MatfileReader(filename);

            if (!matfileReader.Variables.ContainsKey("SamplePeriodInSeconds"))
            {
                throw new Exception(".mat file not compatible");
            }

            //load data
            dataChA      = LoadAnalogChannelFromMatlabFile <float>("ChannelA", matfileReader);
            dataChB      = LoadAnalogChannelFromMatlabFile <float>("ChannelB", matfileReader);
            dataLA       = LoadAnalogChannelFromMatlabFile <byte>("ChannelLA", matfileReader);
            SamplePeriod = (double)matfileReader.Variables["SamplePeriodInSeconds"].data;

            //calc fixed values
            if (dataChA != null)
            {
                NrSamples   = dataChA[0].Length;
                NrWaveforms = dataChA.Count;
            }
            else
            {
                NrSamples   = dataLA[0].Length;
                NrWaveforms = dataLA.Count;
            }

            if (NrWaveforms > 0)
            {
                this.AcquisitionLenght = SamplePeriod * (double)NrSamples;
            }
            else
            {
                this.AcquisitionLenght = 0;
            }
        }