Beispiel #1
0
 public static Signal Modulate(Signal Baseband, Signal Carrier)
 {
     if (Baseband.Samples.Length != Carrier.Samples.Length)
     {
         throw new InvalidOperationException("baseband and carrier signal must have equal number of samples");
     }
     return Baseband * Carrier;
 }
Beispiel #2
0
 //
 //Operators
 //
 public static Signal operator *(Signal A, float x)
 {
     Signal tmp = new Signal(A.SamplingRate, A.Samples);
     for (int i = 0 ; i < tmp.Samples.Length ; i++)
     {
         tmp.Samples[i] = tmp.Samples[i] * x;
     }
     return tmp;
 }
Beispiel #3
0
 /// <summary>
 /// Calculates N-point frequency domain transform (Fast-Fourier Transform) of the given signal
 /// </summary>
 /// <param name="s">signal object</param>
 /// <param name="N">value of N for N-point FFT</param>
 /// <returns>Array of Complex[Re,Im] values</returns>
 public static Complex[] FFT(this OpenSignalLib.Sources.Signal s, int N = 1024)
 {
     float[] sig = new float[s.Samples.Length];
     for (int i = 0; i < s.Length; i++)
     {
         sig[i] = (float)s.Samples[i];
     }
     Complex[] fft = LiquidFFT.fft(sig, N);
     return(fft);
 }
Beispiel #4
0
 public static Signal operator *(Signal A, Array x)
 {
     Signal tmp = new Signal(A.SamplingRate, A.Samples);
     if (A.Samples.Length != x.Length)
     {
         throw new InvalidOperationException("Signal and Array must be of same length");
     }
     for (int i = 0 ; i < tmp.Samples.Length ; i++)
     {
         tmp.Samples[i] = tmp.Samples[i] * (double)x.GetValue(i);
     }
     return tmp;
 }
Beispiel #5
0
 public static Signal DeModulate(Signal PassBand, float carrier_frequency, float threshold = 0)
 {
     Signal ccarrier = new Sinusoidal(carrier_frequency, 0, -1, 1, PassBand.Samples.Length); // generate coherent carrier
     Signal demod = ccarrier * PassBand; // multiply the carrier and the passband signal
     var s = demod.Samples.Split((int)PassBand.SamplingRate);
     bool[] bits = new bool[s.Count()];
     int j = 0;
     foreach (var item in s)
     {
         var sm = item.Sum();
         bits[j] = sm > threshold;
         j++;
     }
     return new BinaryData(bits, demod.Samples.Length);
 }
Beispiel #6
0
 public static Signal BFSK_DeModulate(Signal passband, float f1, float f2, float threshold = 10)
 {
     Sinusoidal c = new Sinusoidal(f1, 0, passband.SamplingRate, 1, passband.Samples.Length);
     Signal demod = passband * c;
     var s = demod.Samples.Split((int)passband.SamplingRate);
     bool[] bits = new bool[s.Count()];
     int j = 0;
     foreach (var item in s)
     {
         var sm = item.Sum();
         bits[j] = sm > threshold;
         j++;
     }
     return new BinaryData(bits, demod.Samples.Length);
 }
Beispiel #7
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;
 }
Beispiel #8
0
 public static Signal Modulate(Signal Baseband, float CarrierFrequency, float CarrierAmplitude = 1)
 {
     Signal Carrier = new Sinusoidal(CarrierFrequency, 0, Baseband.SamplingRate, 1, Baseband.Samples.Length);
     return Baseband * Carrier;
 }
Beispiel #9
0
 public static Signal operator *(Signal A, Signal B)
 {
     if (A.Samples.Length != B.Samples.Length)
     {
         throw new InvalidOperationException("Both the operand signals must have equal number of samples");
     }
     if (A.SamplingRate != B.SamplingRate)
     {
         System.Diagnostics.Debug.Print("WARNING: Two signals with different sampling rates are being multiplied");
     }
     Signal temp = new Signal();
     temp.Samples = new double[A.Samples.Length];
     for (int i = 0 ; i < A.Samples.Length ; i++)
     {
         temp.Samples[i] = A.Samples[i] * B.Samples[i];
     }
     temp.SamplingRate = Math.Max(A.SamplingRate, B.SamplingRate);
     return temp;
 }
Beispiel #10
0
 public Signal Extend(Signal sig)
 {
     Signal x = new Signal();
     if (this.Samples == null) this.Samples = new double[0];
     x.Samples = this.Samples.Concat(sig.Samples).ToArray();
     if (this.SamplingRate == 0) this.SamplingRate = sig.SamplingRate;
     x.SamplingRate = this.SamplingRate;
     return x;
 }