![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Spectrum analyzer using DISCO-F746NG. Spectrum is calculated by FFT or linear prediction. The vowel data is in "vowel_data.hpp"
Dependencies: BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG UIT_FFT_Real mbed BUTTON_GROUP
SpactrumAnalysisClasses/Hamming.hpp@6:f385940fbdb1, 2018-10-09 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Tue Oct 09 10:34:47 2018 +0000
- Revision:
- 6:f385940fbdb1
- Parent:
- 0:c35b8a23a863
7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:c35b8a23a863 | 1 | //------------------------------------------------------------------- |
MikamiUitOpen | 0:c35b8a23a863 | 2 | // Hamming windowing with zero-padding |
MikamiUitOpen | 0:c35b8a23a863 | 3 | // Copyright (c) 2014 MIKAMI, Naoki, 2014/12/21 |
MikamiUitOpen | 0:c35b8a23a863 | 4 | //------------------------------------------------------------------- |
MikamiUitOpen | 0:c35b8a23a863 | 5 | |
MikamiUitOpen | 0:c35b8a23a863 | 6 | #ifndef HAMMING_WINDOW_HPP |
MikamiUitOpen | 0:c35b8a23a863 | 7 | #define HAMMING_WINDOW_HPP |
MikamiUitOpen | 0:c35b8a23a863 | 8 | |
MikamiUitOpen | 0:c35b8a23a863 | 9 | #include "mbed.h" |
MikamiUitOpen | 0:c35b8a23a863 | 10 | |
MikamiUitOpen | 0:c35b8a23a863 | 11 | namespace Mikami |
MikamiUitOpen | 0:c35b8a23a863 | 12 | { |
MikamiUitOpen | 0:c35b8a23a863 | 13 | class HammingWindow |
MikamiUitOpen | 0:c35b8a23a863 | 14 | { |
MikamiUitOpen | 0:c35b8a23a863 | 15 | private: |
MikamiUitOpen | 0:c35b8a23a863 | 16 | const int N_; |
MikamiUitOpen | 0:c35b8a23a863 | 17 | const int NFFT_; |
MikamiUitOpen | 0:c35b8a23a863 | 18 | |
MikamiUitOpen | 0:c35b8a23a863 | 19 | float* w_; |
MikamiUitOpen | 0:c35b8a23a863 | 20 | |
MikamiUitOpen | 0:c35b8a23a863 | 21 | public: |
MikamiUitOpen | 0:c35b8a23a863 | 22 | // Constructor |
MikamiUitOpen | 0:c35b8a23a863 | 23 | HammingWindow(uint16_t nData, uint16_t nFft) |
MikamiUitOpen | 0:c35b8a23a863 | 24 | : N_(nData), NFFT_(nFft) |
MikamiUitOpen | 0:c35b8a23a863 | 25 | { |
MikamiUitOpen | 0:c35b8a23a863 | 26 | w_ = new float[nData]; |
MikamiUitOpen | 0:c35b8a23a863 | 27 | float pi2L = 6.283185f/(float)nData; |
MikamiUitOpen | 0:c35b8a23a863 | 28 | for (int k=0; k<nData; k++) |
MikamiUitOpen | 0:c35b8a23a863 | 29 | w_[k] = 0.54f - 0.46f*cosf(k*pi2L); |
MikamiUitOpen | 0:c35b8a23a863 | 30 | } |
MikamiUitOpen | 0:c35b8a23a863 | 31 | |
MikamiUitOpen | 0:c35b8a23a863 | 32 | // Destructor |
MikamiUitOpen | 0:c35b8a23a863 | 33 | ~HammingWindow() {delete[] w_;} |
MikamiUitOpen | 0:c35b8a23a863 | 34 | |
MikamiUitOpen | 0:c35b8a23a863 | 35 | // Windowing |
MikamiUitOpen | 0:c35b8a23a863 | 36 | void Execute(const float x[], float y[]) |
MikamiUitOpen | 0:c35b8a23a863 | 37 | { |
MikamiUitOpen | 0:c35b8a23a863 | 38 | for (int n=0; n<N_; n++) y[n] = x[n]*w_[n]; |
MikamiUitOpen | 0:c35b8a23a863 | 39 | for (int n=N_; n<NFFT_; n++) y[n] = 0; |
MikamiUitOpen | 0:c35b8a23a863 | 40 | } |
MikamiUitOpen | 0:c35b8a23a863 | 41 | }; |
MikamiUitOpen | 0:c35b8a23a863 | 42 | } |
MikamiUitOpen | 0:c35b8a23a863 | 43 | #endif // HAMMING_WINDOW_HPP |
MikamiUitOpen | 0:c35b8a23a863 | 44 |