# torch-signal

• Fourier Transforms (real & complex) (1D, 2D, 3D)
• Cosine Transforms (1D, 2D, 3D)
• Short-time Fourier Transforms
• Spectrogram
• Hilbert Transform
• Complex Cepstral Analysis, Real Cepstrums

## Quickstart

OSX (Homebrew):

brew install fftw


Ubuntu:

sudo apt-get install libfftw3


Install torch-signal:

luarocks install https://raw.github.com/soumith/torch-signal/master/rocks/signal-scm-1.rockspec


For documentation, go to: http://soumith.github.io/torch-signal/signal/

For examples, see tests/

keep the loaded C object around, so that it doesn't get garbage collected

### complex.lua

All functions in here expect either a 2D Nx2 Complex tensor

### signal.complex.poly(x)

Polynomial with specified roots

Function is super unoptimized

#### Undocumented methods

• signal.complex.angle(h)
• signal.complex.exp(h)
• signal.complex.abs(h)
• signal.complex.real(h)
• signal.complex.imag(h)
• signal.complex.conj(h)
• signal.complex.prod(h)
• signal.complex.cmul(a1,b1, noargcheck)
• signal.complex.dot(a,b)
• signal.complex.mm(a,b)
• signal.complex.diag(x)

### signal.conv1d(input, kernel, stride)

1D valid convolution with stride

### extramath.lua

some extra math functions

#### Undocumented methods

• signal.xmath.round(num)
• signal.xmath.log2(x)
• signal.xmath.nextpow2(x)

### signal.fft(input)

1D FFT Takes Real inputs (1D tensor of N points) or complex inputs 2D tensor of (Nx2) size for N points

Output matches with matlab output

### signal.ifft(input)

inverse 1D FFT Takes Real inputs (1D tensor of N points) or complex inputs 2D tensor of (Nx2) size for N points

Output matches with matlab output

### signal.rfft(input)

real to complex dft. This function retains only the positive frequencies. Input is a 1D real tensor Output is 2D complex tensor of size (input:size(1)/2 + 1, 2)

### signal.irfft(input)

complex to real dft. This function is the exact inverse of signal.rfft

### signal.fft2(input)

2D FFT Takes Real inputs (2D tensor of NxM points) or complex inputs 3D tensor of (NxMx2) size for NxM points

Output matches with matlab output

### signal.ifft2(input)

2D Inverse FFT Takes Real inputs (2D tensor of NxM points) or complex inputs 3D tensor of (NxMx2) size for NxM points

Output matches with matlab output

### signal.fft3(input)

3D FFT Takes Real inputs (3D tensor of NxMxP points) or complex inputs 4D tensor of (NxMxPx2) size for NxMxP points

Output matches with matlab output

### signal.ifft3(input)

3D Inverse FFT Takes Real inputs (3D tensor of NxMxP points) or complex inputs 4D tensor of (NxMxPx2) size for NxMxP points

Output matches with matlab output

### signal.hann(L, flag)

returns an L-point Hann window in a 1D tensor. L must be a positive integer. When 'periodic' is specified, hann computes a length L+1 window and returns the first L points. flag: 'periodic' or 'symmetric'. 'symmetric' is default

Output matches with matlab output

### signal.blackman(N, flag)

returns an N-point Blackman window in a 1D tensor. N must be a positive integer. When 'periodic' is specified, computes a length N+1 window and returns the first N points. flag: 'periodic' or 'symmetric'. 'symmetric' is default

Output matches with matlab output

### signal.blackmanharris(N, flag)

returns an N-point minimum 4-term Blackman-Harris window in a 1D tensor. The window is minimum in the sense that its maximum sidelobes are minimized. N must be a positive integer.
flag: 'periodic' or 'symmetric'. 'symmetric' is default

Output matches with matlab output

### signal.stft(input, window_size, window_stride, window_type)

1D complex short-time fourier transforms Run a window across your signal and calculate fourier transforms on that window. To make sure that the windows are not discontinuous at the edges, you can optionally apply a window preprocessor. The available window preprocessors are: hamming, hann, bartlett

