Direct Digital Frequency Synthesis Technology and Its Implementation of C ++, digital frequency synthesis implementation

Source: Internet
Author: User
Tags radar

Direct Digital Frequency Synthesis Technology and Its Implementation of C ++, digital frequency synthesis implementation

DDFS-Direct Digital Frequency Synthesizer Direct Digital Frequency synthesis technology can be used to generate periodic signals of arbitrary waveforms. The so-called DDFS is simply a look-up Table method that maintains a Lookup Table internally to store a periodic waveform. In fact, this table provides a ing relationship between the phase and the function value:


Here, the phase ω is a linear function of time t.


The adjustment of the output frequency is actually the adjustment of the phase function's coefficient k △.

For example, a search table stores a sine wave cycle. The length of a query table is 1024. The phase of a sine wave is a period of 2 π, so the phase difference between the two adjacent items in the search table is. That is to say, the phases of the query table are:


It should be noted that the phase corresponding to the last element is not 2π, because the phase is actually the same as the phase 0, and the query table can only appear once.

We also need a phase accumulators and a frequency register to record the current phase value. For example, if we use a 16-bit unsigned integer register to record this phase value, then 0 to 65537 (note that this is 65537) correspond to the phase period between 0 and 2 π. The phase changes linearly with time, so we only need to accumulate a fixed phase each time. The value accumulated exists in the frequency Register. For example, if the value in the frequency Register is 5, the values of the phase accumulators are:, 20 ,..., 65530,65535, 3,8, 13 ,.... If the value exceeds 65536, for example, 65537 automatically overflows to 0, and the periodicity of the integer variable is used.

How many suitable is the value of the Frequency Register? If our sampling frequency is Fs, we want the output frequency to be f. The length of the query table is M, the length of the phase accumulators is N, and the value of the Frequency Register is k. The minimum phase variation of the phase accumulators is. The output waveform has Fs/f data points in a cycle. The phase difference between data points is. There are the following equations:


The actually calculated K value is not necessarily an integer. It can be rounded down. For example, if the sampling frequency is 1 kHz and we want to output a sine wave of 10Hz, the length of the phase accumulators is 65536. The value of the Frequency Register should be.

It can be seen that the longer the length of the phase accumulators, the higher the frequency resolution. Therefore, in actual use, the phase accumulators are usually designed to be 32-bit or higher-digit. The length of a query table is usually much shorter, generally 10 or 12 bits. In this case, you only need to use the maximum number of digits of the phase accumulators as the index for table search.

 

Direct Digital frequency synthesis is not only used for hardware generation of specific function waveforms, but can also be used in the field of numerical computing. Take generating a sine wave as an example. Although sin () and cos () functions are provided in most programming languages, the calculation speed of this function is relatively slow. If your program needs to be called several million times, it will take a considerable amount of time. In addition, with the increase of t, the calculation accuracy of sin (t) will also decrease. At this time, the advantages of using DDS technology are shown. First, the lookup table method ensures that the speed is much faster than any existing trigonometric function calculation code. Second, all operations are integer operations to ensure that there is no cumulative calculation error.

 

The following is the implementation code that can generate multiple cyclic function waveforms:

#ifndef DDS_H_INCLUDED#define DDS_H_INCLUDEDclass LookupTable{    friend class DDS;private:    unsigned int m_length;    unsigned int m_shift;    double *m_table;public:    LookupTable();    LookupTable(unsigned int N);    ~LookupTable();    void sine(double amplitude = 1.0, double baseline = 0.0);    void rect(double dutycircle = 0.5, double amplitude = 1.0, double baseline = 0.0);    void sawtooth(double dutycircle = 0.5, double amplitude = 1.0, double baseline = 0.0);    void arbitrary(double table[]);};class DDS{private:    LookupTable *m_pLut;    unsigned int m_iter;    unsigned int m_stride;    unsigned int m_phase;public:    DDS(LookupTable *pLut, unsigned int stride = 1, unsigned int phase = 0);    void setPhase(double phase = 0.0);    void setFreq(double freq);    void setFreq(double freq, double fs);    inline double value();};inline double DDS::value(void){    unsigned int index = (m_iter + m_phase);    index = index >> m_pLut->m_shift;    double value = m_pLut->m_table[index];    m_iter += m_stride;    return value;}#endif // DDS_H_INCLUDED

