autocorrelation program


dn123
09-08-2010, 04:29 AM
hi....
i have to write a program that calculate autocorrelation for different time lags...
can anyone help me...

davekw7x
09-08-2010, 09:51 AM
hi....Hi.
...calculate autocorrelation...



!
! Demonstration using NR function correl to
! perform autocorrelation
!
! davekw7x
!

program xcorrel

use nr


implicit none

integer, parameter :: N = 16

integer i
real data1(N), autocor(N)

! First four are 1.0, rest are zeros
data1(1:4) = 1.0
data1(5:N) = 0.0


! Autocorrelation uses same argument for first and second
autocor(:) = correl(data1, data1)

write(*,'(/" n",10x,"Data", 7x, "Autocorrelation"/)')
do i = 1, N
write(*, '(i4,f15.6,f16.6)') i, data1(i), autocor(i)
enddo

end program xcorrel



Output:


n Data Autocorrelation

1 1.000000 4.000000
2 1.000000 3.000000
3 1.000000 2.000000
4 1.000000 1.000000
5 0.000000 0.000000
6 0.000000 0.000000
7 0.000000 0.000000
8 0.000000 0.000000
9 0.000000 0.000000
10 0.000000 0.000000
11 0.000000 0.000000
12 0.000000 0.000000
13 0.000000 0.000000
14 0.000000 1.000000
15 0.000000 2.000000
16 0.000000 3.000000


Regards,

Dave

dn123
09-09-2010, 06:11 AM
thnks dave