1

When I execute this line of code:

self.forwardDCTSetup = vDSP.DCT(count: 40, transformType: vDSP.DCTTransformType.II)!

I get:

Fatal error: Unexpectedly found nil while unwrapping an Optional value

I am following this tutorial almost exactly: https://developer.apple.com/documentation/accelerate/signal_extraction_from_noise.

Syllabear
  • 193
  • 5

1 Answers1

2

The vDSP.DCT follows the same rules as vDSP_DCT_CreateSetup with regard to length / count:

The supported values are Length = f * 2**n, where f is 1, 3, 5, or 15 and n is at least 4. 

See: https://developer.apple.com/documentation/accelerate/1449930-vdsp_dct_createsetup

Flex Monkey
  • 3,583
  • 17
  • 19
  • Thanks for the quick response. Do you know why this constraint exists? The 2**n part makes sense but `f` doesn't. – Syllabear Aug 27 '20 at 17:53
  • 1
    @Syllabear: The DCT and DFT routines are implemented with a classic (but vectorized) FFT for the power-of-two lengths and the [prime-factor-algorithm](https://en.wikipedia.org/wiki/Prime-factor_FFT_algorithm) (PFA) for other lengths. The PFA is implemented efficiently by hard-coding permutations into the load and store operations and hard-coding “butterfly” calculations, and this was done for factors of 3 and 5, which also supports their product, 15. Supporting higher factors runs into problems with the number of available processor registers and the number of cases that must be hard-coded. – Eric Postpischil Aug 30 '20 at 23:55