Skip to content

Commit

Permalink
Added a method to Signal class to return a reference to the sampling …
Browse files Browse the repository at this point in the history
…rate.
  • Loading branch information
Simon-Stone committed Nov 8, 2021
1 parent a5bacd7 commit dc4fed5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
27 changes: 27 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
}
]
}
1 change: 1 addition & 0 deletions include/Signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace dsp
auto real() const;
auto imag() const;
unsigned getSamplingRate_Hz() const;
unsigned& getSamplingRate_Hz();

// Setter
void setSamples(const std::vector<T>& samples);
Expand Down
6 changes: 6 additions & 0 deletions src/Signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ unsigned dsp::Signal<T>::getSamplingRate_Hz() const
return samplingRate_Hz_;
}

template<class T>
unsigned& dsp::Signal<T>::getSamplingRate_Hz()
{
return samplingRate_Hz_;
}

template <class T>
void dsp::Signal<T>::setSamples(const std::vector<T>& samples)
{
Expand Down
2 changes: 1 addition & 1 deletion src/fft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ std::vector<std::vector<T>> dsp::fft::spectrogram(const std::vector<T>& signal,
// -> Final result is a matrix of real values, each column representing one frame's log-squared magnitude spectrum

// Pre-emphasis
std::vector<T> b{ 1.0, static_cast<T>(0.95) };
std::vector<T> b{ 1.0, static_cast<T>(-0.95) };
std::vector<T> a{ 1.0 };
auto preemph_signal = filter::filter(b, a, signal);

Expand Down
11 changes: 11 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ struct DspTest : ::testing::Test

};


TEST_F(DspTest, SignalMethods)
{
auto s = dsp::Signal<double>(1000);
EXPECT_TRUE(s.getSamplingRate_Hz() == 1000);
s.getSamplingRate_Hz() = 2000;
EXPECT_TRUE(s.getSamplingRate_Hz() == 2000);
auto sr = &s.getSamplingRate_Hz();
*sr = 3000;
EXPECT_TRUE(s.getSamplingRate_Hz() == 3000);
}
TEST_F(DspTest, SignalOperations)
{
auto c = dsp::signals::cos<double>(100, 0.02, 8000);
Expand Down

0 comments on commit dc4fed5

Please sign in to comment.