Projects Inventory

Digital Signal Processing (DSP) Basics Gaming Project in C++

Explanation:

  1. Sine Wave Generation (generateSineWave):
    • The generateSineWave function generates a sine wave signal based on a specified frequency, sample rate, and number of samples.
    • Advertisement
    • It calculates each sample using the sine function, sin(2 * pi * frequency * i / sampleRate), where i is the sample index.
    • The function returns a vector containing the generated sine wave samples.
  2. Low-Pass Filter (lowPassFilter):
    • The lowPassFilter function applies a simple first-order low-pass filter to the input signal.
    • The filter smooths out the signal by averaging each sample with the previous one, weighted by a smoothing factor alpha.
    • The parameter alpha controls the cutoff frequency of the filter; smaller values of alpha result in more smoothing (i.e., a lower cutoff frequency).
    • The filtered signal is returned as a vector of samples.
  3. Signal Printing (printSignal):
    • The printSignal function prints the values of the signal samples to the console, allowing you to observe the waveform.
  4. Main Function (main):
    • The main function sets up the parameters for generating a sine wave: the frequency (5 Hz), sample rate (100 samples per second), and number of samples (100).
    • Advertisement
    • It calls generateSineWave to produce the sine wave, then applies the lowPassFilter with an alpha value of 0.1.
    • The original and filtered signals are printed to the console.

Possible Enhancements:

Exit mobile version