Ejemplo n.º 1
0
 public Sinusoidal(float frequency, float phase = 0, float SampleRate = -1, float amplitude = 1, int length = -1,
                   bool useParallelization      = true)
 {
     if (SampleRate == -1)
     {
         SampleRate = 30 * frequency;
     }
     if (length == -1)
     {
         length = (int)SampleRate;
     }
     this.SamplingRate = SampleRate;
     p.Amplitude       = amplitude;
     p.Frequency       = frequency;
     this.Frequency    = frequency;
     this.Amplitude    = amplitude;
     this.Phase        = phase;
     p.Phase           = phase;
     this._increment   = 1.0f / SampleRate;
     this.Samples      = new double[length];
     if (length > 5000 && useParallelization)
     {
         System.Threading.Tasks.Parallel.For(0, length, _calc);
     }
     else
     {
         float t = 0;
         for (int i = 0; i < length; i++)
         {
             this.Samples[i] = p.GetValue(t);
             t = i * _increment;
         }
     }
 }
Ejemplo n.º 2
0
        public SignalGenerator(SignalType Type, float frequency, float phase = 0,
                               float SampleRate = -1, float amplitude = 1, int length = -1)
        {
            if (SampleRate == -1)
            {
                SampleRate = 20 * frequency;
            }
            if (length == -1)
            {
                length = (int)SampleRate;
            }
            BaseSignalGenerator bs = new BaseSignalGenerator(Type);

            this.SamplingRate = SampleRate;
            bs.Amplitude      = amplitude;
            bs.Frequency      = frequency;
            bs.Phase          = phase;
            Samples           = new double[length];
            float t   = 0;
            float tmp = 1 / SampleRate;

            for (int i = 0; i < length; i++)
            {
                Samples[i] = bs.GetValue(t);
                t         += tmp;
            }
            this.Frequency = frequency;
            this.Amplitude = amplitude;
            this.Phase     = phase;
        }
Ejemplo n.º 3
0
 public Square(float frequency, float phase = 0, float SampleRate = - 1, float amplitude = 1, int length = -1)
 {
     if (SampleRate == -1) SampleRate = 20 * frequency;
     if (length == -1) length = (int)SampleRate;
     this.SamplingRate = SampleRate;
     BaseSignalGenerator s = new BaseSignalGenerator(SignalType.Square);
     Samples = new double[length];
     s.Frequency = frequency;
     s.Amplitude = amplitude;
     s.Phase = phase;
     float t = 0;
     float tmp = 1 / SampleRate;
     for (int i = 0 ; i < length ; i++)
     {
         Samples[i] = s.GetValue(t);
         t += tmp;
     }
 }
Ejemplo n.º 4
0
 public static Signal BFSK_Modulate(BinaryData baseband, float f1, float f2)
 {
     Signal modFSK = new Signal();
     float tmp = 1 / baseband.SamplingRate; //(30 * Math.Max(f1,f2));
     float t = 0;
     BaseSignalGenerator s = new BaseSignalGenerator(    SignalType.Sine);
     modFSK.Samples = new double[baseband.Samples.Length];
     modFSK.SamplingRate = baseband.SamplingRate;
     for (int i = 0 ; i < baseband.Samples.Length ; i++)
     {
         if (baseband.Samples[i] == 1)
         {
             s.Frequency = f1;
         }
         else
         {
             s.Frequency = f2;
         }
         modFSK.Samples[i] = s.GetValue(t);
         t += tmp;
     }
     return modFSK;
 }