#include "dds.h"#include <cstdlib>#include <cmath>LookupTable::LookupTable(){    m_length = 0;    m_table = NULL;}LookupTable::~LookupTable(){    delete[] m_table;}LookupTable::LookupTable(unsigned int N){    if(N < 1)    {        N = 1;    }    if(N > 16)    {        N = 16;    }    m_length = 0x01 << N;    m_shift = 32 - N;    m_table = new double[m_length];}void LookupTable::sine(double amplitude, double baseline){    if(m_length != 0)    {        for(unsigned int i = 0; i < m_length; i++)        {            m_table[i] = amplitude * sin(2 * M_PI / m_length * i) + baseline;        }    }}void LookupTable::rect(double dutycircle, double amplitude, double baseline){    if(m_length != 0)    {        for(unsigned int i = 0; i < m_length; i++)        {             double value = (1.0 * i / m_length < dutycircle) ? 0 : 1;             m_table[i] = amplitude * value + baseline;        }    }}void LookupTable::sawtooth(double dutycircle, double amplitude, double baseline){    double pos, value;    if(m_length != 0)    {        for(unsigned int i = 0; i < m_length; i++)        {            pos = 1.0 * i / m_length;            if(pos < dutycircle)            {                value = pos / dutycircle;            }            else            {                value = (1.0 - pos) / (1.0 - dutycircle);            }            m_table[i] = amplitude * value + baseline;        }    }}void LookupTable::arbitrary(double table[]){    if(m_length != 0)    {        for(unsigned int i = 0; i < m_length; i++)        {            m_table[i] = table[i];        }    }}DDS::DDS(LookupTable *pLut, unsigned int stride, unsigned int phase){    m_iter = 0;    m_pLut = pLut;    m_stride = stride;    m_phase = phase;}void DDS::setPhase(double phase){    m_phase = round(phase /(2 * M_PI) * 4294967296.00);}void DDS::setFreq(double omega){    double stride = omega / (2 *M_PI) * 4294967296.00;    m_stride = round(stride);}void DDS::setFreq(double freq, double fs){    double omega = 2 *M_PI *freq / fs;    setFreq(omega);}

#include <iostream>#include "dds.h"using namespace std;int main(){    LookupTable sincos(10);    LookupTable sawtooth(10);    sincos.sine(2, 0);    sawtooth.sawtooth(0.3, 1, 0);    DDS dds1(&sincos);    DDS dds2(&sincos);    DDS dds3(&sawtooth);    dds1.setFreq(10, 1000);    dds1.setPhase(0.0);    dds2.setPhase(3.1415926/2);    dds2.setFreq(10, 1000);    dds3.setFreq(10, 1000);    for(int i =0; i <200; i++)    {        cout << i << ", " << dds1.value() << ", " ;        cout << dds2.value() << ", " << dds3.value() << endl;    }    return 0;}

Plot the output result as follows:


I hope this code will be useful to you.



What is direct frequency synthesizer (DS)

