- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在执行以下操作:执行 FFT/削减 FFT 结果中高于 100Hz 的每个频率/执行逆 FFT
如果原始数据集没有偏移量,它效果很好!如果它有偏移,则输出结果幅度会被损坏。
示例:
从数学上来说,我什至不确定我是否能做我正在做的事情。我所能观察到的是,在有偏移的情况下,基频是原始频率的两倍???!!!
您知道为什么偏移量会改变吗?
代码:
def FFT(data,time_step):
"""
Perform FFT on raw data and return result of FFT (yf) and frequency axis (xf).
"""
"""
#Test code for the manual frequency magnitude plot
import numpy as np
import matplotlib.pyplot as plt
#Generate sinus waves
x = np.linspace(0,2*np.pi,50000) #You need enough points to be able to capture information (Shannon theorem)
data = np.sin(x*2*np.pi*50) + 0.5*np.sin(x*2*np.pi*200)
time_step = (x[-1]-x[0])/x.size
list_data = FFT(data,time_step)
x = list_data[0]
y = list_data[1]
plt.figure()
plt.xlim(0,300)
plt.plot(x,np.abs(y)/max(np.abs(y)),'k-+')
"""
N_points = data.size
#FFT
yf_original=np.fft.fft(data*time_step) #*dt really necessary? Better for units, probably
#Post-pro
#We keep only the positive part
yf=yf_original[0:N_points/2]
#fundamental frequency
f1=1/(N_points*time_step)
#Generate the frequency axis - n*f1
xf=np.linspace(0,N_points/2*f1,N_points/2)
return [xf, yf, yf_original]
def Inverse_FFT(data,time_step,freq_cut):
list_data = FFT(data,time_step)
N_points = data.size
#FFT data
x = list_data[0]
yf_full = list_data[2]
#Look where the frequency is above freq_cut
index = np.where(x > freq_cut)
x_new_halfpos = x[0:index[0][0]-1] #Contains N_points/2
yf_new = np.concatenate((yf_full[0:index[0][0]-1], yf_full[N_points/2 +1:index[0][0]-1]))
#Apply inverse-fft
y_complex = np.fft.ifft(yf_new)
#Calculate new time_step ??!!
N_points_new = x_new_halfpos.size *2
f1 = x_new_halfpos[1]
time_step_new = 1/(N_points_new*f1)
#Create back the x-axis for plotting. The original data were distributed every time_step. Now, it is every time_step_new
""" WARNING - It assumes that the new x_new axis is equally distributed - True ?!? """
x_new = np.linspace(0,N_points_new*time_step_new,N_points_new/2)
y_new = y_complex.real / time_step_new
return [x_new,y_new]
生成示例的示例代码:
import numpy as np
import matplotlib.pyplot as plt
#Generate sinus waves
x = np.linspace(0,2*np.pi,50000) #You need enough points to be able to capture information (Shannon theorem)
data = np.sin(x*2*np.pi*5) + 0.5*np.sin(x*2*np.pi*20) + 0.2*np.random.normal(x)
plt.figure()
plt.xlim(0,np.pi/4)
plt.plot(x,data)
time_step = (x[-1]-x[0])/x.size
list_data = FFT(data,time_step)
x = list_data[0]
y = list_data[1]
plt.figure()
plt.xlim(0,30)
plt.xlabel("Frequency [Hz]")
plt.ylabel("Normalized magnitude")
plt.plot(x,np.abs(y)/max(np.abs(y)),'k-+')
#Anti-FFT
data_new = Inverse_FFT(data,time_step,100)
x_new = data_new[0]
y_new = data_new[1]
time_step_new = (x_new[-1]-x_new[0])/x_new.size
plt.figure()
plt.xlim(0,np.pi/4)
plt.plot(x_new,y_new)
list_data_new = FFT(y_new,time_step_new)
x_newfft = list_data_new[0]
y_newfft = list_data_new[1]
plt.figure()
plt.xlim(0,30)
plt.xlabel("Frequency [Hz]")
plt.ylabel("Normalized magnitude")
plt.plot(x_newfft,np.abs(y_newfft)/max(np.abs(y_newfft)),'k-+')
谢谢!
亲切的问候,
编辑:更正功能:
def Anti_FFT(data,time_step,freq_cut):
list_data = FFT(data,time_step)
N_points = data.size
#FFT data
x = list_data[0]
yf_full = list_data[2]
#Look where the frequency is above freq_cut
index = np.where(x > freq_cut)
x_new_halfpos = x[0:index[0][0]-1] #Contains N_points/2
#Fill with zeros
yf_new = yf_full
yf_new[index[0][0]:N_points/2 +1]=0
yf_new[N_points/2 +1 :-index[0][0]]=0 #The negative part is symmetric. The last term is the 1st term of the positive part
#Apply anti-fft
y_complex = np.fft.ifft(yf_new)
#Calculate the """new""" x_axis
x_new = np.linspace(0,N_points*time_step,N_points)
#Divide by the time_step to get the right units
y_new = y_complex.real / time_step
return [x_new,y_new]
最佳答案
N 个(偶数)实值序列 f 的 DFT(f)(称为 F)具有以下属性:
F(0)(直流偏移)是一个实数
F(N/2) 是实数,即奈奎斯特频率的幅度。对于[1..N/2-1]中的i,F[N/2+i]* = F[N/2-i],其中“*”表示复共轭。
您对 F 的操作必须保留这些属性。
仅供引用,有一些用于实值输入的特殊例程,它们使用这种对称性来计算 FFT 和 iFFT,其速度几乎是复杂数据的一般对应物的两倍。
关于python - FFT - 滤波 - 逆 FFT - 剩余偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30664640/
我正在尝试从第 4 到 9 页以及第 12 和 13 页上的单元格中清除所有内容(包括图像)。我有以下代码,但它正在清除第 3-9 和 12-15 页中的内容,我不知道为什么。 有什么想法吗? Sub
有没有办法增加极坐标图刻度标签(θ)的填充/偏移? import matplotlib import numpy as np from matplotlib.pyplot import figure,
我正在调用本地 API 并尝试以分页 样式进行操作。我有 n 张图片,我想将它们分成 n/4 行(每行 4 张图片)。因此,我正在调用我的 API,images/count,offset。但不知何故,
我的问题解释起来有点棘手,但无论如何我都会尝试。我有两个水平选项卡,当您单击它们时,会打开一个文本框内容。当他们被点击时,我试图“关注”他们。我在网上找到了很多资料,但除了我在下面显示的这段代码外,没
所以我有一个 float 的 div,我需要它始终向右 200 像素,并填充窗口的其余部分。有没有某种跨浏览器兼容的方法,我可以在不借助 javascript 的情况下使宽度填满页面的其余部分? 最佳
我有以下片段 $('html,body').animate({scrollTop: $('#menu').offset().top}, 'slow'); 单击链接时,我希望浏览器从#menu div
我目前正在为我的应用程序使用 JASidePanel,并且我有一个 UITableViewcontroller 和一个 UIRefreshControl 作为它的 ViewController 之一。
给出以下代码: imshow(np.arange(16*16).reshape(16,16)) cb = colorbar() cb.set_label("Foo") cb.set_ticks([0,
我是编程新手,我认为 VBA 是一个很好的起点,因为我在 Excel 中做了很多工作。 我创建了一个宏,它从输入框中获取一个整数(我一直使用 2、3 和 4 来测试),并创建该数字的一组 4 层层次结
我在 PHP 中有一个 unix 时间戳: $timestamp = 1346300336; 然后我有一个我想要应用的时区的偏移量。基本上,我想应用偏移量并返回一个新的 unix 时间戳。偏移量遵循这
演示:http://jsfiddle.net/H45uY/6/ 我在这里想做的是将 的左上角设为跟随鼠标。代码在没有段落的情况下工作正常(请参阅上面的演示),但是当您添加段落时,被向上推,鼠标位于盒
假设我们有两个由无符号长(64 位)数组表示的位图。我想使用特定的移位(偏移)合并这两个位图。例如,将位图 1(较大)合并到位图 2(较小)中,起始偏移量为 3。偏移量 3 表示位图 1 的第 3 位
通过在 pageViewController 中实现 tableView,tableView 与其显示的内容不一致。对此最好的解决办法是什么? 最佳答案 如果您的 TableView 是 View C
我设置了一个在 nib 中显示地点信息的地点配置文件。当我在标准屏幕流程中推送此 View 时,它工作正常。但是,当我从另一个选项卡推送此 View 时,UINavigationBar 似乎抵消了它,
如果我想选择 5 条记录,我会这样做: SELECT * FROM mytable LIMIT 5 如果我想添加偏移量,我会这样做: SELECT * FROM mytable OFFSET 5 LI
我有一个应用程序,其中某些 View 需要全屏,而其他 View 不需要全屏。在某些情况下,我希望背景显示在状态栏下方,所以我在 View 加载时使用它来使 Activity 全屏显示: window
在下图中,我进行绘制,结果位于 A 点,就在我手指接触的地方。 如何使图像显示在实际触摸上方约 40pt。 (二) 我正在使用经典的 coreGraphic UITouch 代码,如下所示: - (v
只要键盘处于事件状态,我就会尝试偏移 UITextField,效果很好,直到我尝试了表情符号布局。有没有办法检测键盘输入的类型,以便找出高度差?谢谢 最佳答案 不是使用 UIKeyboardDidSh
这是我的 Swift 代码 (AppDelegate.swift): var window: UIWindow? var rootViewController :UIViewController? f
我有一个 div 作为绝对定位的 body 的直接子节点,其 css 属性定义如下: div[id^="Container"] { display: block; position: a
我是一名优秀的程序员,十分优秀!