Skip to content

Examples

Mohammed Boujemaoui Boulaghmoudi edited this page Oct 6, 2018 · 1 revision

Windowing an input signal

This example show how to apply a Hamming window to an input signal $x(n)$ and store the output in a signal $y(n)$:

using namespace edsp;

constexpr std::size_t size = 1024;
auto x = std::vector<double>(size);
auto y = std::vector<double>(size);

// Create a Hamming Window of 1024 samples
auto window = make_window<Hamming>(size);

// Apply the window to the signal X and store it in Y
window.compute(std::cbegin(x), std::cend(x), std::begin(y));

Generate an square signal

This example show how to generate a square wave with a duration of 10 seconds, frequency of 500Hz and sampled at 8000Hz.

const std::size_t size = 80000;
std::vector<double> square(size);

// Configure the oscillator
auto square_oscillator = SquareOscillator();
square_oscillator.set_samplerate(8000);
square_oscillator.set_amplitude(2);
square_oscillator.set_frequency(500);

// Generate the samples and store them
std::generate_n(std::begin(square), size, square_oscillator); 

Computing the DFT

This example show how to compute the DFT of an input signal.

constexpr std::size_t size = 1024;
// Generate a buffer of a sin function
auto real_data = std::vector<double>(size);

...

// Create an array of complex data to store the fft output
auto fft_data = std::vector<std::complex<double>>(size );

// Create an fft object with the expected output size as parameter
edsp::complex_dft(std::cbegin(real_data), std::cend(real_data), std::begin(fft_data));
Clone this wiki locally