Skip to content

Commit ff41957

Browse files
committed
Added TAmplitudeDetector - detects amplitude of a sinus wave with noizes (using only time, samping frequency and points themselfes of a signal)
Added TAmplitudeDetector - detects amplitude of a sinus wave with noizes (using only time, samping frequency and points themselfes of a signal) Added TCorrelator - detects if two waves are similar in sine frequency and returns amplitude of this as a factor of similarity (using only time, samping frequency and points themselfes of a signal) Added TCorrelator - detects if two waves are similar in sine frequency and returns amplitude of this as a factor of similarity (using only time, samping frequency and points themselfes of a signal) Added TFourierTransform - returns fourier wave (graph where axis x is frequency; y - amplitude) (using only time, samping frequency and points themselfes of a signal) Added TFourierTransform - returns fourier wave (graph where axis x is frequency; y - amplitude) (using only time, samping frequency and points themselfes of a signal) Added TDerivative - returns a derivative wave (has points count less by 1 from original wave) (using only points of the original wave) Added TDerivative - returns a derivative wave (has points count less by 1 from original wave) (using only points of the original wave) Added TIntegral - returns an integral wave (has points count less by 1 from original wave) (using only points of the original wave) Added TIntegral - returns an integral wave (has points count less by 1 from original wave) (using only points of the original wave) Added TMultiplier - multiply tow "similar" waves (using only points of the original waves) Added TMultiplier - multiply tow "similar" waves (using only points of the original waves Some fixes Some fixes Some fixes Global update with new feautures
1 parent 4c6b7ba commit ff41957

20 files changed

+326
-19
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ Mkfile.old
5252
dkms.conf
5353

5454
# [Custom]
55-
build
55+
build
56+
*.bat

_build_cmake_make.bat

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ echo off
22
echo Changing directory to "build"
33
cd build
44
echo Running CMake
5-
cmake -G "MinGW Makefiles" ..
5+
cmake -G "MSYS Makefiles" ..
66
echo Running Make
7-
mingw32-make
7+
make
88
set /p DUMMY=Done. Press ENTER to exit...

_build_make.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ echo off
22
echo Changing directory to "build"
33
cd build
44
echo Running Make
5-
mingw32-make
5+
make
66
set /p DUMMY=Done. Press ENTER to exit...

_clean_build_cmake_make.bat

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ mkdir build
88
echo Changing directory to "build"
99
cd build
1010
echo Running CMake
11-
cmake -G "MinGW Makefiles" ..
11+
cmake -G "MSYS Makefiles" ..
1212
echo Running Make
13-
mingw32-make
13+
make
1414

1515
set /p DUMMY=Done. Press ENTER to exit...

main.cpp

+33-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
11
#include "TFileWriter.h"
2+
#include "TSignalLine.h"
23
#include "TGenerator.h"
34
#include "TSummator.h"
5+
#include "TMultiplier.h"
6+
#include "TDerivative.h"
7+
#include "TIntegral.h"
8+
#include "TAmplitudeDetector.h"
9+
#include "TCorrelator.h"
10+
#include "TFourierTransform.h"
411

512
int main() {
613
// EXAMPLE CODE
714
double time = 3;
8-
double oscillationFreq = 2;
15+
double oscillationFreq = 4.5612;
916
double samplingFreq = 200;
1017
double amplitude = 3.5;
1118
double initPhase = 0;
1219
double offsetY = 0;
1320
TGenerator gen1(time, oscillationFreq, initPhase, offsetY, amplitude, samplingFreq);
14-
TGenerator gen2(time+0.1, oscillationFreq, initPhase, offsetY, amplitude, samplingFreq+5);
21+
TGenerator gen2(time, oscillationFreq*1.66, initPhase, offsetY, amplitude-1, samplingFreq);
1522
gen1.exec();
1623
gen2.exec();
1724
TSummator sum(gen1.sl(), gen2.sl());
1825
sum.exec();
19-
TFileWriter file(sum.sl(), "signal.txt");
20-
file.exec();
26+
TFourierTransform trans(sum.sl(), 0, 10, 0.01);
27+
trans.exec();
28+
TFileWriter file1(trans.sl(), "fourier.txt");
29+
TFileWriter file2(sum.sl(), "signal.txt");
30+
file1.exec();
31+
file2.exec();
32+
/*double time = 3;
33+
double oscillationFreq = 2;
34+
double samplingFreq = 200;
35+
double amplitude = 3.5;
36+
double initPhase = 0;
37+
double offsetY = 0;
38+
TGenerator gen1(time, oscillationFreq, initPhase, offsetY, amplitude, samplingFreq);
39+
TGenerator gen2(time, oscillationFreq / 0.66, initPhase, offsetY, amplitude, samplingFreq+5);
40+
gen1.exec();
41+
gen2.exec();
42+
TMultiplier mult1(gen1.sl(), gen2.sl());
43+
TMultiplier mult2(gen1.sl(), gen1.sl());
44+
mult1.exec();
45+
mult2.exec();
46+
TFileWriter file1(mult1.sl(), "signalDiff.txt");
47+
TFileWriter file2(mult2.sl(), "signalEq.txt");
48+
file1.exec();
49+
file2.exec();*/
2150
}

src/analysis/TAmplitudeDetector.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "TAmplitudeDetector.h"
2+
#include "TSignalLine.h"
3+
#include "TMultiplier.h"
4+
#include "TIntegral.h"
5+
#include <math.h>
6+
7+
TAmplitudeDetector::TAmplitudeDetector(TSignalLine* sl) { _sl = sl; }
8+
9+
void TAmplitudeDetector::exec() {
10+
TMultiplier powerSignalLine(_sl, _sl);
11+
powerSignalLine.exec();
12+
TIntegral energy(powerSignalLine.sl());
13+
energy.exec();
14+
double power = energy.sum() / _sl->time();
15+
double voltage = sqrt(power);
16+
_amplitude = sqrt(2) * voltage;
17+
}
18+
19+
double TAmplitudeDetector::amplitude() const { return _amplitude; }

src/analysis/TAmplitudeDetector.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef TAMPLITUDEDETECTOR_H
2+
#define TAMPLITUDEDETECTOR_H
3+
4+
#include "TSignalLine.h"
5+
6+
class TAmplitudeDetector {
7+
public:
8+
TAmplitudeDetector(TSignalLine* sl);
9+
void exec();
10+
double amplitude() const;
11+
12+
private:
13+
TSignalLine* _sl;
14+
double _amplitude;
15+
};
16+
17+
#endif

src/analysis/TCorrelator.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <math.h>
2+
#include <stdexcept>
3+
#include "TCorrelator.h"
4+
#include "TSignalLine.h"
5+
#include "TMultiplier.h"
6+
#include "TIntegral.h"
7+
8+
TCorrelator::TCorrelator(TSignalLine* sl1, TSignalLine* sl2) {
9+
// TODO: Fix equals (see TSignalLine)
10+
// TODD: Fix error output (text should constant and be stored somewhere)
11+
if (!(sl1->equals(sl2))) { throw std::runtime_error("Signals does not have minimum equal params"); }
12+
_sl1 = sl1;
13+
_sl2 = sl2;
14+
}
15+
16+
void TCorrelator::exec() {
17+
TMultiplier powerSignalLine(_sl1, _sl2);
18+
powerSignalLine.exec();
19+
TIntegral energy(powerSignalLine.sl());
20+
energy.exec();
21+
double power = energy.sum() / _sl1->time();
22+
double voltage = abs(power);
23+
_amplitude = 2 * voltage;
24+
}
25+
26+
double TCorrelator::amplitude() const { return _amplitude; }

src/analysis/TCorrelator.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef TCORRELATOR_H
2+
#define TCORRELATOR_H
3+
4+
#include "TSignalLine.h"
5+
6+
class TCorrelator {
7+
public:
8+
TCorrelator(TSignalLine* sl1, TSignalLine* sl2);
9+
void exec();
10+
double amplitude() const;
11+
12+
private:
13+
TSignalLine* _sl1;
14+
TSignalLine* _sl2;
15+
double _amplitude;
16+
};
17+
18+
#endif

src/analysis/TFourierTransform.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "TFourierTransform.h"
2+
#include "TSignalLine.h"
3+
#include "TMultiplier.h"
4+
#include "TIntegral.h"
5+
#include "TCorrelator.h"
6+
#include "TGenerator.h"
7+
#include <math.h>
8+
#include <stdexcept>
9+
10+
TFourierTransform::TFourierTransform(TSignalLine* sl, double from, double to, double step) {
11+
// TODD: Fix error output (text should constant and be stored somewhere)
12+
// TODO: Should be there an error?
13+
if (from > to) { throw std::runtime_error("From is bigger than to"); }
14+
_from = from;
15+
_to = to;
16+
_step = step;
17+
_sl_in = sl;
18+
_sl_out = new TSignalLine(int((to - from) / step));
19+
}
20+
21+
TSignalLine* TFourierTransform::sl() const { return _sl_out; }
22+
23+
void TFourierTransform::exec() {
24+
unsigned int counter = 0;
25+
for (double i = _from; i < _to; i = i + _step) {
26+
TGenerator gen(_sl_in->time(), i, 0, 0, 1, _sl_in->samplingFreq());
27+
gen.exec();
28+
TCorrelator corr = TCorrelator(_sl_in, gen.sl());
29+
corr.exec();
30+
_sl_out->set(counter, i, corr.amplitude());
31+
counter++;
32+
}
33+
}

src/analysis/TFourierTransform.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef TFOURIERTRANSFORM_H
2+
#define TFOURIERTRANSFORM_H
3+
4+
#include "TSignalLine.h"
5+
6+
class TFourierTransform {
7+
public:
8+
TFourierTransform(TSignalLine* sl, double from, double to, double step);
9+
TSignalLine* sl() const;
10+
void exec();
11+
12+
private:
13+
TSignalLine* _sl_in;
14+
TSignalLine* _sl_out;
15+
double _from;
16+
double _to;
17+
double _step;
18+
};
19+
20+
#endif

src/core/TDerivative.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "TDerivative.h"
2+
#include "TSignalLine.h"
3+
4+
TDerivative::TDerivative(TSignalLine* sl) {
5+
_sl_in = sl;
6+
_sl_out = new TSignalLine(_sl_in->time(), _sl_in->samplingFreq(), _sl_in->pointsCount());
7+
}
8+
9+
TSignalLine* TDerivative::sl() const { return _sl_out; }
10+
11+
void TDerivative::exec() {
12+
unsigned int pointsCount = _sl_out->pointsCount();
13+
double dx, dy;
14+
for (int i = 0; i < pointsCount; i++) {
15+
dy = (_sl_in->at(i+1)).y - (_sl_in->at(i)).y;
16+
dx = (_sl_in->at(i+1)).x - (_sl_in->at(i)).x;
17+
_sl_out->set(i, (_sl_in->at(i)).x, dy/dx);
18+
}
19+
}

src/core/TDerivative.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef TDERIVATIVE_H
2+
#define TDERIVATIVE_H
3+
4+
#include "TSignalLine.h"
5+
6+
class TDerivative {
7+
public:
8+
TDerivative(TSignalLine* sl);
9+
TSignalLine* sl() const;
10+
void exec();
11+
private:
12+
TSignalLine* _sl_in;
13+
TSignalLine* _sl_out;
14+
};
15+
16+
#endif

src/core/TIntegral.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "TIntegral.h"
2+
#include "TSignalLine.h"
3+
4+
TIntegral::TIntegral(TSignalLine* sl) {
5+
_sl_in = sl;
6+
_sl_out = new TSignalLine(_sl_in->time(), _sl_in->samplingFreq(), _sl_in->pointsCount());
7+
_sum = 0;
8+
}
9+
10+
TSignalLine* TIntegral::sl() const { return _sl_out; }
11+
12+
void TIntegral::exec() {
13+
unsigned int pointsCount = _sl_out->pointsCount();
14+
double x1, x2, y, sum;
15+
for (int i = 1; i < pointsCount; i++) {
16+
x1 = (_sl_in->at(i-1)).x;
17+
x2 = (_sl_in->at(i)).x;
18+
y = (_sl_in->at(i)).y;
19+
_sum += y * (x2 - x1);
20+
_sl_out->set(i, (_sl_in->at(i)).x, _sum);
21+
}
22+
}
23+
24+
double TIntegral::sum() const { return _sum; }

src/core/TIntegral.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef TINTEGRAL_H
2+
#define TINTEGRAL_H
3+
4+
#include "TIntegral.h"
5+
#include "TSignalLine.h"
6+
7+
class TIntegral {
8+
public:
9+
TIntegral(TSignalLine* sl);
10+
TSignalLine* sl() const;
11+
void exec();
12+
double sum() const;
13+
14+
private:
15+
TSignalLine* _sl_in;
16+
TSignalLine* _sl_out;
17+
double _sum;
18+
};
19+
20+
#endif

src/core/TMultiplier.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <stdexcept>
2+
#include "TMultiplier.h"
3+
#include "TSignalLine.h"
4+
5+
// ************
6+
// PUBLIC
7+
// ************
8+
9+
TMultiplier::TMultiplier(TSignalLine* sl1, TSignalLine* sl2) {
10+
// TODO: Fix equals (see TSignalLine)
11+
// TODD: Fix error output
12+
if (!(sl1->equals(sl2))) { throw std::runtime_error("Signals does not have minimum equal params"); }
13+
_sl1 = sl1;
14+
_sl2 = sl2;
15+
_sl = new TSignalLine(sl1->time(), sl1->samplingFreq());
16+
}
17+
18+
TSignalLine* TMultiplier::sl() const { return _sl; }
19+
20+
void TMultiplier::exec() {
21+
unsigned int pointsCount = _sl->pointsCount();
22+
double x, y;
23+
for (int i = 0; i < pointsCount; i++) {
24+
// TODO: After fix equls use approx. value for x (if it needs)
25+
x = (_sl1->at(i)).x;
26+
y = (_sl1->at(i)).y * (_sl2->at(i)).y;
27+
_sl->set(i, x, y);
28+
}
29+
}
30+
31+
// TODO: Deserializer everywhere???? OR INIT USING CONSTUCTOR!!!

src/core/TMultiplier.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef TMULTIPLIER_H
2+
#define TMULTIPLIER_H
3+
4+
#include "TSignalLine.h"
5+
6+
class TMultiplier {
7+
public:
8+
TMultiplier(TSignalLine* sl1, TSignalLine* sl2);
9+
TSignalLine *sl() const;
10+
void exec();
11+
private:
12+
TSignalLine* _sl;
13+
TSignalLine* _sl1;
14+
TSignalLine* _sl2;
15+
};
16+
17+
#endif

0 commit comments

Comments
 (0)