2

I generated a squere wave signal and put it into a wave file, using this code:

import sys, os, wave, random, struct

noise_output = wave.open('noise.wav', 'w')
noise_output.setparams((1, 2, 1000, 0, 'NONE', 'not compressed'))

SAMPLE_LEN = 1000

for i in range(0, SAMPLE_LEN):
        value = random.choice([-32000, 32000])
        for j in range(100):
            packed_value = struct.pack('h', value)
            noise_output.writeframes(packed_value)

I was expected to hear some short rattles when listened, because this is not let's say a "valid" audio signal. Instead I could hear some rattles with a tone somehow, cannot describe it.

Then I used an osciloscope to see the output signal from the soundcard, and it looks like this:

enter image description here

The output looks to me something like Gibbs effect. My question is, why does it look like this? I was excepted to see no ringing artifact on osciloscope. How the DAC from the soundcard works and which digital/analog filters are outputing this signal?

Paul R
  • 208,748
  • 37
  • 389
  • 560
notkov
  • 59
  • 6
  • 4
    Congratulations - you are seeing [Gibbs' phenomenon](https://en.wikipedia.org/wiki/Gibbs_phenomenon#The_square_wave_example). The square wave is being band-limited to just below Nyquist by your sound card's reconstruction filter (analogue low pass filter on the DAC output). – Paul R Mar 29 '16 at 15:40

1 Answers1

0

This ringing could be due to the interpolation filter(s) used by any automatic sample rate conversion done in the audio driver or hardware. Get rid of most of it by using a "softer" edge or larger rise/fall time.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153