【发布时间】:2014-05-17 01:23:25
【问题描述】:
类 FFT_Plot():
def __init__(self,
win,
nSamples,
aData,
sRate,
wFunction,
zStart = 0):
self.nSamples = nSamples # Number of Sample must be a 2^n power
self.aData = aData # Amplitude data array
self.sRate = sRate # Sample Rate
self.wFunction = wFunction # Windowing Function
self.zStart = zStart # Start of Zoom Window if Used
self.zStop = nSamples/2 # End of Zoom Window if Used
# Instantiate a plot window within an existing pyQtGraph window.
self.plot = win.addPlot(title="FFT")
self.update(aData)
self.grid_state()
self.plot.setLabel('left', 'Amplitude', 'Volts')
self.plot.setLabel('bottom', 'Frequency', 'Hz')
def update(self, aData):
x = np.fft.fft(aData,)
amplitude = np.absolute(x)
fScale = np.linspace(0 , 50000, self.nSamples)
self.plot.plot(amplitude)
# Calculate and set-up X axis
self.plot.setXRange(SampleSize/2, 0)
def grid_state(self, x = True, y = True):
self.plot.showGrid(x, y)
我的问题很简单。如何更改沿 x 和 y 轴显示的值?
当使用 2048 个样本并显示一半样本(0 到样本/2)时,我会显示 0 到 1。如果无法显示频率或幅度,计算它们对我没有好处。
如果我改变范围,我会有效地放大光谱...我看过一些例子,但我很快就迷失了,因为没有任何关于发生了什么的解释。
任何帮助将不胜感激......
正如 Luke 所分享的......我错过了我可以使用“X”数组的事实。 :) 更正的初学者课程如下:
类 FFT_Plot():
def __init__(self,
win,
nSamples,
aData,
sRate,
wFunction,
zStart = 0):
self.nSamples = nSamples # Number of Sample must be a 2^n power
self.aData = aData # Amplitude data array
self.sRate = sRate # Sample Rate as Frequency
self.wFunction = wFunction # Windowing Function
self.zStart = zStart # Start of Zoom Window if Used
self.zStop = nSamples/2 # End of Zoom Window if Used
# Instantiate a plot window within an existing pyQtGraph window.
self.plot = win.addPlot(title="FFT")
self.update(aData)
self.grid_state()
self.plot.setLabel('left', 'Amplitude', 'Volts')
self.plot.setLabel('bottom', 'Frequency', 'Hz')
def update(self, aData):
x = np.fft.fft(aData,)
amplitude = np.absolute(x)
# Create a linear scale based on the Sample Rate and Number of Samples.
fScale = np.linspace(0 , self.sRate, self.nSamples)
self.plot.plot(x = fScale, y = amplitude, pen={'color': (0, 0, 0), 'width': 2})
# Because the X-axis is now tied to the fScale, which os based on sRate,
# to set any range limits you must use the sRate.
self.plot.setXRange(self.sRate/2, 0)
def grid_state(self, x = True, y = True):
self.plot.showGrid(x, y)
任何 DSP 类型请随意添加非数学 cmets。
此外,要让 Y 轴正确读取,幅度数组似乎必须相应地进行预缩放。
【问题讨论】: