Skip to content

Commit 713c56a

Browse files
committed
Added basic functional: generate and export signal (sine wave)
1 parent 238b6de commit 713c56a

14 files changed

+312
-0
lines changed

.gitignore

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Object files
5+
*.o
6+
*.ko
7+
*.obj
8+
*.elf
9+
10+
# Linker output
11+
*.ilk
12+
*.map
13+
*.exp
14+
15+
# Precompiled Headers
16+
*.gch
17+
*.pch
18+
19+
# Libraries
20+
*.lib
21+
# *.a
22+
*.la
23+
*.lo
24+
25+
# Shared objects (inc. Windows DLLs)
26+
*.dll
27+
*.so
28+
*.so.*
29+
*.dylib
30+
31+
# Executables
32+
*.exe
33+
*.out
34+
*.app
35+
*.i*86
36+
*.x86_64
37+
*.hex
38+
39+
# Debug files
40+
*.dSYM/
41+
*.su
42+
*.idb
43+
*.pdb
44+
45+
# Kernel Module Compile Results
46+
*.mod*
47+
*.cmd
48+
.tmp_versions/
49+
modules.order
50+
Module.symvers
51+
Mkfile.old
52+
dkms.conf
53+
54+
# [Custom]
55+
build

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(SignalProcceser)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
add_subdirectory(src)
8+
9+
add_executable(signal main.cpp)
10+
target_link_libraries(signal lib)

_build_cmake_make.bat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
echo off
2+
echo Changing directory to "build"
3+
cd build
4+
echo Running CMake
5+
cmake -G "MinGW Makefiles" ..
6+
echo Running Make
7+
mingw32-make
8+
set /p DUMMY=Done. Press ENTER to exit...

_build_make.bat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
echo off
2+
echo Changing directory to "build"
3+
cd build
4+
echo Running Make
5+
set MAKE=wsl -e make
6+
%MAKE%
7+
set /p DUMMY=Done. Press ENTER to exit...

_clean.bat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
echo off
2+
echo Cleaning "build" directory...
3+
rmdir /S /Q build
4+
echo Making "build" directory...
5+
mkdir build
6+
set /p DUMMY=Done. Press ENTER to exit...

_clean_build_cmake_make.bat

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
echo off
2+
3+
echo Cleaning "build" directory...
4+
rmdir /S /Q build
5+
echo Making "build" directory...
6+
mkdir build
7+
8+
echo Changing directory to "build"
9+
cd build
10+
echo Running CMake
11+
cmake -G "MinGW Makefiles" ..
12+
echo Running Make
13+
mingw32-make
14+
15+
set /p DUMMY=Done. Press ENTER to exit...

main.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "TFileWriter.h"
2+
#include "TGenerator.h"
3+
4+
int main()
5+
{
6+
double time = 3;
7+
double oscillationFreq = 2;
8+
double samplingFreq = 200;
9+
double amplitude = 3.5;
10+
double initPhase = 0;
11+
double offsetY = 0;
12+
TGenerator gen(time, oscillationFreq, initPhase, offsetY, amplitude, samplingFreq);
13+
gen.exec();
14+
TFileWriter file(gen.sl(), "signal.txt");
15+
file.exec();
16+
}

src/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
file(GLOB_RECURSE CORE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/core/*.cpp")
4+
file(GLOB_RECURSE IO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/io/*.cpp")
5+
file(GLOB_RECURSE ANALYSIS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/analysis/*.cpp")
6+
7+
file(GLOB_RECURSE CORE_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/core/*.h")
8+
file(GLOB_RECURSE IO_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/io/*.h")
9+
file(GLOB_RECURSE ANALYSIS_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/analysis/*.h")
10+
11+
add_library(lib
12+
${CORE_SOURCES} ${IO_SOURCES} ${ANALYSIS_SOURCES}
13+
${CORE_HEADERS} ${IO_HEADERS} ${ANALYSIS_HEADERS}
14+
)
15+
16+
target_include_directories(lib PUBLIC
17+
${CMAKE_CURRENT_SOURCE_DIR}/core
18+
${CMAKE_CURRENT_SOURCE_DIR}/io
19+
${CMAKE_CURRENT_SOURCE_DIR}/analysis
20+
)

src/core/TGenerator.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "TGenerator.h"
2+
#include <math.h>
3+
4+
// *************
5+
// PRIVATE
6+
// *************
7+
8+
int TGenerator::_randInt(int from, int to) {
9+
return rand() % (to - from + 1) + from;
10+
}
11+
12+
// ************
13+
// PUBLIC
14+
// ************
15+
16+
TGenerator::TGenerator(double time, double oscillationFreq, double initPhase, double offsetY, double amplitude, double samplingFreq) {
17+
_time = time;
18+
_oscillationFreq = oscillationFreq;
19+
_initPhase = initPhase;
20+
_offsetY = offsetY;
21+
_amplitude = amplitude;
22+
_samplingFreq = samplingFreq;
23+
_sl = new TSignalLine(time, oscillationFreq, initPhase, offsetY, amplitude, samplingFreq);
24+
}
25+
26+
TSignalLine *TGenerator::sl() const { return _sl; }
27+
28+
void TGenerator::exec() {
29+
unsigned int pointsCount = _sl->pointsCount();
30+
double x, y;
31+
for (int i = 0; i < pointsCount; i++) {
32+
x = i / _samplingFreq;
33+
y = _amplitude * sin((2 * i * M_PI * _oscillationFreq) / _samplingFreq + _initPhase) + _offsetY;
34+
_sl->set(i, x, y);
35+
}
36+
}
37+
38+
// TODO: MAKE "TRUE" NOISE WITH TOTAL ABS EQUALS TO 0 + REFACTOR THE FUNCTION
39+
void TGenerator::addNoise(double dispersion){
40+
for (int i = 0;i<_sl->pointsCount();i++){
41+
double yOffset = _randInt(1, 1000000) / 1000000. * dispersion;
42+
int modif = _randInt(0, 2) - 1;
43+
_sl->set(i,_sl->at(i).x,_sl->at(i).y + modif * yOffset);
44+
}
45+
}

src/core/TGenerator.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef TGENERATOR_H
2+
#define TGENERATOR_H
3+
4+
#include <cmath>
5+
#include "TSignalLine.h"
6+
7+
class TGenerator{
8+
public:
9+
TGenerator(double time, double oscillationFreq, double initPhase = 0, double offsetY = 0, double amplitude = 1, double samplingFreq = 1000);
10+
TSignalLine *sl() const;
11+
void exec();
12+
void addNoise(double dispersion);
13+
private:
14+
TSignalLine* _sl;
15+
double _time;
16+
double _oscillationFreq;
17+
double _initPhase;
18+
double _offsetY;
19+
double _amplitude;
20+
double _samplingFreq;
21+
int _randInt(int from, int to);
22+
};
23+
24+
#endif

0 commit comments

Comments
 (0)