Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Noisy pulse waveform

  1. #1
    Junior Member
    Join Date
    May 2021
    Posts
    8

    Noisy pulse waveform

    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?

  2. #2
    Junior Member
    Join Date
    May 2021
    Posts
    8
    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;

  3. #3
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,101
    Have you tried WAVEFORM_BANDLIMIT_PULSE ? Takes more processing power but removes aliasing artifacts.

  4. #4
    Junior Member
    Join Date
    May 2021
    Posts
    8
    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

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •