123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace WpfTest1.Toolkits
- {
- class WaveSimulator
- {
- //产生模拟波形的方法
- //generate a signal combining from 0-5 hz
- //take amplitude and phase shift into account
- public static List<double> getSimulatedWave()
- {
- double Fs = 100; //Sampling frequency
- double T = 1.0 / Fs; //Sample time
- int L = 1500; //Length of signal
- List<double> t = new List<double>(); //Time vector
- for (int i = 0; i < L; ++i)
- {
- t.Add(i * T);
- //System.Console.WriteLine("t[i]:" + t[i].ToString());
- }
- List<double> f = new List<double>(); //frequency
- for (int i = 1; i < 6; ++i)
- {
- f.Add(i);
- }
- //phase
- //int pstep = 0;
- int count = f.Count();
- //phase = 0:pstep:count * pstep;
- List<double> phase = new List<double>();
- for(int i = 0; i < count; ++i)
- {
- phase.Add(0);
- }
- //phase(2) = 0 / 180;
- //phase(3) = 00 / 180;
- //phase(4) = 0 / 180;
- //phase(5) = 0 / 180;
- //amplitude
- List<double> amplitude = new List<double>();
- for (int i = 0; i < count; ++i)
- {
- amplitude.Add(1);
- }
- for(int i = 2 - 1; i <= count - 1; ++i)
- {
- amplitude[i] = 0.9 * amplitude[i - 1];
- }
- amplitude[2-1] = 0.8;
- amplitude[3-1] = 0.1;
- amplitude[4-1] = 0.1;
- amplitude[5-1] = 0.2;
- List<double> y = new List<double>();
- for (int i = 0; i < t.Count; ++i)
- {
- y.Add(0);
- }
- for(int j = 1 - 1; j <= t.Count - 1; ++j)
- {
- for(int i = 1 - 1; i <= count - 1; ++i)
- {
- y[j] = y[j] + amplitude[i] * Math.Sin(2 * Math.PI * f[i] * t[j] + phase[i]);
- //System.Console.WriteLine("y[i]:"+ y[i].ToString());
- }
- }
- for(int i = 0; i < y.Count; ++i)
- {
- y[i] = 1000 * y[i] + 2000;
- }
- return y;
- }
- }
- }
|