CN105974997B - A kind of Digital Implementation method of sine wave signal - Google Patents

A kind of Digital Implementation method of sine wave signal Download PDF

Info

Publication number
CN105974997B
CN105974997B CN201610281047.9A CN201610281047A CN105974997B CN 105974997 B CN105974997 B CN 105974997B CN 201610281047 A CN201610281047 A CN 201610281047A CN 105974997 B CN105974997 B CN 105974997B
Authority
CN
China
Prior art keywords
sine wave
wave signal
sin
cos
value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201610281047.9A
Other languages
Chinese (zh)
Other versions
CN105974997A (en
Inventor
姬宣德
白旭灿
邵麦顿
赵小明
段晓明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Luoyang Matu Network Technology Co ltd
Original Assignee
Luoyang Institute of Science and Technology
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Luoyang Institute of Science and Technology filed Critical Luoyang Institute of Science and Technology
Priority to CN201610281047.9A priority Critical patent/CN105974997B/en
Publication of CN105974997A publication Critical patent/CN105974997A/en
Application granted granted Critical
Publication of CN105974997B publication Critical patent/CN105974997B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F1/00Details not covered by groups G06F3/00 - G06F13/00 and G06F21/00
    • G06F1/02Digital function generators
    • G06F1/022Waveform generators, i.e. devices for generating periodical functions of time, e.g. direct digital synthesizers

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Measurement Of Resistance Or Impedance (AREA)
  • Analogue/Digital Conversion (AREA)

Abstract

本发明涉及一种正弦波信号的数字实现方法,具体为:先设定参数,然后计算一个正弦波信号周期的采样点数N和一个采样点所占用的角度值θ;再计算出sin(θ)和cos(θ)以及sin(2θ)和cos(2θ)的数值;然后计算出正弦波信号的离散点数值f0;再把正弦波信号离散点数值f0送入DAC转换电路,生成连续的正弦波电流信号;最后利用UA运算放大器把连续的正弦波电流信号转换成连续的正弦波电压信号,从而实现正弦波信号的输出。本发明的正弦波信号数字实现方法简化了计算程序,减少了DSP控制器的计算时间;有效减小了连续递推计算导致的累积误差,且占用的存储空间小,成本低;可以很方便地计算出初始的正弦函数值和余弦函数值,灵活地调节正弦波信号的频率。

The invention relates to a digital realization method of a sine wave signal, specifically: first setting parameters, then calculating the number of sampling points N of a sine wave signal cycle and the angle value θ occupied by a sampling point; and then calculating sin(θ) and the values of cos(θ) and sin(2θ) and cos(2θ); then calculate the discrete point value f 0 of the sine wave signal; then send the discrete point value f 0 of the sine wave signal into the DAC conversion circuit to generate a continuous The sine wave current signal; finally, the UA operational amplifier is used to convert the continuous sine wave current signal into a continuous sine wave voltage signal, so as to realize the output of the sine wave signal. The sine wave signal digital implementation method of the present invention simplifies the calculation program, reduces the calculation time of the DSP controller; effectively reduces the cumulative error caused by continuous recursive calculation, and occupies a small storage space and low cost; it can be conveniently Calculate the initial sine function value and cosine function value, and flexibly adjust the frequency of the sine wave signal.

Description

一种正弦波信号的数字实现方法A Digital Realization Method of Sine Wave Signal

技术领域technical field

本发明属于波信号的实现领域,特别是涉及一种正弦波信号的数字实现方法。The invention belongs to the field of realization of wave signals, in particular to a digital realization method of sine wave signals.

背景技术Background technique

正弦波信号发生器已经广泛地应用于通信、仪器仪表和工业控制等领域的信号处理系统中。基于DSP控制器产生正弦波信号的数字实现方法很多,区别主要在于产生算法及软件的不同。常用的方法有三种:查表法、泰勒级数展开法和迭代法。Sine wave signal generators have been widely used in signal processing systems in the fields of communication, instrumentation, and industrial control. There are many digital implementation methods for generating sine wave signals based on DSP controller, the difference mainly lies in the difference of generation algorithm and software. There are three commonly used methods: look-up table method, Taylor series expansion method and iteration method.

查表法是最直接的一种数字实现方法,设计者可以根据运算的需要预先计算好所有可能出现的正弦函数值,将这些结果编排成数据表,在使用时只要根据输入查出表中对应的函数值即可。查表法的特点是速度快、调频调幅容易,但需要占用大量的存储空间,且灵活度低。The look-up table method is the most direct digital implementation method. The designer can pre-calculate all possible sine function values according to the needs of the operation, and arrange these results into a data table. The function value of . The table look-up method is characterized by fast speed and easy frequency and amplitude modulation, but it needs to occupy a large amount of storage space and has low flexibility.

泰勒级数展开法是一种利用多项式逼近正弦函数的数字实现方法,正弦波的波形可以看作由无数点组成,这些点与x轴的每一个角度值θ相对应,可以利用DSP处理器处理大量重复计算(乘加运算)的优势来计算x轴每一点对应的y的值(如果在x轴取N个点来进行逼近,则θ=2π/N)。泰勒级数计算的精度取决于展开项数和点对应角度值θ:展开项数越多精度越高,但计算时间越长,占用DSP控制器的时间就越多;点对应角度值θ越小,精度越高,但随着点对应角度值θ的增加,精度也必然下降。The Taylor series expansion method is a digital implementation method that uses polynomials to approximate the sine function. The waveform of the sine wave can be regarded as composed of countless points. These points correspond to each angle value θ of the x-axis and can be processed by a DSP processor. The advantages of a large number of repeated calculations (multiplication and addition operations) are used to calculate the value of y corresponding to each point on the x-axis (if N points are taken on the x-axis for approximation, then θ=2π/N). The accuracy of Taylor series calculation depends on the number of expansion items and the angle value θ corresponding to the point: the more the number of expansion items, the higher the accuracy, but the longer the calculation time, the more time it takes for the DSP controller; the smaller the angle value θ corresponding to the point , the higher the accuracy is, but the accuracy will inevitably decrease as the angle value θ corresponding to the point increases.

为了克服以上缺点,考虑正弦函数的计算结果可以复用的特点,有学者对泰勒级数展开法进行了改进。首先,用泰勒级数展开法计算0~π/4的正弦与余弦值,保存以上计算结果;其次,利用sin(2θ)=2sin(θ)cos(θ)式求出0~π/2的正弦值;最后,通过复制获得0~2π的正弦值,重复输出该值就可以得到正弦波。由此可看出,改进的泰勒级数展开法利用泰勒级数展开法与查表法结合的方法,通过缩小点对应角度值θ的取值范围来克服泰勒级数展开法随着点对应角度值θ增加而精度下降的缺点,但是同时引入了查表法占用大量存储空间的缺点,而且也没有改变泰勒级数展开法由于展开项数越多导致计算时间越长的固有缺点。In order to overcome the above shortcomings, some scholars have improved the Taylor series expansion method considering the fact that the calculation results of the sine function can be reused. First, use the Taylor series expansion method to calculate the sine and cosine values from 0 to π/4, and save the above calculation results; secondly, use the sin(2θ)=2sin(θ)cos(θ) formula to find the sine and cosine values from 0 to π/2 Sine value; finally, the sine value of 0~2π is obtained by copying, and the sine wave can be obtained by repeatedly outputting this value. It can be seen from this that the improved Taylor series expansion method uses the method of combining the Taylor series expansion method and the look-up table method, and overcomes the problem that the point-corresponding angle value θ of the point-corresponding angle value range of the Taylor series expansion method overcomes the The disadvantage that the value of θ increases and the accuracy decreases, but at the same time, it introduces the disadvantage that the look-up table method takes up a large amount of storage space, and it does not change the inherent disadvantage of the Taylor series expansion method that the calculation time is longer due to the more expansion items.

迭代法是利用数字振荡器通过迭代算法产生正弦波的数字实现方法,它的关键是函数值之间的递推关系,也就是系统的差分方程或系统函数模型。如果一个离散时间系统的系统函数没有零点,只有一对处在单位圆上的共扼极点,则其单位冲激响应为恒幅度振荡,即产生了正弦信号。迭代算法的正弦函数递推公式为:sin(nθ)=2cos(θ)sin[(n-1)θ]-sin[(n-2)θ]。式中,θ=2π/N,N=fs/f为一个正弦波周期内的采用点数,fs为采样频率,f为正弦波频率,n为采样点的序号。迭代法只要首先预置sin(θ)和cos(θ)的数值,就可以计算出后面所有的sin(nθ),并送入DAC转换电路即可生成连续的正弦波信号。迭代法由于是实时生成产生正弦波的离散点数值,因而占用的存储空间相对较少,运算时间短进而占用DSP控制器的时间也就越短。但是,由于新的数值产生利用了之前的函数值,会产生积累误差,尤其是在正弦波的后半部分,积累误差会越来越大,而且当采样点数N不是足够大的时候,误差积累会进一步增大。同时,由于在递推公式计算之前要首先预置sin(θ)和cos(θ)的数值,因而导致采样点数N不可改变,在采样频率fs固定的情况下,影响正弦波频率f的灵活调节。The iterative method is a digital implementation method that uses a digital oscillator to generate a sine wave through an iterative algorithm. Its key is the recursive relationship between function values, that is, the differential equation of the system or the system function model. If the system function of a discrete-time system has no zero point, but only a pair of conjugate poles on the unit circle, its unit impulse response is a constant amplitude oscillation, that is, a sinusoidal signal is generated. The sine function recursion formula of the iterative algorithm is: sin(nθ)=2cos(θ)sin[(n-1)θ]-sin[(n-2)θ]. In the formula, θ=2π/N, N=f s /f is the number of points used in a sine wave cycle, f s is the sampling frequency, f is the frequency of the sine wave, and n is the serial number of the sampling point. In the iterative method, as long as the values of sin(θ) and cos(θ) are preset first, all subsequent sin(nθ) can be calculated and sent to the DAC conversion circuit to generate a continuous sine wave signal. Since the iterative method is to generate the discrete point value of the sine wave in real time, it occupies relatively less storage space, and the operation time is short, which in turn occupies the shorter time of the DSP controller. However, since the new value is generated using the previous function value, there will be cumulative error, especially in the second half of the sine wave, the cumulative error will become larger and larger, and when the number of sampling points N is not large enough, the cumulative error will be will increase further. At the same time, since the values of sin(θ) and cos(θ) must be preset before the calculation of the recursive formula, the number of sampling points N cannot be changed, which affects the flexibility of the sine wave frequency f when the sampling frequency f s is fixed adjust.

发明内容Contents of the invention

为克服现有技术的不足,本发明提出了一种正弦波信号的数字实现方法,有效减小了连续递推计算导致的累积误差,且占用的存储空间小,成本低;可以很方便地计算出初始的正弦函数值和余弦函数值,灵活地调节正弦波信号的频率。In order to overcome the deficiencies of the prior art, the present invention proposes a digital realization method of a sine wave signal, which effectively reduces the cumulative error caused by continuous recursive calculation, and occupies a small storage space and low cost; it can be easily calculated Output the initial sine function value and cosine function value, and flexibly adjust the frequency of the sine wave signal.

本发明的目的及解决其技术问题是采用以下技术方案来实现的。The purpose of the present invention and the solution to its technical problems are achieved by adopting the following technical solutions.

依据本发明提出的一种正弦波信号的数字实现方法,其包括以下步骤:According to the digital realization method of a kind of sine wave signal proposed by the present invention, it comprises the following steps:

(1)、设定参数,具体包括:设定正弦波信号的频率f和幅值A,设定采样频率fs(1), setting parameters specifically include: setting frequency f and amplitude A of sine wave signal, setting sampling frequency f s ;

(2)、计算出一个正弦波信号周期的采样点数N;(2), calculate the number of sampling points N of a sine wave signal cycle;

(3)、计算出一个采样点所占用的角度值θ;(3), calculate the angle value θ that a sampling point occupies;

(4)、在角度值θ在[-0.2,+0.2]之间时,根据角度值θ和正弦函数sin(θ)的近似线性关系,计算出sin(θ)和cos(θ)的数值;(4), when the angle value θ is between [-0.2,+0.2], calculate the numerical value of sin (θ) and cos (θ) according to the approximate linear relationship between the angle value θ and the sine function sin (θ);

(5)、计算sin(2θ)和cos(2θ)的数值;(5) Calculate the values of sin(2θ) and cos(2θ);

(6)、根据采样点n所在区间的不同,交替使用正弦函数和余弦函数的递推公式sin(nθ)=2cos(θ)sin[(n-1)θ]-sin[(n-2)θ]和cos(nθ)=2cos(θ)cos[(n-1)θ]-cos[(n-2)θ]实时计算出正弦波信号的离散点数值f0(6), according to the difference in the interval where the sampling point n is located, alternately use the recursive formula sin(nθ)=2cos(θ)sin[(n-1)θ]-sin[(n-2) of the sine function and the cosine function θ] and cos(nθ)=2cos(θ)cos[(n-1)θ]-cos[(n-2)θ] calculate the discrete point value f 0 of the sine wave signal in real time;

(7)、利用DSP控制器把计算出的正弦波信号离散点数值f0通过接口电路送入DAC转换电路,生成连续的正弦波电流信号;(7), utilize the DSP controller to send the calculated sine wave signal discrete point value f 0 into the DAC conversion circuit through the interface circuit to generate a continuous sine wave current signal;

(8)、最后利用UA运算放大器把连续的正弦波电流信号转换成连续的正弦波电压信号,从而实现正弦波信号的输出。(8) Finally, the UA operational amplifier is used to convert the continuous sine wave current signal into a continuous sine wave voltage signal, thereby realizing the output of the sine wave signal.

本发明的目的及解决其技术问题还可采用以下技术措施进一步实现。The purpose of the present invention and its technical problems can also be further realized by adopting the following technical measures.

前述的一种正弦波信号的数字实现方法,其中,步骤(2)所用的计算公式为N=fs/f。The aforementioned digital implementation method of a sine wave signal, wherein the calculation formula used in step (2) is N=f s /f.

前述的一种正弦波信号的数字实现方法,其中,步骤(3)所用的计算公式为θ=2π/N。In the above-mentioned digital realization method of a sine wave signal, the calculation formula used in step (3) is θ=2π/N.

前述的一种正弦波信号的数字实现方法,其中,步骤(4)利用式sin(θ)≈θ计算出sin(θ)的数值,利用式计算出cos(θ)的数值。The digital implementation method of the aforesaid sine wave signal, wherein, step (4) uses the formula sin(θ)≈θ to calculate the value of sin(θ), and uses the formula Calculate the value of cos(θ).

前述的一种正弦波信号的数字实现方法,其中,步骤(5)利用式sin(2θ)=2sin(θ)cos(θ)计算出sin(2θ)的数值,利用式cos(2θ)=[cos(θ)+sin(θ)][cos(θ)-sin(θ)]计算出cos(2θ)的数值。The digital realization method of a kind of aforementioned sine wave signal, wherein, step (5) utilizes formula sin(2θ)=2sin(θ)cos(θ) to calculate the numerical value of sin(2θ), utilizes formula cos(2θ)=[ cos(θ)+sin(θ)][cos(θ)-sin(θ)] calculates the value of cos(2θ).

前述的一种正弦波信号的数字实现方法,其中,步骤(6)的具体算法为:The digital realization method of aforesaid a kind of sine wave signal, wherein, the concrete algorithm of step (6) is:

令f1s=sin(θ)、f1c=cos(θ)、f2s=sin(2θ)、f2c=cos(2θ);n=1;Let f 1s =sin(θ), f 1c =cos(θ), f 2s =sin(2θ), f 2c =cos(2θ); n=1;

①采样点n在[1,N/4]区间时,令i=n:①When the sampling point n is in the [1,N/4] interval, let i=n:

如果i=1,则f3=f1s,f0=Af3,f1=f1sIf i=1, then f 3 =f 1s , f 0 =Af 3 , f 1 =f 1s ;

如果i=2,则f3=f2s,f0=Af3,f2=f2sIf i=2, then f 3 =f 2s , f 0 =Af 3 , f 2 =f 2s ;

如果i≥3,则f3=2f1cf2-f1,f0=Af3,f1=f2,f2=f3If i≥3, then f 3 =2f 1c f 2 −f 1 , f 0 =Af 3 , f 1 =f 2 , f 2 =f 3 ;

同时n=n+1;At the same time n=n+1;

如果n≤N/4,则重复执行①,否则转入②;If n≤N/4, repeat ①, otherwise transfer to ②;

②采样点n在(N/4,N/2]区间时,令j=n-N/4:②When the sampling point n is in the interval (N/4,N/2], set j=n-N/4:

如果j=1,则f6=f1c,f0=Af6,f4=f1cIf j=1, then f 6 =f 1c , f 0 =Af 6 , f 4 =f 1c ;

如果j=2,则f6=f2c,f0=Af6,f5=f2cIf j=2, then f 6 =f 2c , f 0 =Af 6 , f 5 =f 2c ;

如果j≥3,则f6=2f1cf5-f4,f0=Af6,f4=f5,f5=f6If j≥3, then f 6 =2f 1c f 5 −f 4 , f 0 =Af 6 , f 4 =f 5 , f 5 =f 6 ;

同时n=n+1;At the same time n=n+1;

如果n≤N/2,则重复执行②,否则转入③;If n≤N/2, repeat ②, otherwise transfer to ③;

③采样点n在(N/2,3N/4]区间时,令i=n-N/2:③ When the sampling point n is in the interval (N/2, 3N/4], let i=n-N/2:

如果i=1,则f3=-f1s,f0=Af3,f1=-f1sIf i=1, then f 3 =-f 1s , f 0 =Af 3 , f 1 =-f 1s ;

如果i=2,则f3=-f2s,f0=Af3,f2=-f2sIf i=2, then f 3 =-f 2s , f 0 =Af 3 , f 2 =-f 2s ;

如果i≥3,则f3=2f1cf2-f1,f0=Af3,f1=f2,f2=f3If i≥3, then f 3 =2f 1c f 2 −f 1 , f 0 =Af 3 , f 1 =f 2 , f 2 =f 3 ;

同时n=n+1;At the same time n=n+1;

如果n≤3N/4,则重复执行③,否则转入④;If n≤3N/4, repeat ③, otherwise transfer to ④;

④采样点n在(3N/4,N]区间时,令j=n-3N/4:④ When the sampling point n is in the (3N/4,N] interval, set j=n-3N/4:

如果j=1,则f6=-f1c,f0=Af6,f4=-f1cIf j=1, then f 6 =-f 1c , f 0 =Af 6 , f 4 =-f 1c ;

如果j=2,则f6=-f2c,f0=Af6,f5=-f2cIf j=2, then f 6 =-f 2c , f 0 =Af 6 , f 5 =-f 2c ;

如果j≥3,则f6=2f1cf5-f4,f0=Af6,f4=f5,f5=f6If j≥3, then f 6 =2f 1c f 5 −f 4 , f 0 =Af 6 , f 4 =f 5 , f 5 =f 6 ;

同时n=n+1;At the same time n=n+1;

如果n≤N,则重复执行④,否则,令n=1,转入①,开始下一个正弦波信号周期。If n≤N, execute ④ repeatedly, otherwise, set n=1, turn to ①, and start the next cycle of the sine wave signal.

前述的一种正弦波信号的数字实现方法,其中,所述方法通过生成正弦波信号的电路系统实现,该电路系统包括:键盘输入电路、DSP控制器、接口电路、DAC转换电路和UA运算放大器;其中,键盘输入电路的输出端与DSP控制器连接,DSP控制器的输出端与接口电路连接,接口电路的输出端与DAC转换电路连接,DAC转换电路的输出端与UA运算放大器连接,UA运算放大器输出正弦波信号。The digital realization method of a kind of aforementioned sine wave signal, wherein, described method is realized by the circuit system that generates sine wave signal, and this circuit system comprises: keyboard input circuit, DSP controller, interface circuit, DAC conversion circuit and UA operational amplifier ; Wherein, the output end of the keyboard input circuit is connected with the DSP controller, the output end of the DSP controller is connected with the interface circuit, the output end of the interface circuit is connected with the DAC conversion circuit, the output end of the DAC conversion circuit is connected with the UA operational amplifier, and the UA The operational amplifier outputs a sine wave signal.

所述接口电路是缓冲DSP控制器与DAC转换电路之间的速度差,以保证正弦波信号的离散点数值准确可靠地送入DAC转换电路的一种电路。The interface circuit is a circuit that buffers the speed difference between the DSP controller and the DAC conversion circuit to ensure that the discrete point values of the sine wave signal are accurately and reliably sent to the DAC conversion circuit.

所述DAC转换电路把通过接口电路送入的正弦波信号的离散点数值转换成连续的正弦波电流信号。The DAC conversion circuit converts the discrete point value of the sine wave signal input through the interface circuit into a continuous sine wave current signal.

所述UA运算放大器把连续的正弦波电流信号转换成连续的正弦波电压信号。The UA operational amplifier converts a continuous sinusoidal current signal into a continuous sinusoidal voltage signal.

本发明与现有技术相比具有明显的优点和有益效果,借由上述技术方案,本发明一种正弦波信号的数字实现方法可达到相当的技术进步性及实用性,并具有产业上的广泛利用价值,其至少具有下列优点:Compared with the prior art, the present invention has obvious advantages and beneficial effects. With the above-mentioned technical scheme, a digital realization method of a sine wave signal in the present invention can achieve considerable technical advancement and practicability, and has wide industrial application Utilization value, which has at least the following advantages:

(1)、本发明利用角度值θ和正弦函数sin(θ)的近似线性关系,而不是利用泰勒级数展开公式,计算出初始的正弦函数值和余弦函数值,简化了计算程序,从而减少了DSP控制器的计算时间;(1), the present invention utilizes the approximate linear relationship of angle value θ and sine function sin (θ), rather than utilizing Taylor series expansion formula, calculates initial sine function value and cosine function value, simplifies calculation program, thereby reduces The calculation time of the DSP controller is reduced;

(2)、本发明根据采样点n所在区间的不同,利用DSP控制器交替使用正弦函数和余弦函数的递推公式实时计算出正弦波信号的离散点数值,而不像迭代法那样只用正弦函数递推公式,从而减小了递推公式因连续递推计算导致的累积误差,而且由于实时计算出正弦波信号的离散点数值,不也像查表法大量占用存储空间,从而减少对DSP控制器存储空间的占用,降低了成本;(2), the present invention calculates the discrete point value of sine wave signal in real time by using the recursive formula of sine function and cosine function alternately by DSP controller according to the difference in the interval of sampling point n, instead of only using sine like iterative method The function recursive formula reduces the cumulative error caused by the continuous recursive calculation of the recursive formula, and because the discrete point value of the sine wave signal is calculated in real time, it does not occupy a large amount of storage space like the look-up table method, thereby reducing the need for DSP The occupancy of the controller storage space reduces the cost;

(3)、本发明由于可以很方便地计算出初始的正弦函数值和余弦函数值,不需要像迭代法那样要预置初始的正弦函数值和余弦函数值,采样点数N可改变,因而即使在采样频率fs固定的情况下,仍可以灵活地调节正弦波信号的频率。(3), the present invention owing to can calculate initial sine function value and cosine function value easily, does not need to preset initial sine function value and cosine function value like iterative method, sampling point number N can change, thus even if When the sampling frequency f s is fixed, the frequency of the sine wave signal can still be adjusted flexibly.

综上所述,本发明一种正弦波信号的数字实现方法在技术上有显著的进步,并具有明显的积极效果,诚为一新颖、进步、实用的新设计。To sum up, the digital realization method of a sine wave signal of the present invention has significant technical progress, and has obvious positive effects. It is a novel, progressive and practical new design.

上述说明仅是本发明技术方案的概述,为了能够更清楚了解本发明的技术手段,而可依照说明书的内容予以实施,并且为了让本发明的上述和其他目的、特征和优点能够更明显易懂,以下特举较佳实施例,并配合附图,详细说明如下。The above description is only an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention, it can be implemented according to the contents of the description, and in order to make the above and other purposes, features and advantages of the present invention more obvious and understandable , the following preferred embodiments are specifically cited below, and are described in detail as follows in conjunction with the accompanying drawings.

附图说明Description of drawings

图1为本发明的正弦波信号数字实现方法的电路系统图。Fig. 1 is a circuit system diagram of the digital realization method of the sine wave signal of the present invention.

图2为本发明的角度值θ和正弦函数sin(θ)的近似线性关系图。Fig. 2 is an approximate linear relationship diagram between the angle value θ and the sine function sin(θ) in the present invention.

具体实施方式Detailed ways

为更进一步阐述本发明为达成预定发明目的所采取的技术手段及功效,以下结合附图及较佳实施例,对依据本发明提出的一种正弦波信号的数字实现方法,其具体实施方式、结构、特征及其功效,详细说明如后。In order to further explain the technical means and effects that the present invention adopts to achieve the intended purpose of the invention, below in conjunction with the accompanying drawings and preferred embodiments, a digital implementation method for a sine wave signal proposed according to the present invention, its specific implementation, Structure, characteristic and effect thereof are as follows in detail.

本发明的一种正弦波信号的数字实现方法,结合图1所示,在硬件电路结构上,包括:键盘输入电路、DSP控制器、接口电路、DAC转换电路和UA运算放大器;在软件结构上包括角度值θ和正弦函数sin(θ)。其中:键盘输入电路的主要目的是设定正弦波信号的频率和幅值,以及采样频率。DSP控制器根据键盘输入电路设定的正弦波信号频率、幅值和采样频率,计算正弦波信号的离散点数值,同时把离散点数值通过接口电路送入DAC转换电路。接口电路用于缓冲DSP控制器与DAC转换电路的速度差,以保证正弦波信号的离散点数值准确地可靠地送入DAC转换电路。DAC转换电路主要用于把通过接口电路送入的正弦波信号的离散点数值转换成连续的正弦波电流信号。如果需要的正弦波信号为电压信号,则需要利用UA运算放大器把连续的正弦波电流信号转换成连续的正弦波电压信号。The digital implementation method of a kind of sine wave signal of the present invention, in conjunction with shown in Fig. 1, on hardware circuit structure, comprise: keyboard input circuit, DSP controller, interface circuit, DAC conversion circuit and UA operational amplifier; On software structure Including the angle value θ and the sine function sin(θ). Among them: the main purpose of the keyboard input circuit is to set the frequency and amplitude of the sine wave signal, as well as the sampling frequency. The DSP controller calculates the discrete point value of the sine wave signal according to the frequency, amplitude and sampling frequency of the sine wave signal set by the keyboard input circuit, and at the same time sends the discrete point value to the DAC conversion circuit through the interface circuit. The interface circuit is used to buffer the speed difference between the DSP controller and the DAC conversion circuit, so as to ensure that the discrete point value of the sine wave signal is accurately and reliably sent to the DAC conversion circuit. The DAC conversion circuit is mainly used to convert the discrete point value of the sine wave signal sent through the interface circuit into a continuous sine wave current signal. If the required sine wave signal is a voltage signal, it is necessary to use the UA operational amplifier to convert the continuous sine wave current signal into a continuous sine wave voltage signal.

一种正弦波信号的数字实现方法是通过上述的正弦波数字实现系统,首先根据采样频率fs和正弦波频率f的比值计算出一个正弦波信号周期的采样点数N,利用式θ=2π/N计算出一个采样点数所占用的角度值θ。利用角度值θ和正弦函数sin(θ)的近似线性关系计算出正弦函数sin(θ)的数值,利用式cos(θ)≈1-0.5θ2计算出余弦函数cos(θ)的数值。然后,利用DSP控制器,在采样点n=[1,N/4]区间,使用正弦函数的递推公式计算出正弦波信号的离散点数值;在采样点n=(N/4,N/2]区间,使用余弦函数的递推公式计算出正弦波信号的离散点数值;在采样点n=(N/2,3N/4]区间,使用正弦函数的递推公式计算出正弦波信号的离散点数值;在采样点n=(3N/4,N]区间,使用余弦函数的递推公式计算出正弦波信号的离散点数值。最后通过DAC转换电路把正弦波信号的离散点数值转换成连续的正弦波信号,从而实现正弦波信号的输出。正弦波信号数字实现系统的电路框图如图1所示。A kind of digital realization method of sine wave signal is to realize the system by above-mentioned sine wave number, at first calculate the sampling point number N of a sine wave signal period according to the ratio of sampling frequency f s and sine wave frequency f, utilize formula θ=2π/ N calculates the angle value θ occupied by one sampling point. Use the approximate linear relationship between the angle value θ and the sine function sin(θ) to calculate the value of the sine function sin(θ), and use the formula cos(θ)≈1-0.5θ 2 to calculate the value of the cosine function cos(θ). Then, utilize DSP controller, in the interval of sampling point n=[1, N/4], use the recursive formula of sine function to calculate the discrete point value of sine wave signal; At sampling point n=(N/4, N/ 2] interval, use the recursive formula of the cosine function to calculate the discrete point value of the sine wave signal; in the sampling point n=(N/2, 3N/4] interval, use the recursive formula of the sine function to calculate the value of the sine wave signal Discrete point value; in the sampling point n=(3N/4, N] interval, use the recursive formula of the cosine function to calculate the discrete point value of the sine wave signal. Finally, the discrete point value of the sine wave signal is converted into Continuous sine wave signal, so as to realize the output of sine wave signal. The circuit block diagram of the sine wave signal digital realization system is shown in Figure 1.

泰勒级数展开法是利用勒级数展开公式来计算正弦函数sin(θ)和余弦函数cos(θ)的数值,需要DSP控制器的多次乘加运算才成完成正弦函数sin(θ)和余弦函数cos(θ)的计算;迭代法虽然可以预置正弦函数sin(θ)和余弦函数cos(θ)的数值,但改变正弦波信号频率的灵活性受到限制。The Taylor series expansion method is to use the Taylor series expansion formula to calculate the value of the sine function sin(θ) and the cosine function cos(θ), which requires multiple multiplication and addition operations of the DSP controller to complete the sine function sin(θ) and Calculation of the cosine function cos(θ); Although the iterative method can preset the values of the sine function sin(θ) and the cosine function cos(θ), the flexibility of changing the frequency of the sine wave signal is limited.

一般情况下,角度值θ和正弦函数sin(θ)的关系是非线性的。但是当角度值θ在[-0.2,+0.2]之间时,角度值θ和正弦函数sin(θ)的关系几乎是线性的,图2反映的就是角度值θ和正弦函数sin(θ)的近似线性关系。从图2可以看出,在角度值θ比较小的情况下,角度值θ和正弦函数sin(θ)近似线性关系。由此,在保证角度值θ比较小的情况下,可以利用角度值θ和正弦函数sin(θ)的近似线性关系sin(θ)≈θ,直接得到正弦函数sin(θ)的数值为θ,不需要计算,即可直接得到正弦函数sin(θ)的数值,简化了计算程序,减轻了DSP控制器的负担;而余弦函数cos(θ),只需要三次乘法和一次减法运算,就可以通过式cos(θ)≈1-0.5θ2计算出来,远比泰勒级数展开公式用的计算量小。因此,这种正弦波信号的数字实现方法即克服了泰勒级数展开法计算量大的缺点,还克服了查表法占用大量存储空间的不足,而且拥有迭代法所不具备的正弦波信号频率调节的灵活性。In general, the relationship between the angle value θ and the sine function sin(θ) is nonlinear. But when the angle value θ is between [-0.2,+0.2], the relationship between the angle value θ and the sine function sin(θ) is almost linear, and Figure 2 reflects the relationship between the angle value θ and the sine function sin(θ) Approximate linear relationship. It can be seen from Figure 2 that when the angle value θ is relatively small, the relationship between the angle value θ and the sinusoidal function sin(θ) is approximately linear. Therefore, in the case of ensuring that the angle value θ is relatively small, the approximate linear relationship sin(θ)≈θ between the angle value θ and the sine function sin(θ) can be used to directly obtain the value of the sine function sin(θ) as θ, The value of the sine function sin(θ) can be directly obtained without calculation, which simplifies the calculation procedure and reduces the burden on the DSP controller; while the cosine function cos(θ) only needs three multiplications and one subtraction, and can be passed The formula cos(θ)≈1-0.5θ 2 is calculated, which is much smaller than the amount of calculation used by the Taylor series expansion formula. Therefore, the digital implementation method of this sine wave signal not only overcomes the shortcomings of the large amount of calculation of the Taylor series expansion method, but also overcomes the shortage of the look-up table method taking up a large amount of storage space, and has a sine wave signal frequency that the iterative method does not have. Adjustment flexibility.

以上所述,仅是本发明的较佳实施例而已,并非对本发明作任何形式上的限制,虽然本发明已以较佳实施例揭露如上,然而并非用以限定本发明,任何熟悉本专业的技术人员,在不脱离本发明技术方案范围内,当可利用上述揭示的技术内容作出些许更动或修饰为等同变化的等效实施例,但凡是未脱离本发明技术方案的内容,依据本发明的技术实质对以上实施例所作的任何简单修改、等同变化与修饰,均仍属于本发明技术方案的范围内。The above description is only a preferred embodiment of the present invention, and does not limit the present invention in any form. Although the present invention has been disclosed as above with preferred embodiments, it is not intended to limit the present invention. Anyone familiar with this field Those skilled in the art, without departing from the scope of the technical solution of the present invention, can use the technical content disclosed above to make some changes or modify equivalent embodiments with equivalent changes. Any simple modifications, equivalent changes and modifications made to the above embodiments by the technical essence still belong to the scope of the technical solution of the present invention.

Claims (7)

1.一种正弦波信号的数字实现方法,其特征在于其包括以下步骤:1. A digital realization method of a sine wave signal, characterized in that it comprises the following steps: (1)、设定参数,具体包括:设定正弦波信号的频率f和幅值A,设定采样频率fs(1), setting parameters specifically include: setting frequency f and amplitude A of sine wave signal, setting sampling frequency f s ; (2)、计算出一个正弦波信号周期的采样点数N;(2), calculate the number of sampling points N of a sine wave signal period; (3)、计算出一个采样点所占用的角度值θ;(3), calculate the angle value θ that a sampling point occupies; (4)、在角度值θ在[-0.2,+0.2]之间时,根据角度值θ和正弦函数sin(θ)的近似线性关系,计算出sin(θ)和cos(θ)的数值,具体为:(4), when the angle value θ is between [-0.2,+0.2], calculate the values of sin(θ) and cos(θ) according to the approximate linear relationship between the angle value θ and the sine function sin(θ), Specifically: sin(θ)≈θ, sin(θ)≈θ, (5)、计算sin(2θ)和cos(2θ)的数值,其中,sin(2θ)=2sin(θ)cos(θ),cos(2θ)=[cos(θ)+sin(θ)][cos(θ)-sin(θ)];(5), calculate the value of sin(2θ) and cos(2θ), wherein, sin(2θ)=2sin(θ)cos(θ), cos(2θ)=[cos(θ)+sin(θ)][ cos(θ)-sin(θ)]; (6)、根据采样点n所在区间的不同,交替使用正弦函数和余弦函数的递推公式sin(nθ)=2cos(θ)sin[(n-1)θ]-sin[(n-2)θ]和cos(nθ)=2cos(θ)cos[(n-1)θ]-cos[(n-2)θ]实时计算出正弦波信号的离散点数值f0;其具体算法为:(6), according to the difference in the interval where the sampling point n is located, alternately use the recursive formula sin(nθ)=2cos(θ)sin[(n-1)θ]-sin[(n-2) of the sine function and the cosine function θ] and cos(nθ)=2cos(θ)cos[(n-1)θ]-cos[(n-2)θ] calculate the discrete point value f 0 of the sine wave signal in real time; its specific algorithm is: 令f1s=sin(θ)、f1c=cos(θ)、f2s=sin(2θ)、f2c=cos(2θ);n=1;Let f 1s =sin(θ), f 1c =cos(θ), f 2s =sin(2θ), f 2c =cos(2θ); n=1; ①采样点n在[1,N/4]区间时,令i=n:①When the sampling point n is in the [1,N/4] interval, let i=n: 如果i=1,则f3=f1s,f0=Af3,f1=f1sIf i=1, then f 3 =f 1s , f 0 =Af 3 , f 1 =f 1s ; 如果i=2,则f3=f2s,f0=Af3,f2=f2sIf i=2, then f 3 =f 2s , f 0 =Af 3 , f 2 =f 2s ; 如果i≥3,则f3=2f1cf2-f1,f0=Af3,f1=f2,f2=f3If i≥3, then f 3 =2f 1c f 2 −f 1 , f 0 =Af 3 , f 1 =f 2 , f 2 =f 3 ; 同时n=n+1;At the same time n=n+1; 如果n≤N/4,则重复执行①,否则转入②;If n≤N/4, repeat ①, otherwise transfer to ②; ②采样点n在(N/4,N/2]区间时,令j=n-N/4:②When the sampling point n is in the interval (N/4,N/2], set j=n-N/4: 如果j=1,则f6=f1c,f0=Af6,f4=f1cIf j=1, then f 6 =f 1c , f 0 =Af 6 , f 4 =f 1c ; 如果j=2,则f6=f2c,f0=Af6,f5=f2cIf j=2, then f 6 =f 2c , f 0 =Af 6 , f 5 =f 2c ; 如果j≥3,则f6=2f1cf5-f4,f0=Af6,f4=f5,f5=f6If j≥3, then f 6 =2f 1c f 5 −f 4 , f 0 =Af 6 , f 4 =f 5 , f 5 =f 6 ; 同时n=n+1;At the same time n=n+1; 如果n≤N/2,则重复执行②,否则转入③;If n≤N/2, repeat ②, otherwise transfer to ③; ③采样点n在(N/2,3N/4]区间时,令i=n-N/2:③ When the sampling point n is in the interval (N/2, 3N/4], let i=n-N/2: 如果i=1,则f3=-f1s,f0=Af3,f1=-f1sIf i=1, then f 3 =-f 1s , f 0 =Af 3 , f 1 =-f 1s ; 如果i=2,则f3=-f2s,f0=Af3,f2=-f2sIf i=2, then f 3 =-f 2s , f 0 =Af 3 , f 2 =-f 2s ; 如果i≥3,则f3=2f1cf2-f1,f0=Af3,f1=f2,f2=f3If i≥3, then f 3 =2f 1c f 2 −f 1 , f 0 =Af 3 , f 1 =f 2 , f 2 =f 3 ; 同时n=n+1;At the same time n=n+1; 如果n≤3N/4,则重复执行③,否则转入④;If n≤3N/4, repeat ③, otherwise transfer to ④; ④采样点n在(3N/4,N]区间时,令j=n-3N/4:④ When the sampling point n is in the (3N/4,N] interval, set j=n-3N/4: 如果j=1,则f6=-f1c,f0=Af6,f4=-f1cIf j=1, then f 6 =-f 1c , f 0 =Af 6 , f 4 =-f 1c ; 如果j=2,则f6=-f2c,f0=Af6,f5=-f2cIf j=2, then f 6 =-f 2c , f 0 =Af 6 , f 5 =-f 2c ; 如果j≥3,则f6=2f1cf5-f4,f0=Af6,f4=f5,f5=f6If j≥3, then f 6 =2f 1c f 5 −f 4 , f 0 =Af 6 , f 4 =f 5 , f 5 =f 6 ; 同时n=n+1;At the same time n=n+1; 如果n≤N,则重复执行④,否则,令n=1,转入①,开始下一个正弦波信号周期;If n≤N, repeat ④, otherwise, set n=1, turn to ①, and start the next sine wave signal cycle; (7)、利用DSP控制器把计算出的正弦波信号离散点数值f0通过接口电路送入DAC转换电路,生成连续的正弦波电流信号;(7), utilize the DSP controller to send the calculated sine wave signal discrete point value f 0 into the DAC conversion circuit through the interface circuit to generate a continuous sine wave current signal; (8)、最后利用UA运算放大器把连续的正弦波电流信号转换成连续的正弦波电压信号,从而实现正弦波信号的输出。(8) Finally, the UA operational amplifier is used to convert the continuous sine wave current signal into a continuous sine wave voltage signal, thereby realizing the output of the sine wave signal. 2.如权利要求1所述的方法,其特征在于步骤(2)所用的计算公式为N=fs/f。2. The method according to claim 1, characterized in that the calculation formula used in step (2) is N=f s /f. 3.如权利要求1所述的方法,其特征在于步骤(3)所用的计算公式为θ=2π/N。3. The method according to claim 1, characterized in that the calculation formula used in step (3) is θ=2π/N. 4.如权利要求1所述的方法,其特征在于所述方法通过生成正弦波信号的电路系统实现,该电路系统包括:键盘输入电路、DSP控制器、接口电路、DAC转换电路和UA运算放大器;其中,键盘输入电路的输出端与DSP控制器连接,DSP控制器的输出端与接口电路连接,接口电路的输出端与DAC转换电路连接,DAC转换电路的输出端与UA运算放大器连接,UA运算放大器输出正弦波信号。4. The method according to claim 1, characterized in that said method is realized by generating a circuit system of sine wave signal, which circuit system comprises: keyboard input circuit, DSP controller, interface circuit, DAC conversion circuit and UA operational amplifier ; Wherein, the output end of the keyboard input circuit is connected with the DSP controller, the output end of the DSP controller is connected with the interface circuit, the output end of the interface circuit is connected with the DAC conversion circuit, the output end of the DAC conversion circuit is connected with the UA operational amplifier, and the UA The operational amplifier outputs a sine wave signal. 5.如权利要求4所述的方法,其特征在于所述电路系统中的接口电路是缓冲DSP控制器与DAC转换电路之间的速度差,以保证正弦波信号的离散点数值准确可靠地送入DAC转换电路的一种电路。5. The method according to claim 4, characterized in that the interface circuit in the circuit system is to buffer the speed difference between the DSP controller and the DAC conversion circuit, so as to ensure that the discrete point value of the sine wave signal is accurately and reliably sent A circuit that enters the DAC conversion circuit. 6.如权利要求4所述的方法,其特征在于所述电路系统中的DAC转换电路把通过接口电路送入的正弦波信号的离散点数值转换成连续的正弦波电流信号。6. The method according to claim 4, characterized in that the DAC conversion circuit in the circuit system converts the discrete point value of the sine wave signal sent in through the interface circuit into a continuous sine wave current signal. 7.如权利要求4所述的方法,其特征在于所述电路系统中的UA运算放大器把连续的正弦波电流信号转换成连续的正弦波电压信号。7. The method of claim 4, wherein the UA operational amplifier in the circuit system converts the continuous sinusoidal current signal into a continuous sinusoidal voltage signal.
CN201610281047.9A 2016-04-29 2016-04-29 A kind of Digital Implementation method of sine wave signal Active CN105974997B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610281047.9A CN105974997B (en) 2016-04-29 2016-04-29 A kind of Digital Implementation method of sine wave signal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610281047.9A CN105974997B (en) 2016-04-29 2016-04-29 A kind of Digital Implementation method of sine wave signal

Publications (2)

Publication Number Publication Date
CN105974997A CN105974997A (en) 2016-09-28
CN105974997B true CN105974997B (en) 2018-08-14

Family

ID=56994849

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610281047.9A Active CN105974997B (en) 2016-04-29 2016-04-29 A kind of Digital Implementation method of sine wave signal

Country Status (1)

Country Link
CN (1) CN105974997B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TWI718625B (en) 2019-08-16 2021-02-11 瑞昱半導體股份有限公司 Computation circuit used in dct, dst, idct and idst
TWI799302B (en) 2022-06-24 2023-04-11 瑞昱半導體股份有限公司 Computation circuit used in dct, dst, idct and idst

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106569541B (en) * 2016-10-17 2019-09-17 深圳市科陆精密仪器有限公司 Sine wave generation method and device
CN108010537A (en) * 2017-12-30 2018-05-08 长沙迪普美医疗科技有限公司 A kind of audible alarm processing method, device, system
CN109115533B (en) * 2018-09-07 2020-10-27 天津福云天翼科技有限公司 Real-time accurate reproduction method of sine wave
CN112803896A (en) * 2021-01-07 2021-05-14 配天机器人技术有限公司 Sinusoidal signal generation method, device, equipment and medium
CN118192755B (en) * 2024-05-15 2024-08-20 南京丰道电力科技有限公司 Method and system for generating slip waveform based on fixed time interval

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1666407A (en) * 2002-07-08 2005-09-07 索尼株式会社 Waveform generating device and method, and decoder
CN103065039A (en) * 2012-12-10 2013-04-24 北京航空航天大学 High-precision sine/cosine function computing method based on Euler's formula

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1666407A (en) * 2002-07-08 2005-09-07 索尼株式会社 Waveform generating device and method, and decoder
CN103065039A (en) * 2012-12-10 2013-04-24 北京航空航天大学 High-precision sine/cosine function computing method based on Euler's formula

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TWI718625B (en) 2019-08-16 2021-02-11 瑞昱半導體股份有限公司 Computation circuit used in dct, dst, idct and idst
TWI799302B (en) 2022-06-24 2023-04-11 瑞昱半導體股份有限公司 Computation circuit used in dct, dst, idct and idst

Also Published As

Publication number Publication date
CN105974997A (en) 2016-09-28

Similar Documents

Publication Publication Date Title
CN105974997B (en) A kind of Digital Implementation method of sine wave signal
CN101807089B (en) Waveform signal generator with arbitrarily adjustable output signal offset
CN103368538B (en) The digital pulse width modulation device and method that a kind of switching frequency range is adjustable
CN115575707A (en) Harmonic detection device and method based on combination of improved FFT algorithm and wavelet transform
CN102969913B (en) Method for compensating mismatching of model predictive control parameters for initiative front-end rectifier
CN107436619B (en) High-precision low-cost digital sine wave generating device
CN103870238A (en) Pseudo-random sequence generator based on FPGA (Field Programmable Gate Array) and generation method thereof
CN101257248A (en) Low-power single-phase/three-phase low-distortion frequency conversion power supply
CN105866483B (en) A kind of implementation method with dsp controller generation sine wave signal
CN106155177B (en) The method for realizing SPWM waveforms based on digital processing unit
Shan et al. Design and implementation of a FPGA-based direct digital synthesizer
CN104811193A (en) Phase adjustable multi-channel clock signal synthesizing device
CN102497205B (en) Improved DDS signal generator and signal generating method
Xu et al. A method for implementing fractional order differentiator and integrator based on digital oscilloscope
CN103365827A (en) Computing method of high-precision sine/cosine function
CN109901382A (en) A kind of rule sampling PWM optimization method of numerical control system
CN109857188A (en) A method, device and system for generating pulse wave based on DDS
JP5883705B2 (en) Signal generator
Limin Function signal generator
CN109714048B (en) DDS circuit with phase mode changeable and phase output method
TWI495269B (en) A successive approximation multiplier-divider for signal process and method for signal process
CN108322189A (en) A kind of perturbation phase-modulation DDS signal generating methods
Ying et al. A Method of ADC Circuit Noise Optimization based on A Stochastic Resonance Bistable System
TWI407683B (en) Non-linear oscillator
Jia et al. The design of signal generator with DDS based on FPGA

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20221130

Address after: 471000 Room 204, Building 1, Zone B, Luoguo University Science Park, No. 2 Penglai Road, Jianxi District, Luoyang District, China (Henan) Pilot Free Trade Zone, Luoyang City, Henan Province

Patentee after: Luoyang Matu Network Technology Co.,Ltd.

Address before: 471000 No.71, Jiudu West Road, Jianxi District, Luoyang City, Henan Province

Patentee before: LUOYANG INSTITUTE OF SCIENCE AND TECHNOLOGY

TR01 Transfer of patent right