0

lets say i have a datasetset of seven columns and i just take one column (xyz_magnitude) of size 1,415,684 rows and i feed it to calculate the spectrogram of that column, i expected to get the spectrogram of one column with the same size as the input (xyz_magnitude) but it gets me one column with more than 1,415,684. it prints actually 7,087,647 rows

why this huge number of spectrogram rows, and why it is not the same number of rows as the input

this my code

dataset = np.loadtxt("dataset.txt", delimiter=",")
magnitude = dataset[:,5]
ls, freqs, bins, im = plt.specgram(magnitude, NFFT=1000, Fs=1.0, noverlap=900)
merged = list(itertools.chain(*ls))
Hadeer El-Zayat
  • 281
  • 5
  • 20

1 Answers1

0

specgram computes the Discrete Fourier Transform of multiple segments of the input signal to give an output matrix which presents the frequency content (along rows of each given column) over time (each column represent a different time instant).

In your specific case, when setting the parameter NFFT to 1000, you would get an output with 1000/2 + 1 or 501 rows (i.e. includes 501 frequency bins). The number of time slices is controlled by the combination of NFFT and noverlap parameters to give 14,147 rows. This then results in 501 * 14,147 = 7,087,647 values (which is consistent with your concatenated output).

To get a single time slice (with a larger number of frequency bins as with NFFT=1000) you could either set NFFT=1,415,684 (which would give you an output with 707,843 values for sides=default/sides=onesided, or 1,415,684 values with sides=twosided) with plt.specgram, or use an FFT primitive such as numpy.fft.

SleuthEye
  • 14,379
  • 2
  • 32
  • 61