Skip to content

Commit 1442780

Browse files
authored
added warning when framelen > NFFT
1 parent 55d4ad1 commit 1442780

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

python_speech_features/sigproc.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import numpy
66
import math
7-
7+
import logging
88

99
def round_half_up(number):
1010
return int(decimal.Decimal(number).quantize(decimal.Decimal('1'), rounding=decimal.ROUND_HALF_UP))
@@ -72,17 +72,20 @@ def deframesig(frames,siglen,frame_len,frame_step,winfunc=lambda x:numpy.ones((x
7272
return rec_signal[0:siglen]
7373

7474
def magspec(frames,NFFT):
75-
"""Compute the magnitude spectrum of each frame in frames. If frames is an NxD matrix, output will be NxNFFT.
75+
"""Compute the magnitude spectrum of each frame in frames. If frames is an NxD matrix, output will be Nx(NFFT/2+1).
7676
7777
:param frames: the array of frames. Each row is a frame.
7878
:param NFFT: the FFT length to use. If NFFT > frame_len, the frames are zero-padded.
7979
:returns: If frames is an NxD matrix, output will be Nx(NFFT/2+1). Each row will be the magnitude spectrum of the corresponding frame.
8080
"""
81+
if numpy.shape(frames)[1] > NFFT:
82+
logging.warn('frame length (%d) is greater than FFT size (%d), frame will be truncated. Increase NFFT to avoid.', numpy.shape(frames)[1], NFFT)
8183
complex_spec = numpy.fft.rfft(frames,NFFT)
84+
print(numpy.shape(complex_spec))
8285
return numpy.absolute(complex_spec)
8386

8487
def powspec(frames,NFFT):
85-
"""Compute the power spectrum of each frame in frames. If frames is an NxD matrix, output will be NxNFFT.
88+
"""Compute the power spectrum of each frame in frames. If frames is an NxD matrix, output will be Nx(NFFT/2+1).
8689
8790
:param frames: the array of frames. Each row is a frame.
8891
:param NFFT: the FFT length to use. If NFFT > frame_len, the frames are zero-padded.
@@ -91,7 +94,7 @@ def powspec(frames,NFFT):
9194
return 1.0/NFFT * numpy.square(magspec(frames,NFFT))
9295

9396
def logpowspec(frames,NFFT,norm=1):
94-
"""Compute the log power spectrum of each frame in frames. If frames is an NxD matrix, output will be NxNFFT.
97+
"""Compute the log power spectrum of each frame in frames. If frames is an NxD matrix, output will be Nx(NFFT/2+1).
9598
9699
:param frames: the array of frames. Each row is a frame.
97100
:param NFFT: the FFT length to use. If NFFT > frame_len, the frames are zero-padded.

0 commit comments

Comments
 (0)