2

Say you have an array of 1000 CGFloats

...
at 13.0:   1000.001
at 14.0:   1152.934
at 15.0:   1000.909
at 16.0:   1200.666
...

And you'll be needing a value at any value

smoothed(13.40) == about 1085, say

enter image description here

So, we're talking about something like kernel smoothing - a window function. Such as

  • a gaussian kernel smoother
  • kernel average smoother
  • local linear regression smoother

Excellent article: https://en.wikipedia.org/wiki/Kernel_smoother

enter image description here

Does iOS have something like this built-in to one of the GPU frameworks?

It's completely common for computers to do this sort of thing constantly, particularly in graphics subsystems.

How to do this in iOS on the GPU ... perhaps in Core audio or the Compute stack? (Of course it's easy to do by hand in Swift.)

Fattie
  • 27,874
  • 70
  • 431
  • 719

2 Answers2

5

For anyone googling here, one close-to-a-solution for the problem posed - basically "get smooth values between array points" - is to use precisely Apple's own system for that, which is used by Apple everywhere in iOS (every single animation, fade, etc).

Fortunately there's an excellent beginner article from Apple on it here:

https://developer.apple.com/documentation/accelerate/vdsp/linear_interpolation_functions/use_linear_interpolation_to_construct_new_data_points

enter image description here


Somewhat related, always an opportunity to remind of the truly amazing "best friend of every iOS/droid engineer":

enter image description here

https://cubic-bezier.com/#.17,.67,.81,1.2

How-to use it: https://stackoverflow.com/a/40363603/294884

halfer
  • 19,824
  • 17
  • 99
  • 186
Fattie
  • 27,874
  • 70
  • 431
  • 719
2

There are vDSP functions in the Accelerate Framework on iOS devices which include functions, such as vDSP_biquad() and vDSP_deq22() (and the Swift equivalents), that can be used to construct IIR low-pass filters.

You can also use vDSP functions for convolution, such as vDSP_conv(), and the Swift equivalent convolve(), as well as their 2D versions, for convolutional FIR filtering.

Low-pass filters can be used for very high quality smoothing, as long as the data to be smoothed is much longer than the significant portion of the impulse response of the low-pass filter, or is integer periodic.

Apple claims that their vDSP functions are highly accelerated by using the VLIW functional units available on the arm64 CPU.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153