Blockquote 我生成了2个正弦波,并将其分成2个数组。我汇总第一个指标 数组与第二个数组的每个索引并获得第三个数组(总信号) 之后,我想从totalsignal第二个数组中筛选出第一个数组。 但是结果上的正弦图看起来不一样。 该行的开头是平坦的,幅度为300(在原始正弦图中,幅度为10)。 graph after filter >
public Form1()
{
InitializeComponent();
plot();
}
public void plot()
{
string TestName = "chart name";
string field = "Amplitude";
string x_axis = "Time";
string xTitle = "Time [Sec]";
string yTitle = "Amplitude";
Color[] colors = new Color[] { Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Brown };
bool show_graph_as_line = true;
int freq1 = 10;
int freq2 = 50;
int amplitude1 = 10;
int amplitude2 = 20;
//samples per second
int sampleRate = 10000;
double[] totalSignal;
int idx = 0;
//size of arrays
int size = 10000;
double[] signal_1_xAxis = new double[size];
double[] signal_2_xAxis = new double[size];
double[] signal_1_yAxis = new double[size];
double[] signal_2_yAxis = new double[size];
signal_1_yAxis = GenerateSineWave(freq1, amplitude1, sampleRate, size);
signal_2_yAxis = GenerateSineWave(freq2, amplitude2, sampleRate, size);
double dt = 1.0 / sampleRate;
for (int i = 1; i < size; i++)
{
signal_1_xAxis[i] = i * dt;
signal_2_xAxis[i] = i * dt;
}
totalSignal = SumOfSignals(signal_1_yAxis, signal_2_yAxis);
MathNet.Filtering.OnlineFilter bandPass = MathNet.Filtering.OnlineFilter.CreateLowpass(MathNet.Filtering.ImpulseResponse.Finite, sampleRate, 15);
var Result = bandPass.ProcessSamples(totalSignal);
}
public static double[] GenerateSineWave(
double frequency,
double amplitude,
double sampleRate,
double samplesPerBuffer)
{
double deltaT = 1 / sampleRate; // sec./samp
int intSamplesPerBuffer = (int)samplesPerBuffer;
double[] rVal = new double[intSamplesPerBuffer];
for (int i = 0; i < intSamplesPerBuffer; i++)
rVal[i] = amplitude * Math.Sin((2.0 * Math.PI) * frequency * (i * deltaT));
return rVal;
}
public double[] SumOfSignals(double[] signal_1, double[] signal_2)
{
double[] sumSig = new double[10000];
for (int i = 0; i < signal_1.Length; i++)
{
sumSig[i] = signal_1[i] + signal_2[i];
}
return sumSig;
}
}
}
[1]: https://i.stack.imgur.com/Pbktt.jpg