7 Replies Latest reply on Jan 17, 2019 10:33 AM by user_342122993

    Audio signal generator: strange noise with headphones, no noise when connected to PC

    user_246598725

      Hi,

       

      having some free days, continuing my work on an audio signal generator on a CY8CKIT-059. With help of Odissey and his components (DDS24 24-bit DDS arbitrary frequency generator component and hardware multiplier), I can output a waveform with variable amplitude. So, first many many thanks to Odissey and his valuable contributions to the community.

       

      Now, I have some noise in output when using the headphones, but when connected to soundcard input, there's no noise. The noise sounds like some sort of ripple related to the amplitude control, but it's hard to describe. I'm not sure if it also can be some sort of overtones.

       

      Current test setup is 1kHz sine wave, with an triangle amplitude control waveform of ~0.5Hz. Sample frequency is 512kHz. Output device is 16 Ohm headphone. Connection from two internal OpAmps (one for left & right each) to headphone is done by 100uF in series for each channel, nothing else.

       

      To verify my output stage, I used the PSoC 5LP audio example, which makes the PSoC appear as an USB soundcard, modified the example to my output stage and played some songs. Here, the sample frequency of the device is 32kHz. Using the headphones, there's not the same noise I can hear with the PSoC generated sound. There's only some...hmm, I think it's called "pink" noise, which is what you can expect from low-cost casette playback devices from the 80's/90's So, this let me assume that my output stage is okay.

       

      Next idea was to connect the device to the soundcard and record the input to have a test sample, showing the problem - but interestingly there's no "ripple" noise So I can't show you the problem. I've also written a small C# application, generating the same sound as described above (1kHz sine with 0.5Hz triangle amplitude) and used it with the USB soundcard application, no ripple noise, even when changing the sample rate and/or bit depth of the generated sound... I also changed the headphones, no effect.

       

      In short:

      - signal generator application & headphone: not OK

      - signal generator application & soundcard: OK

      - USB soundcard application & headphone: OK

       

      So, I assume there's some sort of filtering and/or audio processing when using the soundcard, which is missing when using the headphones. How can I figure out where the error is and how to solve it?

       

      Regards

        • 1. Re: Audio signal generator: strange noise with headphones, no noise when connected to PC
          user_342122993

          Ralph,

          The line-in input impedance is high and does not load the output Opamp. On the other side, the input impedance of the headphones is low (16 Ohm), overloading Opamp. For peak output signal of 1V, the driving current  is 62mA. This is too much for Opamp, and it is being overloaded (hence causing distortion). Check the signal on the output pin using scope with and w/o headphones. Remedies: try to add ~500 Ohm resistor in series with the phone to reduce current. Make sure that Opamp direct output pins are used. Try to put output Opamps in parallel to increase output current or simply use high impedance headphones (100-300 Ohm).

          /odissey1

          • 2. Re: Audio signal generator: strange noise with headphones, no noise when connected to PC
            user_246598725

            Hi Odissey,

             

            I can make this change to verify, but I doubt it's the reason - remember, the USB soundcard with headphone doesn't have this distortion.

             

            Regards

            • 3. Re: Audio signal generator: strange noise with headphones, no noise when connected to PC
              user_246598725

              Hi Odissey,

               

              I've done some tests with 120R and 470R in series, the result is the same. Output pins are OpAmp output. So, I think it's not related to output current and hardware distortion.

               

              I assume the distortion comes from my way generating the sound. Currently I'm trying to make some kind of output dithering, using the PRS component and xOR-ing the LSB of the DAC value with the PRS output. The result doesn't get better. The strange thing is that the USB soundcard application works with headphone, so I have to figure out where the differences are.

               

              Regards

              • 4. Re: Audio signal generator: strange noise with headphones, no noise when connected to PC
                user_246598725

                Current state:

                The distortion comes from two sources:

                1) changing the amplitude creates distortion depending on the amplitude value, even when changing the amplitude only when crossing the zero point of the wave

                2) depending on the amplitude, the generated output has distortion

                 

                I've implemented the DAC as 11-Bit PIDAC according to AN64275, which improved the output quality. There's still distortion in the headphones, but it's lower now. The 11-Bit DAC is currently implemented with software, so next step is to modify the hardware design to work with 11-Bit DAC to free up the MCU again.

                 

                I've still to investigate the difference when using the USB soundcard project and output on 8-Bit DAC. I also came across some DDS information, where it's mentioned that the number of samples within the sine table should be greater than the DAC resolution. In my initial application, this is 8-Bit DAC and 512 samples (9-Bit), so I'll make a test with 1024 or 2048 samples to check if this would also reduce the distortion. Since the current application uses DDS24 component to generate a variable clock frequency for the amplitude modulation part, I might change the project approach to use a fixed output frequency and generate the wave based on phase accumulator - this might be the better approach, especially for higher signal frequencies. I have to figure out if this is possible with PSoC 5LP.

                 

                Regards

                • 5. Re: Audio signal generator: strange noise with headphones, no noise when connected to PC
                  user_342122993

                  Ralph,

                  DDS theory predicts that optimal lookup table length equals (N+1) for DAC output width N (see Eq. 11 in the paper attached). So, for 8-bit output, the optimal table length is 512. Unfortunately, PSoC5 native VDACs are not quite 8-bit, and show a lot of distortion at higher frequencies, so a table of 256-length is probably sufficient.

                   

                  I will post fixed frequency DDS example tomorrow later.

                   

                  How do you scale output? Do you use my hardware multiplier? Have in mind that it works for unsigned multiplication and will cause a hard step when signal is not zero. I do have upgraded version for signed multiplication, but it is in a beta stage.

                  /odissey1

                  • 6. Re: Audio signal generator: strange noise with headphones, no noise when connected to PC
                    user_246598725

                    Hello Odissey,

                     

                    thank you for that paper.

                     

                    Yes, I'm using your multiplier. It can be used even in it's current unsigned implementation:

                     

                    Input A is the signed 8-Bit value from the sine table, so the input is without DC voltage. Input B is the scale value as unsigned. The high byte of the result is used as scaled value. If the MSB of the input A value is set, indicating a negative value, the scale value is subtracted from the result high byte. The MSB of either value is flipped. This approach makes the calculation only on the AC part of the signal, takes care for idle value of mid-scale (0x80 if 8-Bit DAC is used and is equivalent to 0x00 in signal table) and converts to unsigned value.

                     

                    If I remember correctly, I made a small change to your multiplier component to register both input values on trigger. In the original implementation, one of the values was not registered, therefore a change of input value during calculation would lead to a wrong result.

                     

                    Regards

                    • 7. Re: Audio signal generator: strange noise with headphones, no noise when connected to PC
                      user_342122993

                      Ralph,

                      Attached is updated Multiplier project. It multiplies 8-bit signed sine wave centered around 128 by unsigned 8-bit multiplier. The sine wave feeds from RAM by DMA using custom "wave generator" (WaveGen8). All components are imported into the project.

                       

                      This version is for multiplying N-bits by M-bits, both signed/unsigned. The component is dated and not tested well, so must be used with caution. Note that the component treats "signed" values not as "2-s compliment" but as "offset binary" (please see application note attached).

                      /odissey1

                      P.S. This is not the equivalent time sampling project i promised above!

                       

                      Figure 1. WaveGen8 pushes sine wave from RAM into h/w bus using DMA. Bus amplitude is scaled by [0-255] using API calls. Output frequency controlled by DDS32.

                      RAM-Multiply-DAC_01b_A.png

                      Figure 2. Screenshot of sine modulation 0-255 taken with long persistence time.

                      RAM-Multiply-DAC_01b_B.png