STATUS: unstable Time-Frequency representation of time-series. More...
#include "definitions.h"#include "complex.h"#include "array.h"#include "optarg.h"#include <math.h>
Go to the source code of this file.
| Data Structures | |
| struct | Spectrogram | 
| Complex spectrogram (Time-Frequency-Representation) of a signal.  More... | |
| Typedefs | |
| typedef Array *(* | WindowFunction )(int, double) | 
| A Window Function. | |
| Functions | |
| Spectrogram * | spectrogram (const Array *sig, Spectrogram *spectgram, OptArgList *optargs) | 
| Easy interface for spectrogram calculation. | |
| void | spectrogram_free (Spectrogram *s) | 
| Free memory associated with Spectrogram. | |
| Spectrogram * | spectrogram_init (int N_freq, int N_time) | 
| Initialize Spectrogram. | |
| Array * | spectrogram_powerspectrum (const Spectrogram *spect) | 
| Calculate the powerspectrum for a Spectrogram. | |
| Spectrogram * | spectrogram_stft (const Array *sig, double sampling_rate, const Array *Window, int N_freq, int N_time, double corner_freqs[2], int *timepoints, Spectrogram *spectgram) | 
| Calculate spectrogram of a signal (using STFT). | |
| Array * | window_dirichlet (int n, double noparam) | 
| Dirichlet (Rectangular) window. | |
| Array * | window_gaussian (int n, double sigma) | 
| Gaussian window. | |
| Array * | window_hamming (int n, double noparam) | 
| Hamming window. | |
| Array * | window_hanning (int n, double noparam) | 
| Hanning (Hann) window. | |
| Array * | window_kaiser (int n, double alpha) | 
| Kaiser Window. | |
STATUS: unstable Time-Frequency representation of time-series.
A time-frequency represenation (TFR) of a signal displays the varying frequency content of a signal over time.
 
Definition in file time_frequency.h.
| typedef Array*(* WindowFunction)(int, double) | 
A Window Function.
| n | is the number of points in the window | |
| param | is a parameter depending on the choice of the window (e.g. sigma for gaussian) | 
Definition at line 51 of file time_frequency.h.
| Spectrogram* spectrogram | ( | const Array * | sig, | |
| Spectrogram * | spectgram, | |||
| OptArgList * | optargs | |||
| ) | 
Easy interface for spectrogram calculation.
| sig | - data to be spectrogrammified (1D DOUBLE array) | |
| spectgram | - if NULL, own memory is alloated, else use this pointer. | |
| optargs | may contain: 
 | 
Definition at line 38 of file time_frequency.c.
| void spectrogram_free | ( | Spectrogram * | s | ) | 
Free memory associated with Spectrogram.
Definition at line 302 of file time_frequency.c.
| Spectrogram* spectrogram_init | ( | int | N_freq, | |
| int | N_time | |||
| ) | 
Initialize Spectrogram.
| N_freq | resolution (number of points) in frequency | |
| N_time | resolution in time | 
Definition at line 282 of file time_frequency.c.
| Array* spectrogram_powerspectrum | ( | const Spectrogram * | s | ) | 
Calculate the powerspectrum for a Spectrogram.
Returns a s->N_time x s->N_freq matrix the absolute value squared of the complex numbers in spectrogram.
| s | - the spectrogram | 
Definition at line 264 of file time_frequency.c.
| Spectrogram* spectrogram_stft | ( | const Array * | sig, | |
| double | sampling_rate, | |||
| const Array * | Window, | |||
| int | N_freq, | |||
| int | N_time, | |||
| double | corner_freqs[2], | |||
| int * | timepoints, | |||
| Spectrogram * | spectgram | |||
| ) | 
Calculate spectrogram of a signal (using STFT).
This function is inspired by (read: 'was shamelessly ripped of from') the TIME-FREQUENCY TOOLBOX by Emmanuel Roy - Manuel DAVY (http://www-lagis.univ-lille1.fr/~davy/toolbox/Ctftbeng.html) It's a bit more efficient and uses different storage formats. It doesn't work on complex signals.
THE ALGORITHM
Given a signal to analyze in time and frequency, computes the Short Time Fourier Transform (STFT) :
![\[ {STFT}(t,f) = \int x(s)h(t-s)e^{-2i\pi f s} ds \]](form_73.png) 
This function is complex valued. Its computation requires a window, which can be computed with one of the window_*() functions.
| sig | - data to be spectrogrammified (1D DOUBLE array) | |
| sampling_rate | - sampling frequency of signal | |
| window | - window for calculating the STFT (1D DOUBLE Array); get from window_*() functions | |
| N_freq | - number of frequency bins = number of rows in the TFR matrix (the next power of 2 is chosen for N_freq) | |
| N_time | - number of cols in the TFR matrix | |
| corner_freqs | - corner frequencies (lower, upper) for the returned spectrum at each time-sample in Hz; maximal would be {0, srate/2} | |
| timepoints | compute the spectrogram at selected time-points; this array is N_time long | |
| spectgram | - if NULL, own memory is alloated, else use this pointer. | 
Definition at line 144 of file time_frequency.c.
| Array* window_dirichlet | ( | int | n, | |
| double | noparam | |||
| ) | 
Dirichlet (Rectangular) window.
![\[ w(x) = 1; \]](form_74.png) 
| n | - ODD number for window (else it is incremented by one) | |
| noparam | ignored (just for comparability to WindowFunction) | 
Definition at line 323 of file time_frequency.c.
| Array* window_gaussian | ( | int | n, | |
| double | sigma | |||
| ) | 
Gaussian window.
![\[ w(n) = e^{-\frac{1}{2}\left( \frac{n-(N-1)/2}{\sigma(N-1)/2}\right)^2 } \]](form_75.png) 
 with
| n | - ODD number for window (else it is incremented by one) | |
| sigma | - gaussian std | 
Definition at line 349 of file time_frequency.c.
| Array* window_hamming | ( | int | n, | |
| double | noparam | |||
| ) | 
Hamming window.
![\[ w(n) = 0.53836 - 0.46164 \cos\left( \frac{2\pi n}{N-1}\right) \]](form_77.png) 
| n | - ODD number for window (else it is incremented by one) | |
| noparam | ignored (just for comparability to WindowFunction) | 
Definition at line 374 of file time_frequency.c.
| Array* window_hanning | ( | int | n, | |
| double | noparam | |||
| ) | 
Hanning (Hann) window.
![\[ w(n) = 0.5\left(1- \cos\left( \frac{2\pi n}{N-1}\right)\right) \]](form_78.png) 
| n | - ODD number for window (else it is incremented by one) | |
| noparam | ignored (just for comparability to WindowFunction) | 
Definition at line 399 of file time_frequency.c.
| Array* window_kaiser | ( | int | n, | |
| double | alpha | |||
| ) | 
Kaiser Window.
http://en.wikipedia.org/wiki/Kaiser_window
| n | - ODD number for window (else it is incremented by one) | |
| alpha | - parameter for window's steepness | 
Definition at line 423 of file time_frequency.c.
 1.7.0
 1.7.0