History of frequency synthesis
Frequency synthesizer has been hailed as the "heart" of many electronic systems ". Modern warfare is a battle for control of electronic spectrum. Frequency Synthesizer generates electronic spectrum. A high-frequency and stable frequency synthesizer is required in advanced electronic systems such as space communication, radar measurement, remote telemetry control, radio astronomy, radio positioning, satellite navigation, and digital communication. Electronic interference brings new challenges to radar and communication. Communication in Electronic Warfare frequency hopping system has become an important military communication means. The frequency-hopping communication system must be equipped with a frequency synthesizer suitable for the frequency-hopping speed. A high-performance frequency synthesizer must have the characteristics of low output phase noise, fast frequency variation, wide output frequency range, and multiple frequency points.
Rate synthesizer can be divided into direct, indirect (Phase-Locked), direct digital, and hybrid. The theory of frequency synthesis was proposed in the middle of 1930s. The direct frequency synthesis technology was initially developed and applied in practice.
In the late 1960s s and early 1970s S, the application of phase feedback control theory and analog phase lock technology in the frequency synthesis field led to a revolution in the development history of frequency synthesis technology, coherent indirect synthesis theory is the direct product of this revolution. The emergence of digital phase-locked loop components, such as digital phase detector and digital programmable frequency divider, and its application in Phase-Locked Frequency Synthesis Technology marks the formation of Digital Phase-Locked Frequency Synthesis technology. Because of the continuous attraction and utilization of new achievements in digital technologies such as swallow Pulse counter, Fractional Divider, and multimode divider, the Digital Phase-lock frequency synthesis technology has become increasingly mature. The emergence of direct digital frequency synthesis (DDS) led to the second revolution in the field of frequency synthesis. In early 1970s, J. Tierney and others published research results on direct digital frequency synthesis, and first proposed the concept of DDS. Because Direct Digital Frequency Synthesizer (DDFS) it has superior performance, such as relatively wide bandwidth, fast frequency variation speed, high frequency resolution, output Phase Continuity, orthogonal signal that can output broadband, programmable and fully digital, and easy integration, therefore, the rapid development has been achieved in just over 20 years, and the application of DDS has become more and more extensive.
Basic concepts of frequency synthesis
Frequeney Synthesis refers to the process of generating and outputting multiple work frequency points in a certain frequency band based on one or more reference frequencies. The frequency source based on this principle is called Frequeney Synthesizer ). The frequency Synthesizer synthesis method can be divided into Direct Synthesizer and IndirectSynthesizer. The phase relationships between output signals can be divided into coherent sources and non-coherent sources.
Concept and example of Direct Frequency Synthesizer (DS)
This is the first frequency synthesizer to be used. It is the necessary frequency obtained by switching, dividing, doubling, mixing, and filtering one or more crystal oscillator. Although the proposed time was early, the initial solution also appeared to be very backward, but because direct simulation of synthesis has a fast rate of frequency reduction, the main advantage of low phase noise makes it play an important role in the field of frequency synthesis.
Directly simulating a frequency synthesizer is prone to generating too many stray components and a large amount of equipment. In recent years, with the development of SAW technology, the new SAW Direct Frequency Synthesizer achieves lower phase noise, more frequent hops, fast frequency variation speed, small size and medium price. It is expected that with the maturity of SAW Technology, SAW direct frequency synthesis technology will make the direct analog frequency synthesizer reproduce brilliant.
SAW direct frequency synthesizer is mainly composed of SAW comb frequency generator, SAW Filter, high-speed conversion switch, divider, and frequency multiplier. SAW frequency synthesizer has been developed abroad. For example, the technical indicators of Radar frequency synthesizer developed by Aircraft Corp are as follows:
Frequency Range: 1369MHz ~ 1606 MHz
Frequency Hopping points: N = 243
Frequency conversion time: t s = 01. μ
Parasitic stray:-47dBc
The technical indexes of four-level multi-synthesis SAW Frequency Synthesizer developed by TRW are as follows:
Frequency Range: 1280MHz ~ 1528 MHz
Frequency Hopping points: N = 256
Frequency interval: △f = 1 MHz
Stray suppression:-43dBc
Frequency conversion time: t s = 0 02 ...... remaining full text>

Direct Digital Frequency Synthesis

Library ieee;
Use ieee. std_logic_00004.all;
Use ieee. std_logic_unsigned.all;
Entity singt is
Port (clk: in std_logic; -- modulated clock
Dout: out std_logic_vector (7 downto 0 );
);
End;
Architecture acc of singt is
Component datarom
Port (address: in std_logic_vector (5 downto 0 );
Clock: in std_logic;
Q: out std_logic_vector (7 downto 0 ));
End component;
Signal q1: std_logic_vector (5 downto 0 );

Begin
Process (clk, x)
Begin
If clk 'event and clk = '1' then
Else q1 <= q1 + 1;
End if;
End process;
U1: datarom port map (address => q1, q => dout, clock => clk );
End;

Then create a ROM with a 5-bit address and 7-Bit Data
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.