Triangle wave with offset#

float uz_wavegen_triangle_sample_with_offset(uz_wavegen_triangle_t *self, float amplitude, float frequency_Hz, float offset)#

Returns one sample of a triangle wave with a configurable DC offset.

Parameters:
  • self – Pointer to uz_wavegen_triangle instance

  • amplitude – Amplitude for the triangle wave

  • frequency_Hz – Frequency for the triangle wave in Hz. Only positive values are permitted

  • offset – DC offset added to the sample

Returns:

Returns one sample for current system time

Example#

Listing 95 Example function call to triangle wave generator with offset#
1#include "uz_wavegen.h"
2int main(void) {
3   float amplitude = 6.0f;
4   float frequency_Hz = 5.0f;
5   float offset = -5.0f;
6   uz_wavegen_triangle_t* triangle = uz_wavegen_triangle_init();
7   float output = uz_wavegen_triangle_sample_with_offset(triangle, amplitude, frequency_Hz, offset);
8}

Description#

This function calculates a triangle wave with offset. The phase is tracked in the wavegen instance and advanced on each sample call.

Figure made with TikZ

Fig. 344 triangle wave with offset