2

I have a list with 1000 sensor reading values (sampling rate = 10Hz):

sensor = [100,100,200,...,100]

I need to get the spectral analysis of subsets of this list with a windowing function (i.e a Kaiser window).

So, I want to get a list where the FFT is calculated over multiple sub-samplers of this data (let's say 100 results), with a displacement window of 50 readings (overlapping 25 reading in each limit) and, so, getting 20 results on frequency domain.

Then, I want to apply a bandpass weighting function for 3 bands (let's say 1-2Hz, 2-4Hz, 4-8Hz).

The ending result should be a 2D list, where in the first dimension are the "bands" and in the second one are represented the values of the amplitude (real part) for that band.

bands = [[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],[1,...],[1,...]]

Can anyone help me?

EDITED: ok, let's split the problem:

1) Given a list=[1,2,3,4,5,6,7,8]. How can I create a 2D list of this kind: list2D = [[1,2,3,4],[3,4,5,6],[5,6,7,8]]? This is the first problem to make a displacement window.

2) For each element (1st dimension) of this list2D: how can I make a FFT analysis together with a windowing function (a FFT that takes more into "consideration" the middle values) ?

3) For each FFT result, how can I make a bandpass filter such as the discrete results from the real part of the spectrum are converted into the average value for a frequency interval?

kairos
  • 524
  • 4
  • 16
  • You might like to take a look at OpenCV. I haven't used it with Python, but the FFT (or rather Discrete Fourier Transform) in C/C++ seems pretty fair. – ilent2 May 26 '14 at 16:11
  • the problem is that all my other code is developed in Python (and there is a lot of that)... I'm already working with numpy and scipy to get it done... – kairos May 26 '14 at 16:12
  • 1
    I'm pretty sure there is a Python binding/library for OpenCV, but I have not tried it. – ilent2 May 26 '14 at 16:13
  • Look e.g. here for libraries: http://stackoverflow.com/q/6363154/2379410 Other than that "can anyone help me" is too broad and you need to refine your question. –  May 26 '14 at 16:31
  • my last edition is enough? please give me a "meta-help" so I could refine even more my doubt.. – kairos May 26 '14 at 17:12
  • Good edit, I think the question is a lot easier to answer like this. For more on asking questions: http://stackoverflow.com/help/how-to-ask For more on part 1) of your question you could look into this: http://stackoverflow.com/q/4923617/2379410 –  May 27 '14 at 07:20

1 Answers1

4

For part 1) and 2) please have a look at the following example:

import numpy as np
import scipy as sci
from scipy.signal import blackman
from scipy.signal import hanning

a = np.array([1,2,3,4,5,6,7,8])


b = np.empty([2, int(len(a)/2)], dtype=complex)
b[0,:] = a[0:int(len(a)/2)]
b[1,:] = a[(int(len(a)/2)-1):-1]

res = np.empty([2, int(len(a)/2)], dtype=complex)

# create blackman window
w = blackman(int(len(a)/2))
# you could also use a hanning window:
# w = hanning(int(len(a)/2))

for i in range(2):
    res[i,:] = sci.fftpack.fft(b[i,:] * w)

Is this what you wanted? As for part 3) I am not quite sure what you need.

  • That is almost perfect! Many thks! For 3) what I want is to get the average amplitude of all frequencies within a "band" (i.e. the average amplitude value of all frequencies between 1Hz and 4Hz) – kairos May 26 '14 at 20:41
  • For that you take the array res and sum up np.abs(res[i,j])**2 and devide by the number of bins you are summing over. Right? Of course first of all you need to define a time axis, otherwise it makes no scence to talk about a frequency in Hz anyway. The frequency step size is - at least proportional to - df = 2 * np.pi / (int(len(a)/2) * dt), where dt is a time step size and int(len(a)/2) number of points in time array. –  May 26 '14 at 20:50
  • Also note, if your time-domain signal is real, then the FFT signal will be symmetric. This means you get possitive and negative frequency. Simply choose one the positive side and then you are set for part 3) –  May 26 '14 at 21:12
  • YES! Many thanks! That worked seamless! I've used the abs value for the FFT. – kairos May 27 '14 at 11:07