Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of voice playback with PWM?

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you what is the principle of PWM to achieve voice playback, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Using PWM to play voice principle 1. Overview

Most microcontrollers use DAC to output audio, because there is no CODEC codec chip on the microcontroller, but DAC does not exist on every chip, so what if there is no DAC? So PWM becomes a good choice. Because most microcontroller boards have PWM, this design greatly simplifies the threshold of voice design. The principle is that the PWM can be turned into a DAC, and then the voice signal is outputted. After the power amplifier and the loudspeaker, the digital signal can be turned into a sound signal and output normally.

two。 Sound principle

Anyone who has studied physical knowledge knows that sound is actually a kind of wave, which is transmitted to people's ears through elastic media such as air vibration to cause eardrum vibration and affect the auditory visual nerve of the brain. After brain processing, it will produce hearing.

The frequency range of sounds that people can distinguish ranges from the lowest 20Hz to the highest 20KHz. I learned in high school physics that the three characteristics of sound are: tone, loudness and timbre, loudness is determined by the amplitude of the vibration of the sound source, the greater the amplitude, the greater the loudness; the level of tone is related to the frequency of vibration, and the higher the frequency, the higher the tone; different timbre, the characteristics of waves are also different.

Since sound is a waveform, waves have two characteristics: frequency and amplitude. For the single-chip microcomputer, it takes some skills to express these two concepts. Frequency is the inherent characteristic of the single-chip microcomputer, and the signal of a specific frequency can be generated by the clock. How to express the amplitude, digital signals 0 and 1? Can be expressed by bit width depth, for example, 8 bit width depth can express the quantitative data between 0-256 data, for digital signals, sound data also has sampling bit width, so this can also be described by single-chip microcomputer, DAC can be used to do this, combined with a timer to generate a specific frequency to make the machine sound.

What is the principle of 3.DAC producing sound?

To really understand how DAC works, we must first understand what the analog signal is. The analog signal is a constantly changing voltage, which can perfectly express the ever-changing sound waves. The microphone can convert the incoming sound into analog electrical signals that represent the sound, which are converted into the original sound through the loudspeaker.

So how do you record these analog signals? Long ago, people came up with the idea of storing analog signals as grooves on records. The electrical analog signal of sound is expressed by moving the pointer back and forth. Over time, the grooves have been converted into digital signals stored on hard drives or various tapes, and these zeros or ones represent the information of the audio signal.

For sound signals, the CD can store 16-bit depth quantized binary data (16bit/44kHz) of 44100 times per second. So in the DAC output, we can also use 16-bit wide DAC for sampling, and then convert the sound signal to the frequency of 44kHz, which is not difficult for MCU to operate DAC, only need to enable a 16-bit wide DAC and a timer, timer is used to control the frequency of sound output, such as sampling rate bit 44.1KHz, then output according to the clock frequency.

How does 4.PWM realize DAC?

After understanding the above principles, let's take a look at PWM and how PWM works.

The simplest understanding of PWM (Pulse Width Modulation) is that there is a timer inside the MCU that flips the level of the GPIO for a specific period of time. The proportion of the time interval of the flip is the duty cycle, and the persistence of these two processes can be counted as a cycle. This is a description of digital signals. Let's change our thinking and understand pwm from the perspective of analog signals.

You can see the diagram above, in a cycle, its duty cycle determines the average voltage value, and the red line represents the average voltage. For the data in a cycle, we can quantify it by first setting the voltage between 0mm 5v (0-256), and then we can have an 8-bit resolution (2 ^ 8 = 256). Since each quantization point can represent a voltage, and the voltage is directly related to the duty cycle of a cycle of the PWM, the relationship between the duty cycle and the quantization point can be obtained. The same 16-bit quantitative data is more accurate. But the larger the quantized data, the lower the PWM frequency (the longer the counting time), which is the basic trade-off of PWM. The faster the execution, the lower the accuracy. It is critical here, but it needs to be well understood that with the continuous increase of PWM frequency, the choice of duty cycle is no longer so random, and the accuracy will be greatly reduced.

The relationship between the Frequency of 5.PWM and the bottom noise

Audio equipment has a parameter called signal-to-noise ratio, which is the ratio of signal to noise, so the analog signal will inevitably produce noise. The better the equipment, the greater the signal-to-noise ratio, that is, it takes a very large gain to hear the noise in the end.

Signal-to-noise ratio (Signal-to-noise ratio, abbreviated as SNR or Splash N), also known as signal-to-clutter ratio or signal-to-noise ratio.

Usually the sounds made by PWM can't get rid of this, but these sounds can sometimes become interesting, such as red and white 8bit game music.

To be exact, if you want to improve the sound quality, you can use 16-bit data. It has the following formula:

SNR (dB) = (Bit Depth) * 6.02dB + 1.76dB)

In other words, if you want to achieve better sound effects, there are two ways, the first is to reduce the frequency of PWM, as explained in the previous chapter, if you want to achieve greater depth, you must reduce the frequency of PWM. The second is to increase the number of PWM. According to Nyquist sampling theorem, the highest frequency of PWM is at least twice the highest frequency of sound (20Khz).

The above figure depicts the relationship between sampling frequency and the number of PWM and bit width depth. If you increase the number of PWM, you can improve the accuracy of sampling, for example, without changing the frequency of the PWM can change its bit width depth.

Analysis of 6.PWM Music repertoire

I once saw a very interesting article, which talked about pwm and then used a passive buzzer to play the song "you look good when you smile". I thought it was very interesting. Although my above analysis can not be completely combined with this principle, it can at least help to understand the knowledge of music theory. In music, rhythm and rhythm complement each other and form the skeleton of music. Use PWM to directly supply power to the passive buzzer. When the level is high, the passive buzzer will ring, and the low level will not ring at ordinary times. Then given the beat of the music to make it ring or not, the music can be played, but the sound made by people is much more complicated than this. It is very difficult to show the change of voice and tone.

The above content is what is the principle of voice playback in PWM. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report