### signal.rstft(input, window_size, window_stride, window_type)

1D real short-time fourier transforms Run a window across your signal and calculate fourier transforms on that window. To make sure that the windows are not discontinuous at the edges, you can optionally apply a window preprocessor. rfft is used for fourier transform, so only the positive frequencies are retained The available window preprocessors are: hamming, hann, bartlett

### signal.spectrogram(inp, window_size, window_stride)

Takes the rstft(x) and generates a pretty spectrogram by taking the magnitude of the stft, and applying a (natural log * 10) Also transposes the output, to have time on the X axis.

### signal.unwrap(a, tol)

Correct phase angles to produce smoother phase plots
Unwrap radian phases by adding multiples of 2*pi as appropriate to remove jumps greater than tol. tol defaults to pi.

Output matches with matlab output

### signal.rcunwrap(x)

unwraps the phase and removes phase corresponding to integer lag.

Output matches with matlab output

### signal.rcwrap(y, nd)

Adds phase corresponding to integer lag

Output matches with matlab output

### signal.cceps(x)

1D Complex cepstral analysis Returns the cepstrum and a phase shift factor "nd" that is useful to invert the signal back.

Output matches with matlab output

### signal.icceps(xhat,nd)

1D Inverse Complex cepstral analysis. Takes in the outputs of cceps to produce the input signal back

Output matches with matlab output

### signal.rceps(x)

Real cepstrum and minimum phase reconstruction The real cepstrum is the inverse Fourier transform of the real logarithm of the magnitude of the Fourier transform of a sequence.

Output matches with matlab output

### signal.dct(input)

1D Discrete Cosine Transform (DCT) Takes Real inputs (1D tensor of N points)

To see what is exactly computed, see section REDFT10 over here: http://www.fftw.org/doc/1d-Real_002deven-DFTs-_0028DCTs_0029.html

### signal.idct(input)

inverse 1D Discrete Cosine Transform (DCT) Takes Real inputs (1D tensor of N points)

To see what is exactly computed, see section REDFT01 over here: http://www.fftw.org/doc/1d-Real_002deven-DFTs-_0028DCTs_0029.html

### signal.dct2(input)

2D Discrete Cosine Transform (DCT) Takes Real inputs (2D tensor of NxM points)

To see what is exactly computed, see section REDFT10 over here: http://www.fftw.org/doc/1d-Real_002deven-DFTs-_0028DCTs_0029.html

### signal.idct2(input)

inverse 2D Discrete Cosine Transform (DCT) Takes Real inputs (2D tensor of NxM points)

To see what is exactly computed, see section REDFT01 over here: http://www.fftw.org/doc/1d-Real_002deven-DFTs-_0028DCTs_0029.html

### signal.dct3(input)

3D Discrete Cosine Transform (DCT) Takes Real inputs (3D tensor of NxMXP points)

To see what is exactly computed, see section REDFT10 over here: http://www.fftw.org/doc/1d-Real_002deven-DFTs-_0028DCTs_0029.html

### signal.idct3(input)

inverse 3D Discrete Cosine Transform (DCT) Takes Real inputs (3D tensor of NxMxP points)

To see what is exactly computed, see section REDFT01 over here: http://www.fftw.org/doc/1d-Real_002deven-DFTs-_0028DCTs_0029.html

### signal.hilbert(xr)

Discrete-time analytic signal using Hilbert transform Takes 1D inputs

Output matches with matlab output

#### Undocumented methods

• signal.typecheck(input)

### signal.wavelet.haar1d()

Haar wavelet (1D) return the phi and psi functions of a haar wavelet

### signal.wavelet.daubechies1d()

Daubechies wavelet (1D) return the phi and psi functions of a daubechies wavelet

### signal.wavelet.dwt1d(input, phi, psi, maxlevels)

Calculates the discrete wavelet transform, given the phi and psi functions phi and psi are functions that take the input signal and give out the scaled signal, and the wavelet coefficients respectively.

input - input signal \phi φ(x) - scaling function \psi ψ(x) - wavelet function [maxlevels] - maximum number of levels to recurse