18kHz Sine wave DAC

Status
Not open for further replies.

SamWiseTheg

New member
I am trying to create a 18kHz sine wave coming off the DAC on a 3.1 using the teensy Audio Library.

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

AudioSynthWaveformSine   sine1;          
AudioOutputAnalog        dac1;           
AudioConnection          patchCord2(sine1, dac1);

long freq = 18000;

void setup() {
  AudioMemory(20);
  sine1.frequency(freq);
  sine1.amplitude(1);
}


void loop(){

  
}

I have tried with a 10 and 22µF cap coming off my DAC, and still no luck in producing a nice sine wave on my scope.

Any help is greatly appreciated
 
With 44.1 kHz sample rate and no analog low pass filter, you'll never see a "nice" 18 kHz sine wave shape. It's always going to look much like a square wave, since it's so close to 22 kHz.
 
Im pretty new to arduino and especially the Teensy libraries so, is that code sufficient to produce the sine wave with the added low pass filter? Or is 18kHz just too close to the 22kHz and is always going to be square?
 
In this case, talk of a filter means after the DAC, as an analog filter.

The built in DAC just converts each sample, without any analog filter to remove frequencies over 22 kHz. That's why you see a rough waveform. All those ugly square parts are ultrasonic frequencies, over 22 kHz. It looks terrible on an oscilloscope, but it really is 18 kHz plus high frequencies that should be filtered away.

Better DACs meant for audio do have filtering. Usually the have interpolation, like 4X or 8X higher output rates, which allows an analog filter to more easily remove the high frequency stuff, so you end up with only the under-22kHz signal. But the built in DAC doesn't do this.... it's just a simple DAC, so you get a raw waveform with all the ultrasonic stuff from the 44 kHz sampling.
 
Status
Not open for further replies.
Back
Top