0
$\begingroup$

Using a micro-processor of 48MHz, I am trying to output a sine wave from the DAC (digital to analog ), and I am not sure if my Nyquist and calculations are good.

  1. I have to output sine in frequencies range of 1KHz to 3MHz

  2. I have created an array of a sine samples that has 1000 points(for 1 period )

  3. I am running a timer between samples, and the frequency calculation

    float timerFrequency=sineFrequency*1000; //(timerT*1000=finalSineT)

But then I was thinking that for 3MHz sine wave, I will need a timer frequency of 3GHz with this approach(!). (3Mhz signal * 1000 sine samples)

Something here is very wrong with everything, because if I have a processor that is 48MHz, I can probably output a 3MHz , isn't it ?

  1. Whats wrong with my approach, and what are my limits with these assumptions ?

  2. Can I reduce the sine samples array to lets say 100 ? what would it do to the Nyqvist at 3MHz ?

  3. How many samples should my sine array needs? (the min), and my timer frequency?

$\endgroup$
9
  • 1
    $\begingroup$ There are a few pieces of information missing: what SNR do you need? How many (effective) bits is the DAC? Are you running bare metal or is there an (RT)OS involved? $\endgroup$
    – Peter K.
    Apr 26, 2016 at 18:14
  • 1
    $\begingroup$ Are you sure your micro is up to a 3MHz sine output? This project uses a 20MHz PIC and only claims up to 60kHz clean sine waves. FWIW, it uses a 256-entry lookup table $\endgroup$
    – Peter K.
    Apr 26, 2016 at 18:57
  • 1
    $\begingroup$ I repeat my earlier questions: What SNR do you need? Are you running bare metal or is there an (RT)OS involved? $\endgroup$
    – Peter K.
    Apr 26, 2016 at 19:04
  • 1
    $\begingroup$ @Curnelious While you're at it, please also include in your question the sampling rate of your DAC. If it is embedded in a small microcontroller, then it is unlikely to be able to produce a 3 MHz signal. $\endgroup$
    – MBaz
    Apr 26, 2016 at 20:00
  • 1
    $\begingroup$ @Fat32 Fire away! $\endgroup$
    – Peter K.
    Apr 26, 2016 at 22:33

1 Answer 1

3
$\begingroup$

Eventhough your problem is quite a practical one, based on a particular chip to produce a sine wave that requres a solid understanding of its blocks, I would, nevertheless, like to provide you a general framework for producing a continuous time sine wave from a set of discrete time samples, from which you can deduce the details of implementation for your particular architecture.

Now for this particular problem of producing a sine wave, the fundamental factor which will determine your analog output capability from a DAC is the quality of the analog "Anti-Imaging" filter (also known as interpolation or reconstruction filter)

When that filter is an ideal one (or a close enough approximation) it can reject all the distorting image frequency bands that exist due to the DAC output being an ideal impulse based sampled representation of the signal to be reconstructed. (A sine wave in this case).

In such a case (of close to ideal) of operating conditions, you can generate a perfect sine wave at any desired frequency from just "2" samples of it, by merely adjusting the output DAC conversion frequency. The filter will interpolate all the missing wave in the ideal case.

In other words, your sine wave samples will be this $$x[n] = \cos(\pi n)$$ which has only two samples which are +1 and -1 per period, representing a critically sampled sinusoidal. Your DAC will output +A and -A after scaling for each consequitive conversion period (which is limited by either your chip speed or your DAC output settling time) and that perfect reconstruction filter will convert those apexes into a smooth sine wave.

By adjusting the DAC output conversion period you can control the produced sinusoidal wave frequency simply as: $$f_{sine} = \frac{1}{2 T_{conversion}}$$

Now things are not ideal (especially DAC output involves a zero order hold block that should be taken into account in the design of the reconstruction filter) and therefore sadly just two samples per period will not be enough. In such a case, to be able to use a less perfect and easier to design analog output reconstruction filter you will provide more samples of the sine wave per period. But how many samples? It depends on your filter quality. The better the filter the less the number of samples.

The frequency is however is still adjusted the same way: In general let: $$x[n] = \cos(\omega_k n)$$ be your one period of sampled signal (look up table samples) where $w_k$ (being between $0$ and $\pi$) is the discrete time frequency of the generic set of samples. And let your DAC output period be $T_s$ then the produced output sine wave will have the frequency of: $$f_{sine} = \frac {\omega_k}{2 \pi T_s}$$

Again by adjusting $T_s$ or $\omega_k$ you can control this frequency.

$\endgroup$
6
  • $\begingroup$ Thank you very much, but i knew all of that and its quite obvious, these are the fundamentals of smapling theory. The interesting stuff is calculating what happens in each case of N samples of a signal. How it looks for every N in the f domain. However you provided a great answer and i accept it even that its not a clear sense of what will happen. $\endgroup$
    – Curnelious
    Apr 27, 2016 at 6:41
  • $\begingroup$ In your question you talk about using 1000 samples per peiod. That's too much! i.e. N=1000 samples gives you $w_k = 2\pi / 1000 = \pi / 500$ a very small discrete time frequency, this leads for example for a required output $f_{sine} = 3M Hz$ => $T_{DAC} = 1/ (3G) s$ => a 3 Ghz of operation DAC frequency. Just as you complain. This high frequency results from using very low $w_k$, if you instead use a small number of samples such as N=10, you would need a 30 Mhz of DAC frequency $\endgroup$
    – Fat32
    Apr 27, 2016 at 11:15
  • $\begingroup$ Thats true but there is no such animal 30m dac :) $\endgroup$
    – Curnelious
    Apr 27, 2016 at 11:18
  • $\begingroup$ What's your DAC maximum frequency?, 30Mhz an animal?? $\endgroup$
    – Fat32
    Apr 27, 2016 at 11:19
  • $\begingroup$ You don't need large number of bits... You may just use a switch with on/off to produce a very high frequency oscillation and filter out a sine wave instead? as a completely different approach ? $\endgroup$
    – Fat32
    Apr 27, 2016 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.