Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int calcLenth(int length)//округление длинны массива до ближайшей степени 2ки.
- {
- int bit = 2;
- for (int i = 0; i < 30; i++)
- {
- bit *= 2;
- if ((bit == length) || (bit > length)) return bit;
- }
- return 0;
- }
- private double midleOfFrame(int pos, int framesize)
- {
- double res = 0;
- for (int i = pos; i <= pos + framesize; i++)
- {
- res += Math.Abs(Math.Sqrt(output[i].Real * output[i].Real + output[i].Imaginary * output[i].Imaginary));
- }
- res /= framesize;
- return res;
- }
- public double midleOfFrame(Complex[] input, int pos, int framesize)
- {
- double res = 0;
- for (int i = pos; i <= pos + framesize; i++)
- {
- res += Math.Sqrt(input[i].Real * input[i].Real + input[i].Imaginary * input[i].Imaginary);
- }
- res /= framesize;
- return res;
- }
- public double maxOfFrame(Complex[] input, int pos, int framesize)
- {
- double res = 0;
- for (int i = pos; i <= pos + framesize; i++)
- {
- res = Math.Sqrt(input[i].Real * input[i].Real + input[i].Imaginary * input[i].Imaginary) > res ? Math.Sqrt(input[i].Real * input[i].Real + input[i].Imaginary * input[i].Imaginary) : res;
- }
- return res;
- }
- private double maxOfArray(Double[] input)
- {
- double max = input[0];
- for (int i = 1; i < input.Count(); i++)
- max = input[i] > max ? input[i] : max;
- return max;
- }
- public double[] normalize(double[] input)
- {
- Double[] tmp = new Double[input.Count()];
- double k = 100 / maxOfArray(input);
- for (int i = 0; i < input.Count(); i++)
- tmp[i] = input[i] * k;
- return tmp;
- }
- private void AddDelimed(int start, int end)
- {
- int size = end - start;
- Complex[] tmp = new Complex[calcLenth(size)];
- for(int i = 0; i < size; i++)
- {
- tmp[i] = output[i + start];
- }
- delimed.Add(tmp, start);
- }
- private bool isSil(int pos)
- {
- const int framesize = 100;
- const double level = 0.01;
- return midleOfFrame(pos, framesize) < level;
- }
- private void delimBySil()
- {
- const int framesize = 500;
- int last = 0;
- bool mark = false;
- for (int i = 0; i < output.Length - framesize; i += framesize)
- {
- if(isSil(i))
- {
- if(mark)
- {
- AddDelimed(last, i);
- mark = false;
- }
- }
- else
- {
- if(!mark)
- {
- last = i;
- }
- mark = true;
- }
- }
- if(mark)
- {
- AddDelimed(last, output.Length - framesize);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement