Noisy pulse waveform

Status
Not open for further replies.

brabudu

Member
Hi to all
I am working with pulsed waveforms, and have noticed that they are very noisy.
This code

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>

#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveform       waveform1;      //xy=263,153
AudioOutputAnalogStereo  dacs1;          //xy=693,173
AudioConnection          patchCord1(waveform1, 0, dacs1, 0);
// GUItool: end automatically generated code

int16_t wave[256];

void setup() {
  AudioMemory(10);

  for (int i=0;i<256;i++)
  {
    if (i>51) {
      wave[i]=32767;
    }
    else {
      wave[i]=-32767;
    }
  }
  
}

void loop() {
  waveform1.begin(1,500,WAVEFORM_PULSE);
  waveform1.pulseWidth(.2);
  delay(2000);
  waveform1.arbitraryWaveform(wave, 650.0);
  waveform1.begin(1,500,WAVEFORM_ARBITRARY);
  delay(2000);

}
shows the difference between a WAVEFORM_PULSE and an equal but memorized one with WAVEFORM_ARBITRARY: the latter is much better.
So i'm thinking of adapting the code to perform a filter similar to the one present in WAVEFORM_ARBITRARY.
Has anyone already tried it?
 
it needs to be optimized but this is much better

(synt_waveform.cpp)
Code:
case WAVEFORM_TEST:
		magnitude15 = signed_saturate_rshift(magnitude, 16, 1);
		for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
			index = ph >> 24;
			index2 = index + 1;
			if (index2 >= 256) index2 = 0;
			
			if (index < (pulse_width>>24)) {
				val1=magnitude15;
			
			} else {
				val1=-magnitude15;
			}
			
			if ((index2) < (pulse_width>>24)) {
				val2=magnitude15;
			} else {
				val2=-magnitude15;
			}
			
			scale = (ph >> 8) & 0xFFFF;
			val2 *= scale;
			val1 *= 0x10000 - scale;
			*bp++ = multiply_32x32_rshift32(val1 + val2, magnitude);
			ph += inc;
		}
		break;
 
Have you tried WAVEFORM_BANDLIMIT_PULSE ? Takes more processing power but removes aliasing artifacts.
 
I've installed teensy on arduino ide this year, but i don't know why the audio library was old (2018), so I didn't know waveform_bandlimit_xxx :D

Thanks
 
Status
Not open for further replies.
Back
Top