Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Crosscorrel.cpp@0:61544337ff5e, 2018-05-03 (annotated)
- Committer:
- gunarthon
- Date:
- Thu May 03 20:39:50 2018 +0000
- Revision:
- 0:61544337ff5e
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| gunarthon | 0:61544337ff5e | 1 | #include "Crosscorrel.h" |
| gunarthon | 0:61544337ff5e | 2 | #include "mbed.h" |
| gunarthon | 0:61544337ff5e | 3 | |
| gunarthon | 0:61544337ff5e | 4 | Crosscorrel::Crosscorrel() |
| gunarthon | 0:61544337ff5e | 5 | { |
| gunarthon | 0:61544337ff5e | 6 | this->tau = 50; |
| gunarthon | 0:61544337ff5e | 7 | } |
| gunarthon | 0:61544337ff5e | 8 | |
| gunarthon | 0:61544337ff5e | 9 | float Crosscorrel::GetMax(SignalBuf &buf, unsigned chA, unsigned chB) |
| gunarthon | 0:61544337ff5e | 10 | { |
| gunarthon | 0:61544337ff5e | 11 | float max = 0; |
| gunarthon | 0:61544337ff5e | 12 | for(int j = -tau; j <= tau; j++) |
| gunarthon | 0:61544337ff5e | 13 | { |
| gunarthon | 0:61544337ff5e | 14 | float correl = 0; |
| gunarthon | 0:61544337ff5e | 15 | |
| gunarthon | 0:61544337ff5e | 16 | for(unsigned t = 0; t < buf.size(); t++) |
| gunarthon | 0:61544337ff5e | 17 | { |
| gunarthon | 0:61544337ff5e | 18 | correl += buf[t][chA] * GetValue(buf, t+j, chB); |
| gunarthon | 0:61544337ff5e | 19 | } |
| gunarthon | 0:61544337ff5e | 20 | printf("%i\n", int(correl)); |
| gunarthon | 0:61544337ff5e | 21 | max = correl > max ? correl : max; |
| gunarthon | 0:61544337ff5e | 22 | } |
| gunarthon | 0:61544337ff5e | 23 | return max; |
| gunarthon | 0:61544337ff5e | 24 | } |
| gunarthon | 0:61544337ff5e | 25 | |
| gunarthon | 0:61544337ff5e | 26 | Crosscorrel::~Crosscorrel() |
| gunarthon | 0:61544337ff5e | 27 | { |
| gunarthon | 0:61544337ff5e | 28 | |
| gunarthon | 0:61544337ff5e | 29 | } |
| gunarthon | 0:61544337ff5e | 30 | |
| gunarthon | 0:61544337ff5e | 31 | float Crosscorrel::GetValue(SignalBuf &buf, int index, unsigned ch) |
| gunarthon | 0:61544337ff5e | 32 | { |
| gunarthon | 0:61544337ff5e | 33 | if(index < 0 || index >= buf.size()) |
| gunarthon | 0:61544337ff5e | 34 | return 0; |
| gunarthon | 0:61544337ff5e | 35 | |
| gunarthon | 0:61544337ff5e | 36 | return buf[index][ch]; |
| gunarthon | 0:61544337ff5e | 37 | } |
