Skip to content

Commit

Permalink
Added TAmplitudeDetector - detects amplitude of a sinus wave with noi…
Browse files Browse the repository at this point in the history
…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
ilvoron committed Apr 22, 2024
1 parent 4c6b7ba commit ff41957
Show file tree
Hide file tree
Showing 20 changed files with 326 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ Mkfile.old
dkms.conf

# [Custom]
build
build
*.bat
4 changes: 2 additions & 2 deletions _build_cmake_make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ echo off
echo Changing directory to "build"
cd build
echo Running CMake
cmake -G "MinGW Makefiles" ..
cmake -G "MSYS Makefiles" ..
echo Running Make
mingw32-make
make
set /p DUMMY=Done. Press ENTER to exit...
2 changes: 1 addition & 1 deletion _build_make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ echo off
echo Changing directory to "build"
cd build
echo Running Make
mingw32-make
make
set /p DUMMY=Done. Press ENTER to exit...
4 changes: 2 additions & 2 deletions _clean_build_cmake_make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mkdir build
echo Changing directory to "build"
cd build
echo Running CMake
cmake -G "MinGW Makefiles" ..
cmake -G "MSYS Makefiles" ..
echo Running Make
mingw32-make
make

set /p DUMMY=Done. Press ENTER to exit...
37 changes: 33 additions & 4 deletions main.cpp
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();*/
}
19 changes: 19 additions & 0 deletions src/analysis/TAmplitudeDetector.cpp
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; }
17 changes: 17 additions & 0 deletions src/analysis/TAmplitudeDetector.h
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
26 changes: 26 additions & 0 deletions src/analysis/TCorrelator.cpp
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; }
18 changes: 18 additions & 0 deletions src/analysis/TCorrelator.h
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
33 changes: 33 additions & 0 deletions src/analysis/TFourierTransform.cpp
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++;
}
}
20 changes: 20 additions & 0 deletions src/analysis/TFourierTransform.h
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
19 changes: 19 additions & 0 deletions src/core/TDerivative.cpp
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);
}
}
16 changes: 16 additions & 0 deletions src/core/TDerivative.h
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
24 changes: 24 additions & 0 deletions src/core/TIntegral.cpp
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; }
20 changes: 20 additions & 0 deletions src/core/TIntegral.h
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
31 changes: 31 additions & 0 deletions src/core/TMultiplier.cpp
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!!!
17 changes: 17 additions & 0 deletions src/core/TMultiplier.h
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
Loading

0 comments on commit ff41957

Please sign in to comment.