MATLAB dct vs NAG c06rbf vs dfftpack dcost
Show older comments
Hi,
I've been trying to implement MATLAB's discrete cosine transform for a while now, converting some old code which uses the NAG routine c06rbf. My Google searching hasn't turned anything up so I thought I'd ask here.
- Documentation for the MATLAB routine: MATLAB dct
- Documentation for the NAG routine: NAG c06rbf
- Documentation for the dfftpack routine: dfftpack
- Minimal working example:
MATLAB:
N = 5;
vin = (1:-0.25:0).';
vout = dct(vin,N,'Type',1);
vout = sqrt(N/2)*vout; %remove normalisation factor
Fortran:
integer N,j
parameter (N=5)
double precision vin(N),vout_nag(N),vout_dfft(N)
double precision work(3*N+15),ifail
! !!!!!!! NAG implementation !!!!!!! !
do j = 1,N
vin(j) = 1-0.25*(j-1)
end do
ifail = 0
call c06rbf(1,N,vin,work,ifail)
do j = 1,N
vout_nag(j) = sqrt(N/2)*vin(j)
end do
! !!!!!!! dfftpack implementation !!!!!!! !
do j = 1,N
vin(j) = 1-0.25*(j-1)
end do
call dcosti(N,work)
call dcost(N,vin,work)
do j = 1,N
vout_dfft(j) = 0.5*vin(j)
end do
MATLAB output:
vout =
1.7449
1.1859
0.23155
0.39528
0.16373
Fortran output:
vout_nag =
2
1.184
0.125
0.065983
0.125
vout_dfft =
2
1.184
0.125
0.065983
0.125
I just can't quite figure out what's going wrong. I thought it might be a scaling factor issue but I can't pin it down, and trying to dissect the individual methods hasn't got me anywhere.
Any help appreciated!
Answers (0)
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!