File indexing completed on 2024-04-28 15:14:11

0001 /***************************************************************************
0002     File                 : NSLFilterTest.cpp
0003     Project              : LabPlot
0004     Description          : NSL Tests for filter
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2019 Stefan Gerlach (stefan.gerlach@uni.kn)
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *  This program is free software; you can redistribute it and/or modify   *
0012  *  it under the terms of the GNU General Public License as published by   *
0013  *  the Free Software Foundation; either version 2 of the License, or      *
0014  *  (at your option) any later version.                                    *
0015  *                                                                         *
0016  *  This program is distributed in the hope that it will be useful,        *
0017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0019  *  GNU General Public License for more details.                           *
0020  *                                                                         *
0021  *   You should have received a copy of the GNU General Public License     *
0022  *   along with this program; if not, write to the Free Software           *
0023  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0024  *   Boston, MA  02110-1301  USA                                           *
0025  *                                                                         *
0026  ***************************************************************************/
0027 
0028 #include "NSLFilterTest.h"
0029 
0030 extern "C" {
0031 #include "backend/nsl/nsl_filter.h"
0032 }
0033 
0034 void NSLFilterTest::initTestCase() {
0035     const QString currentDir = __FILE__;
0036     m_dataDir = currentDir.left(currentDir.lastIndexOf(QDir::separator())) + QDir::separator() + QLatin1String("data") + QDir::separator();
0037 }
0038 
0039 //##############################################################################
0040 //#################  form test
0041 //##############################################################################
0042 
0043 
0044 void NSLFilterTest::testForm() {
0045     const int N = 1000;
0046     double data[N+2];
0047 
0048     int i;
0049     for (i = 0; i < N+2; i++)
0050         data[i] = 1.0;
0051     
0052     /*Bessel gain*/
0053     int n = 3;
0054     double x = 1.;
0055     double G = nsl_filter_gain_bessel(n, x);
0056     printf("G = %.15g\n", G);
0057     QCOMPARE(G, 0.901262652189164);
0058 
0059     /* filter form */
0060     nsl_filter_apply(data, N, nsl_filter_type_low_pass, nsl_filter_form_legendre, 2, 50, 2);
0061     nsl_filter_apply(data, N, nsl_filter_type_high_pass, nsl_filter_form_legendre, 2, 50, 2);
0062     nsl_filter_apply(data, N, nsl_filter_type_band_pass, nsl_filter_form_legendre, 2, 100, 50);
0063     nsl_filter_apply(data, N, nsl_filter_type_band_reject, nsl_filter_form_legendre, 2, 100, 100);
0064     nsl_filter_apply(data, N, nsl_filter_type_low_pass, nsl_filter_form_bessel, 2, 100, 100);
0065     nsl_filter_apply(data, N, nsl_filter_type_high_pass, nsl_filter_form_bessel, 2, 100, 100);
0066     nsl_filter_apply(data, N, nsl_filter_type_band_pass, nsl_filter_form_bessel, 2, 100, 100);
0067     nsl_filter_apply(data, N, nsl_filter_type_band_reject, nsl_filter_form_bessel, 2, 100, 100);
0068 
0069     //for(i=0; i < N/2; i++)
0070     //  printf("%d %g\n", i, data[2*i]);
0071 
0072     /* all pass order,cut,bw */
0073     nsl_filter_fourier(data, N, nsl_filter_type_high_pass, nsl_filter_form_ideal, 0, 0, 2);
0074 
0075     /* filter tests */
0076     nsl_filter_fourier(data, N, nsl_filter_type_low_pass, nsl_filter_form_ideal, 0, 3, 2);
0077     nsl_filter_fourier(data, N, nsl_filter_type_high_pass, nsl_filter_form_ideal, 0, 3, 2);
0078     nsl_filter_fourier(data, N, nsl_filter_type_band_pass, nsl_filter_form_ideal, 0, 2, 2);
0079     nsl_filter_fourier(data, N, nsl_filter_type_band_reject, nsl_filter_form_ideal, 0, 2, 2);
0080     nsl_filter_fourier(data, N, nsl_filter_type_low_pass, nsl_filter_form_butterworth, 1, 2, 2);
0081     nsl_filter_fourier(data, N, nsl_filter_type_high_pass, nsl_filter_form_butterworth, 1, 2, 2);
0082     nsl_filter_fourier(data, N, nsl_filter_type_band_pass, nsl_filter_form_butterworth, 2, 2, 2);
0083 }
0084 
0085 //##############################################################################
0086 //#################  performance
0087 //##############################################################################
0088 
0089 QTEST_MAIN(NSLFilterTest)