-
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 basic functional: generate and export signal (sine wave)
- Loading branch information
Showing
14 changed files
with
312 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Prerequisites | ||
*.d | ||
|
||
# Object files | ||
*.o | ||
*.ko | ||
*.obj | ||
*.elf | ||
|
||
# Linker output | ||
*.ilk | ||
*.map | ||
*.exp | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Libraries | ||
*.lib | ||
# *.a | ||
*.la | ||
*.lo | ||
|
||
# Shared objects (inc. Windows DLLs) | ||
*.dll | ||
*.so | ||
*.so.* | ||
*.dylib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
*.i*86 | ||
*.x86_64 | ||
*.hex | ||
|
||
# Debug files | ||
*.dSYM/ | ||
*.su | ||
*.idb | ||
*.pdb | ||
|
||
# Kernel Module Compile Results | ||
*.mod* | ||
*.cmd | ||
.tmp_versions/ | ||
modules.order | ||
Module.symvers | ||
Mkfile.old | ||
dkms.conf | ||
|
||
# [Custom] | ||
build |
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,10 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(SignalProcceser) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
add_subdirectory(src) | ||
|
||
add_executable(signal main.cpp) | ||
target_link_libraries(signal lib) |
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,8 @@ | ||
echo off | ||
echo Changing directory to "build" | ||
cd build | ||
echo Running CMake | ||
cmake -G "MinGW Makefiles" .. | ||
echo Running Make | ||
mingw32-make | ||
set /p DUMMY=Done. Press ENTER to exit... |
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,7 @@ | ||
echo off | ||
echo Changing directory to "build" | ||
cd build | ||
echo Running Make | ||
set MAKE=wsl -e make | ||
%MAKE% | ||
set /p DUMMY=Done. Press ENTER to exit... |
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,6 @@ | ||
echo off | ||
echo Cleaning "build" directory... | ||
rmdir /S /Q build | ||
echo Making "build" directory... | ||
mkdir build | ||
set /p DUMMY=Done. Press ENTER to exit... |
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,15 @@ | ||
echo off | ||
|
||
echo Cleaning "build" directory... | ||
rmdir /S /Q build | ||
echo Making "build" directory... | ||
mkdir build | ||
|
||
echo Changing directory to "build" | ||
cd build | ||
echo Running CMake | ||
cmake -G "MinGW Makefiles" .. | ||
echo Running Make | ||
mingw32-make | ||
|
||
set /p DUMMY=Done. Press ENTER to exit... |
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 @@ | ||
#include "TFileWriter.h" | ||
#include "TGenerator.h" | ||
|
||
int main() | ||
{ | ||
double time = 3; | ||
double oscillationFreq = 2; | ||
double samplingFreq = 200; | ||
double amplitude = 3.5; | ||
double initPhase = 0; | ||
double offsetY = 0; | ||
TGenerator gen(time, oscillationFreq, initPhase, offsetY, amplitude, samplingFreq); | ||
gen.exec(); | ||
TFileWriter file(gen.sl(), "signal.txt"); | ||
file.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,20 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
file(GLOB_RECURSE CORE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/core/*.cpp") | ||
file(GLOB_RECURSE IO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/io/*.cpp") | ||
file(GLOB_RECURSE ANALYSIS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/analysis/*.cpp") | ||
|
||
file(GLOB_RECURSE CORE_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/core/*.h") | ||
file(GLOB_RECURSE IO_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/io/*.h") | ||
file(GLOB_RECURSE ANALYSIS_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/analysis/*.h") | ||
|
||
add_library(lib | ||
${CORE_SOURCES} ${IO_SOURCES} ${ANALYSIS_SOURCES} | ||
${CORE_HEADERS} ${IO_HEADERS} ${ANALYSIS_HEADERS} | ||
) | ||
|
||
target_include_directories(lib PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/core | ||
${CMAKE_CURRENT_SOURCE_DIR}/io | ||
${CMAKE_CURRENT_SOURCE_DIR}/analysis | ||
) |
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,45 @@ | ||
#include "TGenerator.h" | ||
#include <math.h> | ||
|
||
// ************* | ||
// PRIVATE | ||
// ************* | ||
|
||
int TGenerator::_randInt(int from, int to) { | ||
return rand() % (to - from + 1) + from; | ||
} | ||
|
||
// ************ | ||
// PUBLIC | ||
// ************ | ||
|
||
TGenerator::TGenerator(double time, double oscillationFreq, double initPhase, double offsetY, double amplitude, double samplingFreq) { | ||
_time = time; | ||
_oscillationFreq = oscillationFreq; | ||
_initPhase = initPhase; | ||
_offsetY = offsetY; | ||
_amplitude = amplitude; | ||
_samplingFreq = samplingFreq; | ||
_sl = new TSignalLine(time, oscillationFreq, initPhase, offsetY, amplitude, samplingFreq); | ||
} | ||
|
||
TSignalLine *TGenerator::sl() const { return _sl; } | ||
|
||
void TGenerator::exec() { | ||
unsigned int pointsCount = _sl->pointsCount(); | ||
double x, y; | ||
for (int i = 0; i < pointsCount; i++) { | ||
x = i / _samplingFreq; | ||
y = _amplitude * sin((2 * i * M_PI * _oscillationFreq) / _samplingFreq + _initPhase) + _offsetY; | ||
_sl->set(i, x, y); | ||
} | ||
} | ||
|
||
// TODO: MAKE "TRUE" NOISE WITH TOTAL ABS EQUALS TO 0 + REFACTOR THE FUNCTION | ||
void TGenerator::addNoise(double dispersion){ | ||
for (int i = 0;i<_sl->pointsCount();i++){ | ||
double yOffset = _randInt(1, 1000000) / 1000000. * dispersion; | ||
int modif = _randInt(0, 2) - 1; | ||
_sl->set(i,_sl->at(i).x,_sl->at(i).y + modif * yOffset); | ||
} | ||
} |
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 @@ | ||
#ifndef TGENERATOR_H | ||
#define TGENERATOR_H | ||
|
||
#include <cmath> | ||
#include "TSignalLine.h" | ||
|
||
class TGenerator{ | ||
public: | ||
TGenerator(double time, double oscillationFreq, double initPhase = 0, double offsetY = 0, double amplitude = 1, double samplingFreq = 1000); | ||
TSignalLine *sl() const; | ||
void exec(); | ||
void addNoise(double dispersion); | ||
private: | ||
TSignalLine* _sl; | ||
double _time; | ||
double _oscillationFreq; | ||
double _initPhase; | ||
double _offsetY; | ||
double _amplitude; | ||
double _samplingFreq; | ||
int _randInt(int from, int to); | ||
}; | ||
|
||
#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 "TSignalLine.h" | ||
#include <math.h> | ||
|
||
// ************ | ||
// PUBLIC | ||
// ************ | ||
|
||
TSignalLine::TSignalLine(double time, double oscillationFreq, double initPhase, double offsetY, double amplitude, double samplingFreq) { | ||
_time = time; | ||
_oscillationFreq = oscillationFreq; | ||
_initPhase = initPhase; | ||
_offsetY = offsetY; | ||
_amplitude = amplitude; | ||
_samplingFreq = samplingFreq; | ||
_pointsCount = ceil(time * samplingFreq); | ||
_points = new Point[_pointsCount]; | ||
} | ||
|
||
TSignalLine::~TSignalLine(){ delete _points; } | ||
|
||
void TSignalLine::set(unsigned int index,double x, double y){ | ||
_points[index].x = x; | ||
_points[index].y = y; | ||
} | ||
|
||
Point TSignalLine::at(unsigned int index){ return _points[index]; } | ||
unsigned int TSignalLine::pointsCount() { return _pointsCount; } | ||
double TSignalLine::time() { return _time; } | ||
double TSignalLine::oscillationFreq() { return _oscillationFreq; } | ||
double TSignalLine::initPhase() { return _initPhase; } | ||
double TSignalLine::offsetY() { return _offsetY; } | ||
double TSignalLine::amplitude() { return _amplitude; } | ||
double TSignalLine::samplingFreq() { return _samplingFreq; } |
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 @@ | ||
#ifndef TSIGNALLINE_H | ||
#define TSIGNALLINE_H | ||
|
||
struct Point{ | ||
double x; | ||
double y; | ||
}; | ||
|
||
class TSignalLine{ | ||
public: | ||
TSignalLine(double time, double oscillationFreq, double initPhase = 0, double offsetY = 0, double amplitude = 1, double samplingFreq = 1000); | ||
~TSignalLine(); | ||
void set(unsigned int index, double x, double y); | ||
Point at(unsigned int index); | ||
unsigned int pointsCount(); | ||
double time(); | ||
double oscillationFreq(); | ||
double initPhase(); | ||
double offsetY(); | ||
double amplitude(); | ||
double samplingFreq(); | ||
private: | ||
Point* _points; | ||
unsigned int _pointsCount; | ||
double _time; | ||
double _oscillationFreq; | ||
double _initPhase; | ||
double _offsetY; | ||
double _amplitude; | ||
double _samplingFreq; | ||
}; | ||
|
||
#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 "TFileWriter.h" | ||
#include <fstream> | ||
|
||
// ************ | ||
// PUBLIC | ||
// ************ | ||
|
||
TFileWriter::TFileWriter(TSignalLine* sl, std::string filePath) { | ||
_sl = sl; | ||
_filePath = filePath; | ||
} | ||
|
||
void TFileWriter::exec() { | ||
std::ofstream file; | ||
file.open(_filePath); | ||
unsigned int pointsCount = _sl->pointsCount(); | ||
double x, y; | ||
for (int i = 0; i < pointsCount; i++) { | ||
x = _sl->at(i).x; | ||
y = _sl->at(i).y; | ||
file << x << '\t' << y << '\n'; | ||
} | ||
file.close(); | ||
} |
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 TFILEWRITER_H | ||
#define TFILEWRITER_H | ||
|
||
#include "TSignalLine.h" | ||
#include <string> | ||
|
||
class TFileWriter { | ||
public: | ||
TFileWriter(TSignalLine* sl, std::string filePath); | ||
void exec(); | ||
private: | ||
TSignalLine* _sl; | ||
std::string _filePath; | ||
}; | ||
|
||
#endif |