Need help implementing DCT Type 4 algorithm I'm trying to implement Algorithm 2 from this paper: 


  Xuancheng Shao and Steven G. Johnson: Type-IV DCT, DST, and MDCT algorithms
  with reduced numbers of arithmetic operations, https://arxiv.org/pdf/0708.4399.pdf


It outlines an algorithm for computing an even-sized DCT type 4 via a DCT type 3 and a DST type 3 of half size.

I've made a few attempts at implementing this, but either the paper has a mistake or I have a serious misunderstanding about what's happening here.

https://pastebin.com/uFiHsMKX Here's my C++ code, which uses FFTW to compute the inner transforms, as well as to compute an "expected output". Aside from FFTW all the code necessary to compile is in this one file. The function compute_dct4 is what does the actual processing -- I did my best to name variables the same as in the paper, so it should be clear what in the code corresponds to what in the paper.

I'd appreciate some extra eyes on what's going wrong. Thanks!
I found the solution. There was a mistake in the paper.

On the first 2 lines of Algorithm 2:

w0 ← x0
vN/2 ← xN−1


x0 and xN-1 should be scaled by 2, giving:

w0 ← x0 * 2
vN/2 ← xN−1 * 2


The following paste has working code (and an open source license, so feel free to copy it)

https://pastebin.com/TvgU4b6d