Ejemplo n.º 1
0
        private List <double> fIRFilter(List <double> Xn, int filter_type, double fc1, double fc2, double t_width, double stop_attenuation, double fs)
        {
            List <double> res = new List <double>();
            List <double> Hd = new List <double>();
            List <double> Wn = new List <double>();
            List <double> Hn = new List <double>();
            int           N = 0, fullSize = 0;

            Wn = calculatWindowFunction(stop_attenuation, t_width, ref N, ref fullSize);
            Hd = calculateFilterFunction(filter_type, fc1, fc2, fs, t_width, N);
            for (int i = 0; i <= N; i++)
            {
                Hn.Add(Hd[i] * Wn[i]);
            }

            //int j = N - 1;
            //for (int i = N + 1; i < fullSize; i++)
            //{
            //    Hn.Add(Hn[j]);
            //    j--;
            //}
            ConvolutionAndCorrelation obj = new ConvolutionAndCorrelation();
            string p = "D:\\My Collage's Stages\\Fourth Year\\Second Semester\\Signal Processing\\Labs\\The Package\\Results\\FIR\\CoffOfFIR.txt";

            obj.SaveInFile(p, Hn);


            ConvolutionAndCorrelation c = new ConvolutionAndCorrelation();

            res = c.Convolution(Xn, Hn);

            p = "D:\\My Collage's Stages\\Fourth Year\\Second Semester\\Signal Processing\\Labs\\The Package\\Results\\FIR\\AfterConvolution.txt";
            obj.SaveInFile(p, Hn);
            return(res);
        }
Ejemplo n.º 2
0
        private void btnDone_Click(object sender, EventArgs e)
        {
            filterType  = comboBox1.SelectedIndex;
            cutOffFreq1 = double.Parse(txtboxFC1.Text);
            if (filterType == 2 || filterType == 3)
            {
                cutOffFreq2 = double.Parse(txtBoxFC2.Text);
            }
            transitionWidth = double.Parse(txtBoxTransitionWidth.Text);
            stopbandAtten   = double.Parse(txtBoxStopbandAttenuation.Text);
            samplingFreq    = double.Parse(txtBoxSamplingFrequency.Text);
            transitionWidth = transitionWidth / samplingFreq; //DeltaF

            if (rbuttonDownSampling.Checked)
            {
                m                  = int.Parse(txtBoxDownSampling.Text);
                result             = fIRFilter(signal, filterType, cutOffFreq1, cutOffFreq2, transitionWidth, stopbandAtten, samplingFreq);
                downSamplingResult = downSampling(result, m);
                finalResult        = downSamplingResult;
            }
            else if (rbuttonUpSampling.Checked)
            {
                l = int.Parse(txtBoxUpSampling.Text);
                upSamplingResult = upSampling(signal, l);

                result      = fIRFilter(upSamplingResult, filterType, cutOffFreq1, cutOffFreq2, transitionWidth, stopbandAtten, samplingFreq);
                finalResult = result;
            }
            else if (rbuttonUpDownSampling.Checked)
            {
                m = int.Parse(txt2DownSampling.Text);
                l = int.Parse(txt1UpSampling.Text);
                upSamplingResult   = upSampling(signal, l);
                result             = fIRFilter(upSamplingResult, filterType, cutOffFreq1, cutOffFreq2, transitionWidth, stopbandAtten, samplingFreq);
                downSamplingResult = downSampling(result, m);
                finalResult        = downSamplingResult;
            }
            else
            {
                result      = fIRFilter(signal, filterType, cutOffFreq1, cutOffFreq2, transitionWidth, stopbandAtten, samplingFreq);
                finalResult = result;
            }

            ConvolutionAndCorrelation obj = new ConvolutionAndCorrelation();
            string p = "D:\\My Collage's Stages\\Fourth Year\\Second Semester\\Signal Processing\\Labs\\The Package\\Results\\FIR\\resultOfFIR.txt";

            obj.SaveInFile(p, finalResult);
            MessageBox.Show("the filter have done and the file is saved successfully :D", "Done", MessageBoxButtons.OK);
        }
Ejemplo n.º 3
0
        private List <double> upSampling(List <double> list, int factor)
        {
            List <double> sampled = new List <double>();

            for (int i = 0; i < list.Count; i++)
            {
                sampled.Add(list[i]);
                for (int j = 0; j < (factor - 1); j++)
                {
                    sampled.Add(0);
                }
            }
            ConvolutionAndCorrelation obj = new ConvolutionAndCorrelation();
            string p = "D:\\My Collage's Stages\\Fourth Year\\Second Semester\\Signal Processing\\Labs\\The Package\\Results\\FIR\\UpsampledData.txt";

            obj.SaveInFile(p, sampled);

            return(sampled);
        }
Ejemplo n.º 4
0
        private void btnCovolution_Click(object sender, EventArgs e)
        {
            ConvolutionAndCorrelation c = new ConvolutionAndCorrelation();

            c.Show();
        }