- #1
eoghan
- 210
- 7
Dear all,
I don't know if this is the correct place for this question, but I did a little search on the forum and I saw that most FFT related questions have been posted here.
My question is this: I need to deconvolve two real signals (in my case they are two probability density functions), so I go in Fourier space, I divide them and then I go back to real space.
Now, before apply FFT I need to sample the signals, i.e. I have to define a sampling interval and frequency. Now, if the sampling interval is on the positive axis (the signal s is sampled at discrete time points s[t], t>=0) then everything is fine, but if the sampling interval includes negative points, then when I perform the inverse FFT on the FFTs of the two signals, the final signal results swapped, i.e. the
signal corresponding to the negative sampling points is put to the right, after the positive sampling points.
Can you please help me understand why this happens? Notice that if I perform iFFT(FFT(s)), where iFFT is the inverse FFT and s is my sampled signal, everything is fine even when the sampling interval comprises negative time points (i.e. s[t], t<0).
Here you can see an example of the code (R language):
I don't know if this is the correct place for this question, but I did a little search on the forum and I saw that most FFT related questions have been posted here.
My question is this: I need to deconvolve two real signals (in my case they are two probability density functions), so I go in Fourier space, I divide them and then I go back to real space.
Now, before apply FFT I need to sample the signals, i.e. I have to define a sampling interval and frequency. Now, if the sampling interval is on the positive axis (the signal s is sampled at discrete time points s[t], t>=0) then everything is fine, but if the sampling interval includes negative points, then when I perform the inverse FFT on the FFTs of the two signals, the final signal results swapped, i.e. the
signal corresponding to the negative sampling points is put to the right, after the positive sampling points.
Can you please help me understand why this happens? Notice that if I perform iFFT(FFT(s)), where iFFT is the inverse FFT and s is my sampled signal, everything is fine even when the sampling interval comprises negative time points (i.e. s[t], t<0).
Here you can see an example of the code (R language):
Code:
#Define sampling interval
fs <- 0.05
n0 <- -30
nMax <- 100
N=(nMax-n0)/fs
mids <- seq(0, (N-1))*fs+n0
#Sample two continuous probability density functions (fO and fB) that must be deconvolved
fO = density(rnorm(1000000, 40, 6), bw=1.5, from=n0, to=nMax, n=N)
fB = hist(rnorm(1000000, 14, 2), breaks=c((mids-fs/2), (tail(mids,1)+fs/2)), plot=F)$density
#Perform the FFT
fO.fft <- fft(fO$y)
fB.fft <- fft(fB)
#Divide the FFTs (deconvolution) and go back to real space
fT <- abs(fft(fO.fft/(fs*fB.fft), inverse=T))/length(fO$x)
#Plot the results to check the deconvolution
plot(fO$x, fB, type='l', col=1) #First signal
lines(fO, type='l', col=2) #Second signal
shift <- which(mids==min(abs(mids))) #Now I need to swap the deconvolved signal... why?
fT.shifted <- c(tail(fT, shift), fT[shift : length(fT)-shift]) #Swapped deconvolved signal
lines(mids, abs(fT.shifted), type='l', col=3)
lines(mids, dnorm(mids, 26, sqrt(36-4)), col=4) #Theoretical deconvolved signal
legend(x='topright', legend=c('B', 'O', 'Estimated T', 'True T'), col=1:4, lwd=1)