libtfr
Multi-taper time-frequency reassignment spectrograms
tfr.h
Go to the documentation of this file.
1
57#ifndef _LIBTFR_H
58#define _LIBTFR_H
59
60/* keep in step with [project] version in pyproject.toml, which is the
61 single source of truth; the python module reads it from package
62 metadata, but a C header has no way to do that */
63#define LIBTFR_VERSION "2.2.0"
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
80typedef double cmplx_t[2];
81
85typedef struct mfft_s mfft;
86
87/* initialization and destruction functions */
88
99mfft * mtm_init(int nfft, int npoints, int ntapers);
100
111mfft * mtm_init_dpss(int nfft, int npoints, double nw, int ntapers);
112
123mfft * mtm_init_herm(int nfft, int npoints, int order, double tm);
124
134void mtm_copy(mfft * mtmh, const double * tapers, const double * weights);
135
145void mtm_destroy(mfft * mtm);
146
147/* utility functions */
148
149int mtm_nfft(mfft const * mtm);
150int mtm_npoints(mfft const * mtm);
151int mtm_ntapers(mfft const * mtm);
152int mtm_nreal(mfft const * mtm);
153int mtm_nframes(mfft const * mtm, int signal_size, int step_size);
154double const * mtm_buffer(mfft const * mtm);
155double const * mtm_tapers(mfft const * mtm);
156
157
158/* transformation functions */
159
170void mtm_tapers_fft(mfft * mtm, double scale);
171
187void mtm_tapers_interp(mfft const * mtm, double * out, double const * times,
188 int ntimes, double t0, double dt);
189
204double mtfft(mfft * mtm, double const * data, int nbins);
205
206/* spectrogram functions */
207
220void mtpower(mfft const * mtm, double * pow, double sigpow);
221
222
230void mtcomplex(mfft const * mtm, cmplx_t * out);
231
246void mtm_spec(mfft * mtm, double * spec, const double *samples, int nsamples, int shift,
247 int adapt);
248
262void mtm_zspec(mfft * mtm, cmplx_t *spec, const double *samples, int nsamples,
263 int shift);
264
285void tfr_spec(mfft * mtm, double *spec, const double *samples, int nsamples, int k,
286 int shift, double flock, int tlock, int nfreq, const double *fgrid);
287
288/* taper generating functions */
289
306int dpss(double *tapers, double *lambda, int npoints, double nw, int k);
307
324int hermf(int N, int M, double tm, double *h, double *Dh, double *Th);
325
326/* reassignment functions */
327
338void tfr_displacements(mfft const * mtm, double *q, double *tdispl, double *fdispl);
339
375void tfr_reassign(double *spec, const double *q, const double *tdispl, const double *fdispl,
376 int N, int nfreq, const double *fgrid,
377 double dt, double qthresh, double flock, int tminlock, int tmaxlock);
378
379#ifdef __cplusplus
380}
381#endif
382
383#endif
void mtm_copy(mfft *mtmh, const double *tapers, const double *weights)
Copy pre-calculated tapers/window functions (e.g.
void mtm_zspec(mfft *mtm, cmplx_t *spec, const double *samples, int nsamples, int shift)
Compute a multitaper complex spectrogram by stepping through a signal.
struct mfft_s mfft
Opaque pointer type for multitaper fft transforms.
Definition tfr.h:85
int mtm_nframes(mfft const *mtm, int signal_size, int step_size)
mfft * mtm_init(int nfft, int npoints, int ntapers)
Initialize a multitaper mtm transform and allocate memory for tapers/window functions.
void tfr_displacements(mfft const *mtm, double *q, double *tdispl, double *fdispl)
Compute the power spectrum and the time/frequency displacement.
mfft * mtm_init_herm(int nfft, int npoints, int order, double tm)
Initialize mtfft transform for reassigned spectrogram (i.e.
void mtpower(mfft const *mtm, double *pow, double sigpow)
Extract power spectrum from multiple taper FFT.
int hermf(int N, int M, double tm, double *h, double *Dh, double *Th)
Computes a set of orthogonal Hermite functions.
double const * mtm_tapers(mfft const *mtm)
double cmplx_t[2]
An interleaved real/imaginary pair: [0] is the real part, [1] the imaginary.
Definition tfr.h:80
void mtcomplex(mfft const *mtm, cmplx_t *out)
Extract complex multitaper transform of signal from transform object.
void tfr_reassign(double *spec, const double *q, const double *tdispl, const double *fdispl, int N, int nfreq, const double *fgrid, double dt, double qthresh, double flock, int tminlock, int tmaxlock)
Assign power from a spectrum to a spectrogram based on time-frequency displacements.
void mtm_tapers_interp(mfft const *mtm, double *out, double const *times, int ntimes, double t0, double dt)
Compute interpolation of tapers.
mfft * mtm_init_dpss(int nfft, int npoints, double nw, int ntapers)
Initialize a mtfft transform using DPSS tapers (i.e.
double mtfft(mfft *mtm, double const *data, int nbins)
Compute multitaper FFT of a real-valued signal.
int mtm_npoints(mfft const *mtm)
int mtm_ntapers(mfft const *mtm)
void tfr_spec(mfft *mtm, double *spec, const double *samples, int nsamples, int k, int shift, double flock, int tlock, int nfreq, const double *fgrid)
Compute a time-frequency reassignment spectrogram by stepping through a signal.
void mtm_destroy(mfft *mtm)
Frees up the mfft structure and dependent data.
void mtm_spec(mfft *mtm, double *spec, const double *samples, int nsamples, int shift, int adapt)
Compute a multitaper spectrogram by stepping through a signal.
void mtm_tapers_fft(mfft *mtm, double scale)
Compute FFT of the tapers.
int dpss(double *tapers, double *lambda, int npoints, double nw, int k)
Computes discrete prolate spherical sequences.
int mtm_nreal(mfft const *mtm)
int mtm_nfft(mfft const *mtm)
double const * mtm_buffer(mfft const *mtm)