diff --git a/CMakeLists.txt b/CMakeLists.txt index e2352722e528f5fbfb99060eb6e66719376a4f29..0a219443dbccf1efb2ff26c87499101499bcd383 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,6 @@ include(cmake/shared_settings.cmake) add_executable(compressed_sensing main.cpp - vector.h ) target_link_libraries(compressed_sensing shared_settings Eigen3::Eigen) target_compile_features(compressed_sensing PUBLIC cxx_std_17) diff --git a/main.cpp b/main.cpp index 99fb5d758deb8f1d8fcd6d5e4898f589382386c4..35346902f1a67de444ed665b8da9318cad2b9928 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,36 @@ +#include <Eigen/Core> #include <iostream> -#include "vector.h" -using namespace cs; +using Scalar = double; +using Vector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>; +using Matrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>; + +void python_print(char const* name, Vector const& x) { + std::cout << name << " = np.array(["; + std::cout << x[0]; + for (uint32_t i = 1; i < x.size(); ++i) { + std::cout << ", " << x[i]; + } + std::cout << "])\n"; +} //-------------------------------------------------------------------------------------------------- int main() { - Vector<double> x = Vector<double>::Random(5); - std::cout << x << '\n'; + //Vector x = Vector::Random(5); + //std::cout << x << '\n'; + + Scalar pi = 3.1415926535897932384626433832795; + + Scalar f1 = 697; + Scalar f2 = 1209; + + Scalar sample_period = 0.01; + uint32_t n_samples = 10; + Vector sample_times = (sample_period / n_samples) * Vector::LinSpaced(n_samples, 0, n_samples); + python_print("sample_times", sample_times); + Vector sample_rads = 2 * pi * sample_times; + Vector sample_values = sin((f1 * sample_rads).array()) + sin((f2 * sample_rads).array()); + python_print("sample_values", sample_values); + return 0; } diff --git a/plotter.py b/plotter.py new file mode 100644 index 0000000000000000000000000000000000000000..0b4575e29fc480d22d7f67e152300cc2e3a1b34a --- /dev/null +++ b/plotter.py @@ -0,0 +1,9 @@ +import numpy as np +import matplotlib.pyplot as plt + +if __name__ == "__main__": + sample_times = np.array([0, 0.00111111, 0.00222222, 0.00333333, 0.00444444, 0.00555556, 0.00666667, 0.00777778, 0.00888889, 0.01]) + sample_values = np.array([0, -0.155307, -1.22423, 1.08309, 1.2909, -1.69749, -0.428405, 1.04634, -0.0577232, 0.348445]) + plt.plot(sample_times, sample_values) + plt.savefig("fig_a.png") + plt.close() diff --git a/vector.h b/vector.h deleted file mode 100644 index cf7c07e5a25eeaf27d9b3d59cfc4e3119760998b..0000000000000000000000000000000000000000 --- a/vector.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef FUNSIM_VECTOR_H -#define FUNSIM_VECTOR_H - -#include <Eigen/Core> - -namespace cs { - -//-------------------------------------------------------------------------------------------------- -template <typename T> -using Vector = Eigen::Matrix<T, Eigen::Dynamic, 1>; - -//-------------------------------------------------------------------------------------------------- -template <typename T> -using Matrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>; - -} - -#endif