Exemplo n.º 1
0
        DFMSignal LoadSignalFromFile(string path)
        {
            string[] lines = File.ReadAllLines(path);
            if (!lines[0].ToLower().StartsWith("signal "))
            {
                throw new FileFormatException("File is not formatted as a signal file");
            }
            string[] namelines = lines[0].Split(' ');
            string   name      = namelines[1];

            string[]   nums         = lines[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            List <int> totalnumbers = new List <int>();

            if (nums[0].StartsWith("*"))
            {
                int repetitions = int.Parse(nums[0].Substring(1));
                var numbers     = nums.Skip(1).Select(x => int.Parse(x));
                for (int i = 0; i < repetitions; i++)
                {
                    totalnumbers.AddRange(numbers);
                }
            }
            else
            {
                var numbers = nums.Select(x => int.Parse(x));
                totalnumbers.AddRange(numbers);
            }
            DFMSignal signal = new DFMSignal(name, totalnumbers.ToArray());

            return(signal);
        }
Exemplo n.º 2
0
 void SaveSignal(DFMSignal signal)
 {
     string[] lines = new string[2];
     lines[0] = "Signal " + signal.Name;
     lines[1] = signal.ValuesString;
     File.WriteAllLines(SignalDir + @"\" + signal.Name, lines);
 }
Exemplo n.º 3
0
 public Controller()
 {
     curFilter = DFMFilter.delayFilter;
     curSignal = 2 * DFMSignal.PeriodicSignal2 + DFMSignal.PeriodicSignal3;
     maxLength = 8;
     Reload();
 }
Exemplo n.º 4
0
        public void LoadSignal(string path, Controller controller)
        {
            DFMSignal signal = LoadSignalFromFile(path);

            SaveSignal(signal);
            GetSavedSignals();
            controller.CurSignal = signal;
        }
Exemplo n.º 5
0
 static DFMSignal()
 {
     ImpulseSignal   = new DFMSignal("Impulse", 5);
     ConstantSignal  = new DFMSignal("Constant", 5, 5, 5, 5, 5);
     VariableSignal  = new DFMSignal("Variable", 4, 0, -4, 4, 4, 0, -4, -4);
     PeriodicSignal2 = new DFMSignal("Periodic2", 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4);
     PeriodicSignal3 = new DFMSignal("Periodic3", 4, 0, -4, 4, 0, -4, 4, 0, -4, 4, 0, -4, 4, 0, -4, 4, 0, -4);
 }
Exemplo n.º 6
0
        public DFMSignal RightShift(int steps)
        {
            DFMSignal res = new DFMSignal();

            for (int i = 0; i < Length() + steps; i++)
            {
                res[i] = this[i - steps];
            }
            return(res);
        }
Exemplo n.º 7
0
        public static DFMSignal operator *(double x, DFMSignal signal)
        {
            DFMSignal res = new DFMSignal();

            for (int i = 0; i < signal.Length(); i++)
            {
                res[i] = (int)(signal[i] * x);
            }
            return(res);
        }
Exemplo n.º 8
0
        public DFMSignal GenerateOutput(DFMSignal input, int stepsNumber)
        {
            DFMSignal output = new DFMSignal();

            for (int i = 0; i < stepsNumber; i++)
            {
                OutputStep(input, output, i);
            }
            return(output);
        }
Exemplo n.º 9
0
        public static DFMSignal operator +(DFMSignal sig1, DFMSignal sig2)
        {
            DFMSignal res       = new DFMSignal();
            int       maxlength = sig1.Length() > sig2.Length() ? sig1.Length() : sig2.Length();

            for (int i = 0; i < maxlength; i++)
            {
                res[i] = sig1[i] + sig2[i];
            }
            return(res);
        }
Exemplo n.º 10
0
        public double MultiplyBySignal(DFMSignal signal, int signalpos, bool IgnoreFirst = false)
        {
            double res      = 0;
            int    startInd = IgnoreFirst ? 1 : 0;

            for (int i = startInd; i < coefs.Length; i++)
            {
                res += signal[signalpos - i] * coefs[i];
            }
            return(res);
        }
Exemplo n.º 11
0
        public bool IsEqual(DFMSignal signal, int maxCompareLength = -1)
        {
            int maxlength = maxCompareLength == -1
                ? signal.Length() > Length() ? signal.Length() : Length()
                : maxCompareLength;

            for (int i = 0; i < maxlength; i++)
            {
                if (this[i] != signal[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 12
0
        void OutputStep(DFMSignal input, DFMSignal output, int stepnum)
        {
            double res = upper.MultiplyBySignal(input, stepnum) - lower.MultiplyBySignal(output, stepnum, true);

            output[stepnum] = (int)(res / lower[0]);
        }