I have a simple problem. I'm programming my own script to calculate the cross-correlation between two signals in Fortran (each signal can be represented as 1-D array). As any cross-correlation, I have to delay one signal with respect to the other, and compare only the intersecting elements between them. This means that for each lag, one of the signals will change its size because the intersecting elements will reduce.
The problem is the resizing of the array inside the code. I show a very simple example to show the situation, where the second signal is delayed with respect to the other. I only would need to know how to define s1
and s2
to keep this working, because what I put with allocatable
statement doesn't work:
program test_corr
! Defining variables:
integer :: i, max_delay
real, dimension(5) :: signal_1, signal_2
real, allocatable :: s1(:), s2(:)
! Signals to correlate:
signal_1 = (/ 1, 2, 3, 4, 5 /)
signal_2 = (/ 6, 7, 8, 9, 10 /)
! Loop along delays:
max_delay = 3
do i=1,max_delay
! Applying delay to the second signal:
s1 = signal_1(1:size(signal_1)-1)
s2 = signal_2(i+1:size(signal_2))
end do
end program
For example, if I add a print *, s2
statement inside the loop, it doesn't show anything. I would expect an output for the second signal like: 7 8 9 10
and then 8 9 10
for the first two iterations.
I am using ifort 15 and I compile like
ifort test_corr.f90 -o test_corr