-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TAmplitudeDetector - detects amplitude of a sinus wave with noi…
…zes (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
- Loading branch information
Showing
20 changed files
with
326 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,4 +52,5 @@ Mkfile.old | |
dkms.conf | ||
|
||
# [Custom] | ||
build | ||
build | ||
*.bat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,50 @@ | ||
#include "TFileWriter.h" | ||
#include "TSignalLine.h" | ||
#include "TGenerator.h" | ||
#include "TSummator.h" | ||
#include "TMultiplier.h" | ||
#include "TDerivative.h" | ||
#include "TIntegral.h" | ||
#include "TAmplitudeDetector.h" | ||
#include "TCorrelator.h" | ||
#include "TFourierTransform.h" | ||
|
||
int main() { | ||
// EXAMPLE CODE | ||
double time = 3; | ||
double oscillationFreq = 2; | ||
double oscillationFreq = 4.5612; | ||
double samplingFreq = 200; | ||
double amplitude = 3.5; | ||
double initPhase = 0; | ||
double offsetY = 0; | ||
TGenerator gen1(time, oscillationFreq, initPhase, offsetY, amplitude, samplingFreq); | ||
TGenerator gen2(time+0.1, oscillationFreq, initPhase, offsetY, amplitude, samplingFreq+5); | ||
TGenerator gen2(time, oscillationFreq*1.66, initPhase, offsetY, amplitude-1, samplingFreq); | ||
gen1.exec(); | ||
gen2.exec(); | ||
TSummator sum(gen1.sl(), gen2.sl()); | ||
sum.exec(); | ||
TFileWriter file(sum.sl(), "signal.txt"); | ||
file.exec(); | ||
TFourierTransform trans(sum.sl(), 0, 10, 0.01); | ||
trans.exec(); | ||
TFileWriter file1(trans.sl(), "fourier.txt"); | ||
TFileWriter file2(sum.sl(), "signal.txt"); | ||
file1.exec(); | ||
file2.exec(); | ||
/*double time = 3; | ||
double oscillationFreq = 2; | ||
double samplingFreq = 200; | ||
double amplitude = 3.5; | ||
double initPhase = 0; | ||
double offsetY = 0; | ||
TGenerator gen1(time, oscillationFreq, initPhase, offsetY, amplitude, samplingFreq); | ||
TGenerator gen2(time, oscillationFreq / 0.66, initPhase, offsetY, amplitude, samplingFreq+5); | ||
gen1.exec(); | ||
gen2.exec(); | ||
TMultiplier mult1(gen1.sl(), gen2.sl()); | ||
TMultiplier mult2(gen1.sl(), gen1.sl()); | ||
mult1.exec(); | ||
mult2.exec(); | ||
TFileWriter file1(mult1.sl(), "signalDiff.txt"); | ||
TFileWriter file2(mult2.sl(), "signalEq.txt"); | ||
file1.exec(); | ||
file2.exec();*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "TAmplitudeDetector.h" | ||
#include "TSignalLine.h" | ||
#include "TMultiplier.h" | ||
#include "TIntegral.h" | ||
#include <math.h> | ||
|
||
TAmplitudeDetector::TAmplitudeDetector(TSignalLine* sl) { _sl = sl; } | ||
|
||
void TAmplitudeDetector::exec() { | ||
TMultiplier powerSignalLine(_sl, _sl); | ||
powerSignalLine.exec(); | ||
TIntegral energy(powerSignalLine.sl()); | ||
energy.exec(); | ||
double power = energy.sum() / _sl->time(); | ||
double voltage = sqrt(power); | ||
_amplitude = sqrt(2) * voltage; | ||
} | ||
|
||
double TAmplitudeDetector::amplitude() const { return _amplitude; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef TAMPLITUDEDETECTOR_H | ||
#define TAMPLITUDEDETECTOR_H | ||
|
||
#include "TSignalLine.h" | ||
|
||
class TAmplitudeDetector { | ||
public: | ||
TAmplitudeDetector(TSignalLine* sl); | ||
void exec(); | ||
double amplitude() const; | ||
|
||
private: | ||
TSignalLine* _sl; | ||
double _amplitude; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <math.h> | ||
#include <stdexcept> | ||
#include "TCorrelator.h" | ||
#include "TSignalLine.h" | ||
#include "TMultiplier.h" | ||
#include "TIntegral.h" | ||
|
||
TCorrelator::TCorrelator(TSignalLine* sl1, TSignalLine* sl2) { | ||
// TODO: Fix equals (see TSignalLine) | ||
// TODD: Fix error output (text should constant and be stored somewhere) | ||
if (!(sl1->equals(sl2))) { throw std::runtime_error("Signals does not have minimum equal params"); } | ||
_sl1 = sl1; | ||
_sl2 = sl2; | ||
} | ||
|
||
void TCorrelator::exec() { | ||
TMultiplier powerSignalLine(_sl1, _sl2); | ||
powerSignalLine.exec(); | ||
TIntegral energy(powerSignalLine.sl()); | ||
energy.exec(); | ||
double power = energy.sum() / _sl1->time(); | ||
double voltage = abs(power); | ||
_amplitude = 2 * voltage; | ||
} | ||
|
||
double TCorrelator::amplitude() const { return _amplitude; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef TCORRELATOR_H | ||
#define TCORRELATOR_H | ||
|
||
#include "TSignalLine.h" | ||
|
||
class TCorrelator { | ||
public: | ||
TCorrelator(TSignalLine* sl1, TSignalLine* sl2); | ||
void exec(); | ||
double amplitude() const; | ||
|
||
private: | ||
TSignalLine* _sl1; | ||
TSignalLine* _sl2; | ||
double _amplitude; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "TFourierTransform.h" | ||
#include "TSignalLine.h" | ||
#include "TMultiplier.h" | ||
#include "TIntegral.h" | ||
#include "TCorrelator.h" | ||
#include "TGenerator.h" | ||
#include <math.h> | ||
#include <stdexcept> | ||
|
||
TFourierTransform::TFourierTransform(TSignalLine* sl, double from, double to, double step) { | ||
// TODD: Fix error output (text should constant and be stored somewhere) | ||
// TODO: Should be there an error? | ||
if (from > to) { throw std::runtime_error("From is bigger than to"); } | ||
_from = from; | ||
_to = to; | ||
_step = step; | ||
_sl_in = sl; | ||
_sl_out = new TSignalLine(int((to - from) / step)); | ||
} | ||
|
||
TSignalLine* TFourierTransform::sl() const { return _sl_out; } | ||
|
||
void TFourierTransform::exec() { | ||
unsigned int counter = 0; | ||
for (double i = _from; i < _to; i = i + _step) { | ||
TGenerator gen(_sl_in->time(), i, 0, 0, 1, _sl_in->samplingFreq()); | ||
gen.exec(); | ||
TCorrelator corr = TCorrelator(_sl_in, gen.sl()); | ||
corr.exec(); | ||
_sl_out->set(counter, i, corr.amplitude()); | ||
counter++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef TFOURIERTRANSFORM_H | ||
#define TFOURIERTRANSFORM_H | ||
|
||
#include "TSignalLine.h" | ||
|
||
class TFourierTransform { | ||
public: | ||
TFourierTransform(TSignalLine* sl, double from, double to, double step); | ||
TSignalLine* sl() const; | ||
void exec(); | ||
|
||
private: | ||
TSignalLine* _sl_in; | ||
TSignalLine* _sl_out; | ||
double _from; | ||
double _to; | ||
double _step; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "TDerivative.h" | ||
#include "TSignalLine.h" | ||
|
||
TDerivative::TDerivative(TSignalLine* sl) { | ||
_sl_in = sl; | ||
_sl_out = new TSignalLine(_sl_in->time(), _sl_in->samplingFreq(), _sl_in->pointsCount()); | ||
} | ||
|
||
TSignalLine* TDerivative::sl() const { return _sl_out; } | ||
|
||
void TDerivative::exec() { | ||
unsigned int pointsCount = _sl_out->pointsCount(); | ||
double dx, dy; | ||
for (int i = 0; i < pointsCount; i++) { | ||
dy = (_sl_in->at(i+1)).y - (_sl_in->at(i)).y; | ||
dx = (_sl_in->at(i+1)).x - (_sl_in->at(i)).x; | ||
_sl_out->set(i, (_sl_in->at(i)).x, dy/dx); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef TDERIVATIVE_H | ||
#define TDERIVATIVE_H | ||
|
||
#include "TSignalLine.h" | ||
|
||
class TDerivative { | ||
public: | ||
TDerivative(TSignalLine* sl); | ||
TSignalLine* sl() const; | ||
void exec(); | ||
private: | ||
TSignalLine* _sl_in; | ||
TSignalLine* _sl_out; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "TIntegral.h" | ||
#include "TSignalLine.h" | ||
|
||
TIntegral::TIntegral(TSignalLine* sl) { | ||
_sl_in = sl; | ||
_sl_out = new TSignalLine(_sl_in->time(), _sl_in->samplingFreq(), _sl_in->pointsCount()); | ||
_sum = 0; | ||
} | ||
|
||
TSignalLine* TIntegral::sl() const { return _sl_out; } | ||
|
||
void TIntegral::exec() { | ||
unsigned int pointsCount = _sl_out->pointsCount(); | ||
double x1, x2, y, sum; | ||
for (int i = 1; i < pointsCount; i++) { | ||
x1 = (_sl_in->at(i-1)).x; | ||
x2 = (_sl_in->at(i)).x; | ||
y = (_sl_in->at(i)).y; | ||
_sum += y * (x2 - x1); | ||
_sl_out->set(i, (_sl_in->at(i)).x, _sum); | ||
} | ||
} | ||
|
||
double TIntegral::sum() const { return _sum; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef TINTEGRAL_H | ||
#define TINTEGRAL_H | ||
|
||
#include "TIntegral.h" | ||
#include "TSignalLine.h" | ||
|
||
class TIntegral { | ||
public: | ||
TIntegral(TSignalLine* sl); | ||
TSignalLine* sl() const; | ||
void exec(); | ||
double sum() const; | ||
|
||
private: | ||
TSignalLine* _sl_in; | ||
TSignalLine* _sl_out; | ||
double _sum; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <stdexcept> | ||
#include "TMultiplier.h" | ||
#include "TSignalLine.h" | ||
|
||
// ************ | ||
// PUBLIC | ||
// ************ | ||
|
||
TMultiplier::TMultiplier(TSignalLine* sl1, TSignalLine* sl2) { | ||
// TODO: Fix equals (see TSignalLine) | ||
// TODD: Fix error output | ||
if (!(sl1->equals(sl2))) { throw std::runtime_error("Signals does not have minimum equal params"); } | ||
_sl1 = sl1; | ||
_sl2 = sl2; | ||
_sl = new TSignalLine(sl1->time(), sl1->samplingFreq()); | ||
} | ||
|
||
TSignalLine* TMultiplier::sl() const { return _sl; } | ||
|
||
void TMultiplier::exec() { | ||
unsigned int pointsCount = _sl->pointsCount(); | ||
double x, y; | ||
for (int i = 0; i < pointsCount; i++) { | ||
// TODO: After fix equls use approx. value for x (if it needs) | ||
x = (_sl1->at(i)).x; | ||
y = (_sl1->at(i)).y * (_sl2->at(i)).y; | ||
_sl->set(i, x, y); | ||
} | ||
} | ||
|
||
// TODO: Deserializer everywhere???? OR INIT USING CONSTUCTOR!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef TMULTIPLIER_H | ||
#define TMULTIPLIER_H | ||
|
||
#include "TSignalLine.h" | ||
|
||
class TMultiplier { | ||
public: | ||
TMultiplier(TSignalLine* sl1, TSignalLine* sl2); | ||
TSignalLine *sl() const; | ||
void exec(); | ||
private: | ||
TSignalLine* _sl; | ||
TSignalLine* _sl1; | ||
TSignalLine* _sl2; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.