Skip to content

Conversation

@amishutin
Copy link
Contributor

@amishutin amishutin commented Dec 28, 2023

Added signal module with resampling function implemented with cubic interpolation function and a filtering function based on Kaiser window and Bessel function, used to construct a FIR filter.
Detail: https://en.wikipedia.org/wiki/Sample-rate_conversion

There are provided:

  • signal resampling API
  • optimization done with universal intrinsics
  • functional tests with reference signals
  • performance tests

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=Linux x64 Debug,Win32,ARMv7,ARMv8

@amishutin amishutin changed the title Add signal module with signal resampling function Add signal module with signal resampling function Dec 28, 2023
@amishutin amishutin changed the title Add signal module with signal resampling function Add signal module with signal resampling function Dec 28, 2023
@amishutin amishutin force-pushed the signal_module branch 4 times, most recently from 529db0a to ec7edb9 Compare January 9, 2024 06:35
@amishutin amishutin closed this Jan 9, 2024
@amishutin amishutin reopened this Jan 9, 2024
Copy link

@opencv-alalek opencv-alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution!

Please take a look on comments below.


float MSE(const Mat1f &outSignal, const Mat1f &refSignal)
{
auto mse{0.f};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use

float mse = 0.f;

here and below (instead of "auto" scalars).

To workaround old ARMv7 compiler.

static float Bessel(float x)
{
int k = 12; // approximation parameter
float defmul = powf(x, 2) * 0.25f;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

powf(x, 2)

x * x should be faster.


The same is below.

{
tabs[i] = 2 * fc * (i - (ntabs - 1) / 2);
}
float *tmparr = new float[ntabs];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use cv::AutoBuffer or std::vector instead. Avoid manual memory management.

for (int i = 0; i < ntabs; ++i)
{
tabs[i] = std::sin(tmparr[i]) / tmparr[i];
tabs[i] *= Bessel(beta * sqrtf((float)1 - powf((2 * i / (float)(ntabs - 1) - 1), 2))) / Bessel(beta);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ (float)(ntabs - 1)

could be moved out of the loop as pre-computed 2.0f / (float)(ntabs - 1)


/////////////// cubic Hermite spline (OpenCV's Universal Intrinsics) ///////////////
#if (CV_SIMD || CV_SIMD_SCALABLE)
static v_float32 simd_cubicHermite(v_float32 v_A, v_float32 v_B, v_float32 v_C, v_float32 v_D, v_float32 v_t)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v_float32

  1. static inline
  2. const v_float32& to workaround alignment issues (see Win32 builder)

@amishutin amishutin force-pushed the signal_module branch 3 times, most recently from c82e7f5 to 71d52c8 Compare January 10, 2024 11:28
@opencv-alalek
Copy link

Thank you for the updates!
Could you please try to run signal tests in Debug mode to verify failed assertions?

@amishutin
Copy link
Contributor Author

Thank you for the updates! Could you please try to run signal tests in Debug mode to verify failed assertions?

Found the issue in scalar code. Fixed

Copy link

@opencv-alalek opencv-alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for update!

// of this distribution and at http://opencv.org/license.html
#ifndef OPENCV_SIGNAL_HPP
#define OPENCV_SIGNAL_HPP

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add module declaration for documentation: http://pullrequest.opencv.org/buildbot/export/pr_contrib/3613/docs/

/**
@defgroup signal Signal Processing

This module includes signal processing algorithms.

@}
*/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added declaration

Copy link

@opencv-alalek opencv-alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done 👍

@amishutin
Copy link
Contributor Author

Added fix for Windows10-x64 warnings check

@opencv-alalek opencv-alalek self-assigned this Jan 12, 2024
@opencv-pushbot opencv-pushbot merged commit 674cec1 into opencv:4.x Jan 12, 2024
@asmorkalov asmorkalov mentioned this pull request Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants