How to use tensorflow's FFT?

痴心易碎 提交于 2020-06-17 15:51:51

问题


I am having some trouble reconciling my FFT results from MATLAB and TF. The results are actually very different. Here is what I have done:

1). I would attach my data file here but didn't find a way to do so. Anyways, my data is stored in a .mat file, and the variable we will work with is called 'TD'. In MATLAB, I first subtract the mean of the data, and then perform fft:

f_hat = TD-mean(TD);
x = fft(f_hat);

2). In TF, I use

tf.math.reduce_mean

to calculate the mean, and it only differs from MATLAB's mean on the order of 10^-8. So in TF I have:

mean_TD = tf.reduce_mean(TD)
f_hat_int = TD - mean_TD
f_hat_tf = tf.dtypes.cast(f_hat_int,tf.complex64)
x_tf = tf.signal.fft(f_hat_tf)

So up until 'f_hat' and 'f_hat_tf', the difference is very slight and is caused only by the difference in the mean. However, x and x_tf are very different. I am wondering did I not use TF's FFT correctly?

Thanks!

Picture showing the difference

来源:https://stackoverflow.com/questions/62238459/how-to-use-tensorflows-fft

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!