Envelope detection C program

Source: Internet
Author: User

Recently, a project was designed to extract the envelope waveform of a sound signal, so it took some time to study various envelope extraction algorithms.

The so-called envelope detection, also called amplitude demodulation, has important applications in many fields. If the carrier signal is determined, the synchronous demodulation method is usually used. The signal-to-noise ratio is the best, and the noise mixing in the signal is the strongest. Synchronous demodulation is a common term in the communication field. In the field of signal detection, this method is usually called phase-sensitive detection. The lock-in amplifier uses the most typical example.

If the carrier is messy, just like in my current application scenarios, the envelope detection method is more suitable to extract the variation of the noise amplitude over time. The code here is the envelope detection method.

The basic principle of the envelope detection method can be seen in the following circuit diagram. This is the most basic half-wave envelope detection.

The following code is available for implementing this process using a program.

/*** Envelope detection, simulating the hardware half-wave detection process * rc = 0 initialization **/Double env_1 (Double X, double RDBMS) {static double old_y = 0.0; if (RDBMS = 0.0) {old_y = 0.0;} else {If (x> old_y) {old_y = x ;} else {old_y * = rdbms/(RDBMS + 1) ;}return old_y;} void env_2 (Double X [], Double Y [], int N, double RDBMS) {double xx= 0.0; int I; y [0] = FABS (X [0]); for (I = 1; I <n; I ++) {If (X [I]> Y [I-1]) {Y [I] = x [I];} else {Y [I] = Y [I-1] * rdbms/(RDBMS + 1 );}}}

The above is the half-wave detection code. You only need to add a few lines to implement full-wave detection.

/*** Envelope detection, simulating the hardware full-wave detection process * rc = 0 when initializing **/Double env_3 (Double X, double RDBMS) {static double old_y = 0.0; if (RDBMS = 0.0) {old_y = 0.0;} else {x = FABS (x); If (x> old_y) {old_y = x ;} else {old_y * = rdbms/(RDBMS + 1) ;}} return old_y;} void env_4 (Double X [], Double Y [], int N, double RDBMS) {double xx= 0.0; int I; y [0] = FABS (X [0]); for (I = 1; I <n; I ++) {xx = FABS (X [I]); If (XX> Y [I-1]) {Y [I] = xx ;} else {Y [I] = Y [I-1] * rdbms/(RDBMS + 1 );}}}

In this Code, there is a parameter named RDBMS, which corresponds to the RC time constant in the hardware circuit. It must be determined based on the frequency band of the envelope signal to be detected.

The following is an example of extracting the envelope with this code. It can be seen that the effect of this Code is quite good. (Better than the result obtained by using the Hilbert transformation)



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.