diff --git a/src/algorithms/standard/directscaletransform.cpp b/src/algorithms/standard/directscaletransform.cpp index bc9cb5c61..a228773dc 100644 --- a/src/algorithms/standard/directscaletransform.cpp +++ b/src/algorithms/standard/directscaletransform.cpp @@ -34,22 +34,23 @@ DOC("Computes Direct Scale Transform on a given matrix.\n" "14.4 (2000): 545-559."); void DirectScaleTransform::configure() { - _C = parameter("C").toInt(); - _fs = parameter("fs").toInt(); + _C = parameter("C").toReal(); + _fs = parameter("fs").toReal(); } - void DirectScaleTransform::compute() { const std::vector>& matrix = _matrix.get(); std::vector>& result = _result.get(); + int N = matrix.size(); + if (N == 0) throw EssentiaException("Input matrix is empty"); std::complex zi = std::complex(0, 1); - int N = matrix.size(); Real step = M_PI/log(N+1); - int num_rows = _C/step; - result.resize(num_rows, std::vector(N-1, 0)); + int num_rows = _C/step+1; // Number of rows. +1 because need to include the first row which is the 0th multiple of step + int P = matrix[0].size(); + result.resize(num_rows, std::vector(P, 0)); // Compute Scale Transform Matrix std::vector>> dst_mat(num_rows, std::vector>(N-1, 0)); @@ -67,7 +68,6 @@ void DirectScaleTransform::compute() { } // First Order Difference of the input matrix - int P = matrix[0].size(); std::vector> diff_matrix(N-1, std::vector(P, 0)); FOR(i, 0, N-1) FOR(j, 0, P) diff_matrix[i][j] = matrix[i][j] - matrix[i+1][j]; @@ -81,37 +81,4 @@ void DirectScaleTransform::compute() { // Absolute value of the result matrix FOR(i, 0, num_rows) FOR(j, 0, P) result[i][j] = std::abs(result_mat[i][j]); -} - -// std::vector >> DirectScaleTransform(int N=10, int C=6, int fs=1) { -// std::complex zi = 1i; -// double step = M_PI/log(N+1); -// int num_rows = C/step; - -// std::vector >> result(num_rows, std::vector< std::complex >(N-1, 0)); -// double Ts = 1/fs; - -// FOR(i, 0, num_rows) { -// FOR(j, 0, N-1) { -// double c = step * i; -// double k = j + 1; -// std::complex k_ = std::complex(k * Ts); -// std::complex c_ = std::complex(0.5) - zi * c; - -// std::complex M = pow(k_, c_)/(c_ * sqrt(2*M_PI)); -// result[i][j] = M; -// } -// } -// return result; -// } - -// int main() { -// std::vector >> result = DirectScaleTransform(); -// for(auto row: result){ -// for(auto elem: row){ -// cout << elem.real() << "+" << elem.imag() << "j "; -// } -// cout << endl; -// } -// return 0; -// } \ No newline at end of file +} \ No newline at end of file diff --git a/src/algorithms/standard/directscaletransform.h b/src/algorithms/standard/directscaletransform.h index a2caff70e..7be12037e 100644 --- a/src/algorithms/standard/directscaletransform.h +++ b/src/algorithms/standard/directscaletransform.h @@ -31,8 +31,8 @@ class DirectScaleTransform : public Algorithm { Input> > _matrix; Output> > _result; - int _C; - int _fs; + Real _C; + Real _fs; public: DirectScaleTransform() { @@ -57,27 +57,27 @@ class DirectScaleTransform : public Algorithm { } // namespace standard } // namespace essentia -// #include +#include -// namespace essentia { -// namespace streaming { +namespace essentia { +namespace streaming { -// class DirectScaleTransform : public StreamingAlgorithmWrapper { +class DirectScaleTransform : public StreamingAlgorithmWrapper { -// protected: -// Sink>> _matrix; -// Source>> _result; + protected: + Sink>> _matrix; + Source>> _result; -// public: -// DirectScaleTransform() { -// declareAlgorithm("DirectScaleTransform"); -// declareInput(_matrix, TOKEN, "the input matrix"); -// declareOutput(_result, TOKEN, "the result of the direct scale transform"); -// } -// }; + public: + DirectScaleTransform() { + declareAlgorithm("DirectScaleTransform"); + declareInput(_matrix, TOKEN, "the input matrix"); + declareOutput(_result, TOKEN, "the result of the direct scale transform"); + } +}; -// } // namespace streaming -// } // namespace essentia +} // namespace streaming +} // namespace essentia #endif // ESSENTIA_DIRECTSCALETRANSFORM_H