2014-04-04 4 views
0

클래스 FFT_Plot() :pyQTGraph 설정 축 값 (FFT)

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을 표시합니다. 빈도 나 진폭을 표시 할 수 없다면 계산할 수 없습니다.

범위를 변경하면 스펙트럼이 효과적으로 축소됩니다 ... 일부 예제를 보았지만 무슨 일이 벌어지는 지에 대한 설명이 없어져서 빨리 잃었습니다.

어떤 도움을 주시면 감사하겠습니다 ... 누가 공유로

... 나는 내가 '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 유형이 아닌 수학의 의견을 추가 할 주시기 바랍니다.

또한 Y 축을 올바르게 읽으려면 진폭 배열을 그에 따라 사전 크기 조정해야하는 것으로 보입니다.

+0

수정 - 취소됨 – user3279899

답변

1

pyqtgraph에서 축 값은 표시된 데이터의 좌표계를 기반으로 자동 결정됩니다. 지정된 y 값만 사용하여 plot()을 호출하면 range(len(yValues))과 같은 정수 x 값이 필요하다고 가정합니다. 따라서 샘플의 x 값의 범위를 0에서 50k로 지정하려면 plot : self.plot.plot(x=fScale, y=amplitude) 호출에서 해당 값을 제공해야합니다. 그에 따라 축 값이 반응해야합니다.