44
55import numpy
66import math
7-
7+ import logging
88
99def 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
7474def 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
8487def 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
9396def 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