Mercurial > hg > qm-dsp
changeset 357:650bbacf8288
Add forwardMagnitude
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Tue, 15 Oct 2013 18:26:38 +0100 |
parents | 42d416af5030 |
children | 7a225d665ed2 |
files | dsp/phasevocoder/PhaseVocoder.h dsp/transforms/FFT.cpp dsp/transforms/FFT.h |
diffstat | 3 files changed, 34 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/dsp/phasevocoder/PhaseVocoder.h Tue Oct 15 11:52:00 2013 +0100 +++ b/dsp/phasevocoder/PhaseVocoder.h Tue Oct 15 18:26:38 2013 +0100 @@ -21,7 +21,6 @@ class PhaseVocoder { public: - //!!! review: size must be a power of two, or not? PhaseVocoder(int size, int hop); virtual ~PhaseVocoder();
--- a/dsp/transforms/FFT.cpp Tue Oct 15 11:52:00 2013 +0100 +++ b/dsp/transforms/FFT.cpp Tue Oct 15 18:26:38 2013 +0100 @@ -132,6 +132,19 @@ } } + void forwardMagnitude(const double *ri, double *mo) { + + double *io = new double[m_n]; + + forward(ri, mo, io); + + for (int i = 0; i < m_n; ++i) { + mo[i] = sqrt(mo[i] * mo[i] + io[i] * io[i]); + } + + delete[] io; + } + void inverse(const double *ri, const double *ii, double *ro) { for (int i = 0; i < m_n; ++i) { @@ -172,6 +185,12 @@ } void +FFTReal::forwardMagnitude(const double *ri, double *mo) +{ + m_d->forwardMagnitude(ri, mo); +} + +void FFTReal::inverse(const double *ri, const double *ii, double *ro) { m_d->inverse(ri, ii, ro);
--- a/dsp/transforms/FFT.h Tue Oct 15 11:52:00 2013 +0100 +++ b/dsp/transforms/FFT.h Tue Oct 15 18:26:38 2013 +0100 @@ -49,8 +49,9 @@ /** * Construct an FFT object to carry out real-to-complex transforms * of size nsamples. nsamples does not have to be a power of two, - * but it does have to be even. (A std::invalid_argument exception - * will be thrown if nsamples is odd.) + * but it does have to be even. (Use the complex-complex FFT above + * if you need an odd FFT size. This constructor will throw + * std::invalid_argument if nsamples is odd.) */ FFTReal(int nsamples); ~FFTReal(); @@ -68,6 +69,18 @@ double *realOut, double *imagOut); /** + * Carry out a forward real-to-complex transform of size nsamples, + * where nsamples is the value provided to the constructor + * above. Return only the magnitudes of the complex output values. + * + * realIn and magOut must point to (enough space for) nsamples + * values. For consistency with the FFT class above, and + * compatibility with existing code, the conjugate half of the + * output is returned even though it is redundant. + */ + void forwardMagnitude(const double *realIn, double *magOut); + + /** * Carry out an inverse real transform (i.e. complex-to-real) of * size nsamples, where nsamples is the value provided to the * constructor above.