Practical application of the Fourier transform for signal processing. Digital signal processing on ARM7 microcontrollers Fourier transform avr

Fourier's theorem states that any signal can be expanded into a series in an orthonormal set of periodic functions (for example, sines and cosines) with frequencies that are multiples of the frequency of the periodic signal. Thus, the spectral analysis of a signal is based on the search for weighting coefficients (in the general case, complex ones), the module of which corresponds to the fraction of the oscillation power of the corresponding harmonic introduced into the general superposition of all harmonics.

Fast Fourier Transform

The Fast Fourier Transform is a calculation algorithm that successfully exploits the periodicity properties of trigonometric functions to avoid unnecessary calculations in the discrete Fourier transform (DFT), thereby making it faster to find coefficients in the Fourier expansion. The main difference from discrete conversion is only in the method of calculating numerical values ​​(algorithm), and not in the signal processing itself. Both in the case of FFT and in the case of DFT, the result of the calculations is the same. The only requirement for the FFT algorithm is a sample size that is a multiple of N = 2L, where L is any positive integer. The most common base-2 FFT algorithms are: time-decimated and frequency-decimated.

In this work, a radix-2 FFT algorithm with time thinning (Cooley-Tukey algorithm) is implemented. It is easy to obtain by studying some DFT laws. Let's introduce the so-called rotation coefficient:

In this case, in the DFT, the Fourier coefficients for a number of signal values ​​(f0,f1,…,fN-1) are expressed by the relation:

Consider a signal series of 4 values: (f0,f1,f2,f3). Let us present the Fourier transform in matrix form (the normalization coefficient 1/N is included in the column vector Cij on the right side of the expression):

Having written the rotation coefficients using Euler's formula and determined their values ​​for k = 0, 1, 2,.. 9, you can construct a diagram (Fig. 2), from which the pattern of repeating coefficients can be seen.

Figure 2. Power series w for N=4

Substituting numerical values ​​into (4) we get:

That is, the values ​​of w, starting from w4, are equal to the corresponding value from w0 to w3. Next, we rewrite matrix equation (4) in a non-standard form (similar notations are introduced for clarity of further operations):

Let's swap the columns of the matrix, dividing it into two groups: by even f0, f2 and odd f1, f3 indices:

Let us take into account that wk+1 = wkw1, then expression (6) will be rewritten as:

Using the ratios:

We obtain the required expansion coefficients in the form of a column vector with cell values:

The graphical representation of the algorithm (Fig. 3) looks like a butterfly with open wings, which is why this calculation method is called “butterfly”.

Figure 3. Butterfly graph for a series of 4 terms

So, at the first step of the algorithm, the members of a number of signal values ​​are divided into even and odd indices. Then the “butterfly” graph is executed; it consists of two stages, their number is equal to the power of two of the sample size (N = 4 = 22). At each stage, two “butterflies” are performed and their total number remains unchanged. Each butterfly operation corresponds to one multiplication operation. For comparison: in DFT with sampling (f0,f1,f2,f3), the multiplication operation would need to be performed 4×4 = 16 times, and in the case of FFT only 4 times.

This series can also be written as:

(2),
where , k-th complex amplitude.

The relationship between coefficients (1) and (3) is expressed by the following formulas:

Note that all these three representations of the Fourier series are completely equivalent. Sometimes, when working with Fourier series, it is more convenient to use exponents of the imaginary argument instead of sines and cosines, that is, use the Fourier transform in complex form. But it is convenient for us to use formula (1), where the Fourier series is presented as a sum of cosines with the corresponding amplitudes and phases. In any case, it is incorrect to say that the Fourier transform of a real signal will result in complex harmonic amplitudes. As Wiki correctly says, “The Fourier transform (?) is an operation that associates one function of a real variable with another function, also a real variable.”

Total:
The mathematical basis for spectral analysis of signals is the Fourier transform.

The Fourier transform allows you to represent a continuous function f(x) (signal), defined on the segment (0, T) as the sum of an infinite number (infinite series) of trigonometric functions (sine and/or cosine) with certain amplitudes and phases, also considered on the segment (0, T). Such a series is called a Fourier series.

Let us note some more points, the understanding of which is required for the correct application of the Fourier transform to signal analysis. If we consider the Fourier series (the sum of sinusoids) on the entire X-axis, we can see that outside the segment (0, T) the function represented by the Fourier series will periodically repeat our function.

For example, in the graph of Fig. 7, the original function is defined on the segment (-T\2, +T\2), and the Fourier series represents a periodic function defined on the entire x-axis.

This happens because sinusoids themselves are periodic functions, and accordingly their sum will be a periodic function.


Fig.7 Representation of a non-periodic original function by a Fourier series

Thus:

Our original function is continuous, non-periodic, defined on a certain segment of length T.
The spectrum of this function is discrete, that is, it is presented in the form of an infinite series of harmonic components - the Fourier series.
In fact, the Fourier series defines a certain periodic function that coincides with ours on the segment (0, T), but for us this periodicity is not significant.

The periods of the harmonic components are multiples of the value of the segment (0, T) on which the original function f(x) is defined. In other words, the harmonic periods are multiples of the duration of the signal measurement. For example, the period of the first harmonic of the Fourier series is equal to the interval T on which the function f(x) is defined. The period of the second harmonic of the Fourier series is equal to the interval T/2. And so on (see Fig. 8).


Fig.8 Periods (frequencies) of the harmonic components of the Fourier series (here T = 2?)

Accordingly, the frequencies of the harmonic components are multiples of 1/T. That is, the frequencies of the harmonic components Fk are equal to Fk = k\T, where k ranges from 0 to?, for example k = 0 F0 = 0; k=1 F1=1\T; k=2 F2=2\T; k=3 F3=3\T;… Fk= k\T (at zero frequency - constant component).

Let our original function be a signal recorded during T=1 sec. Then the period of the first harmonic will be equal to the duration of our signal T1=T=1 sec and the harmonic frequency will be 1 Hz. The period of the second harmonic will be equal to the signal duration divided by 2 (T2=T/2=0.5 sec) and the frequency will be 2 Hz. For the third harmonic T3=T/3 sec and the frequency is 3 Hz. And so on.

The step between harmonics in this case is 1 Hz.

Thus, a signal with a duration of 1 second can be decomposed into harmonic components (obtaining a spectrum) with a frequency resolution of 1 Hz.
To increase the resolution by 2 times to 0.5 Hz, you need to increase the measurement duration by 2 times - up to 2 seconds. A signal lasting 10 seconds can be decomposed into harmonic components (to obtain a spectrum) with a frequency resolution of 0.1 Hz. There are no other ways to increase frequency resolution.

There is a way to artificially increase the duration of a signal by adding zeros to the array of samples. But it does not increase the actual frequency resolution.

3. Discrete signals and discrete Fourier transform

With the development of digital technology, the methods of storing measurement data (signals) have also changed. If previously a signal could be recorded on a tape recorder and stored on tape in analog form, now signals are digitized and stored in files in computer memory as a set of numbers (samples).

The usual scheme for measuring and digitizing a signal is as follows.


Fig.9 Diagram of the measuring channel

Signal from measuring transducer arrives at the ADC during a period of time T. The signal samples (sampling) obtained during time T are transferred to the computer and stored in memory.


Fig. 10 Digitized signal - N samples received during time T

What are the requirements for signal digitization parameters? A device that converts an input analog signal into a discrete code ( digital signal) is called an analog-to-digital converter (ADC, English Analog-to-digital converter, ADC) (Wiki).

One of the main parameters of the ADC is the maximum sampling frequency (or sampling rate, English sample rate) - the sampling rate of a time-continuous signal when sampling it. It is measured in Hertz. ((Wiki))

According to Kotelnikov’s theorem, if a continuous signal has a spectrum limited by the frequency Fmax, then it can be completely and unambiguously reconstructed from its discrete samples taken at time intervals , i.e. with frequency Fd? 2*Fmax, where Fd is the sampling frequency; Fmax - maximum frequency of the signal spectrum. In other words, the signal digitization frequency (ADC sampling frequency) must be at least 2 times higher than the maximum frequency of the signal that we want to measure.

What will happen if we take samples with a lower frequency than required by Kotelnikov’s theorem?

In this case, the “aliasing” effect occurs (also known as the stroboscopic effect, moiré effect), in which a high-frequency signal, after digitization, turns into a low-frequency signal, which actually does not exist. In Fig. 5 red high frequency sine wave is a real signal. A blue sinusoid of a lower frequency is a fictitious signal that arises due to the fact that during the sampling time more than half a period of the high-frequency signal has time to pass.


Rice. 11. The appearance of a false low-frequency signal at an insufficiently high sampling rate

To avoid the aliasing effect, a special anti-aliasing filter is placed in front of the ADC - a low-pass filter (LPF), which passes frequencies below half the ADC sampling frequency, and cuts off higher frequencies.

In order to calculate the spectrum of a signal from its discrete samples, the discrete Fourier transform (DFT) is used. Let us note once again that the spectrum of a discrete signal “by definition” is limited by the frequency Fmax, which is less than half the sampling frequency Fd. Therefore, the spectrum of a discrete signal can be represented by the sum of a finite number of harmonics, in contrast to the infinite sum for the Fourier series of a continuous signal, the spectrum of which can be unlimited. According to Kotelnikov's theorem, the maximum frequency of a harmonic must be such that it accounts for at least two samples, therefore the number of harmonics is equal to half the number of samples of a discrete signal. That is, if there are N samples in the sample, then the number of harmonics in the spectrum will be equal to N/2.

Let us now consider the discrete Fourier transform (DFT).

Comparing with Fourier series

We see that they coincide, except that time in the DFT is discrete in nature and the number of harmonics is limited by N/2 - half the number of samples.

DFT formulas are written in dimensionless integer variables k, s, where k are the numbers of signal samples, s are the numbers of spectral components.
The value s shows the number of complete harmonic oscillations over period T (duration of signal measurement). The discrete Fourier transform is used to find the amplitudes and phases of harmonics using a numerical method, i.e. "on the computer"

Returning to the results obtained at the beginning. As mentioned above, when expanding a non-periodic function (our signal) into a Fourier series, the resulting Fourier series actually corresponds to a periodic function with period T (Fig. 12).


Fig. 12 Periodic function f(x) with period T0, with measurement period T>T0

As can be seen in Fig. 12, the function f(x) is periodic with period T0. However, due to the fact that the duration of the measurement sample T does not coincide with the period of the function T0, the function obtained as a Fourier series has a discontinuity at point T. As a result, the spectrum of this function will contain a large number of high-frequency harmonics. If the duration of the measurement sample T coincided with the period of the function T0, then the spectrum obtained after the Fourier transform would contain only the first harmonic (sinusoid with a period equal to the sampling duration), since the function f(x) is a sinusoid.

In other words, the DFT program “does not know” that our signal is a “piece of a sinusoid”, but tries to represent a periodic function in the form of a series, which has a discontinuity due to the inconsistency of individual pieces of the sinusoid.

As a result, harmonics appear in the spectrum, which should sum up the shape of the function, including this discontinuity.

Thus, in order to obtain the “correct” spectrum of a signal, which is the sum of several sinusoids with different periods, it is necessary that an integer number of periods of each sinusoid fit into the signal measurement period. In practice, this condition can be met for a sufficiently long duration of signal measurement.


Fig. 13 Example of the function and spectrum of the gearbox kinematic error signal

With a shorter duration, the picture will look “worse”:


Fig. 14 Example of the function and spectrum of a rotor vibration signal

In practice, it can be difficult to understand where are the “real components” and where are the “artifacts” caused by the non-multiple periods of the components and the duration of the signal sampling or “jumps and breaks” in the signal shape. Of course, the words “real components” and “artifacts” are put in quotation marks for a reason. The presence of many harmonics on the spectrum graph does not mean that our signal actually “consists” of them. This is the same as thinking that the number 7 “consists” of the numbers 3 and 4. The number 7 can be represented as the sum of the numbers 3 and 4 - this is correct.

So our signal... or rather not even “our signal”, but a periodic function composed by repeating our signal (sampling) can be represented as a sum of harmonics (sine waves) with certain amplitudes and phases. But in many cases that are important for practice (see the figures above), it is indeed possible to associate the harmonics obtained in the spectrum with real processes that are cyclic in nature and make a significant contribution to the signal shape.

Some results

1. A real measured signal with a duration of T seconds, digitized by an ADC, that is, represented by a set of discrete samples (N pieces), has a discrete non-periodic spectrum, represented by a set of harmonics (N/2 pieces).

2. The signal is represented by a set of real values ​​and its spectrum is represented by a set of real values. Harmonic frequencies are positive. The fact that it is more convenient for mathematicians to represent the spectrum in complex form using negative frequencies does not mean that “this is correct” and “this should always be done.”

3. A signal measured over a time interval T is determined only over a time interval T. What happened before we started measuring the signal, and what will happen after that, is unknown to science. And in our case, it’s not interesting. The DFT of a time-limited signal gives its “true” spectrum, in the sense that, under certain conditions, it allows one to calculate the amplitude and frequency of its components.

Materials used and other useful materials.

A two-line character LCD indicator is used as a display device. The main point in the implementation of this project is not the hardware, but the software, more precisely the implementation of the discrete Fourier transform (DFT) on an 8-bit microcontroller. It should be noted right away that the author is not an expert in this field and therefore started with the basics - with a simple discrete Fourier transform. The fast Fourier transform algorithm is not only fast, but also quite complex.

Discrete Fourier Transform (in English literature DFT, Discrete Fourier Transform) is one of the Fourier transforms widely used in digital signal processing algorithms (its modifications are used in audio compression in MP3, image compression in JPEG, etc.), as well as in others areas related to the analysis of frequencies in a discrete (for example, digitized analog) signal. The discrete Fourier transform requires a discrete function as input. Such functions are often created by sampling (sampling values ​​from continuous functions).

Schematic diagram of a spectrum analyzer sound signal is very simple and can be roughly divided into digital and analog parts.

The digital part is formed by a microcontroller and an LCD indicator connected to it. The microcontroller is clocked from quartz resonator 16 MHz, the supply voltage of +5 V is used as a reference voltage for the ADC of the microcontroller.
The data bus of the LCD indicator is connected to port C of the microcontroller (input/output lines PC0-PC3), the control bus is connected to port D (PD5, PD6) of the microcontroller. The indicator operates in 4-bit mode. A variable resistor with a nominal value of 4.7 kOhm is used to adjust the contrast. To work with the indicator, custom symbols were created to display 8 horizontal columns of the analyzer; these custom symbols occupy all 64 Bytes of RAM of the LCD indicator.

The microcontroller operates from an external 16 MHz quartz resonator.

The analog part of the device is the most important part and is a pre-amplifier of the electret microphone signal, the output of which is connected to the ADC0 channel of the ADC built into the microcontroller. We need to set the zero level at the ADC input to exactly half the reference voltage, i.e. 2.5 V. In this case, we can use the positive and negative half-wave of the signal, but its amplitude should not exceed the established limit, i.e. The gain must be finely tuned to prevent overload. All the above conditions are met by a common low-power operational amplifier microcircuit.

The DFT algorithm is slightly slower compared to the Fast Fourier Transform. But our spectrum analyzer does not require high speed, and if it can provide an update rate of about 30 frames per second, this will be more than enough to visualize the spectrum of an audio signal. In any case, in our version it is possible to achieve a speed of 100 frames per second, but this is already too high a parameter value for a two-line character LCD indicator and is not recommended. The sampling frequency is 20 kHz for a 32 point discrete Fourier transform and since the result of the transform is symmetric, we only need to use the first half, i.e. first 16 results. Therefore, we can display the frequency spectrum up to 10 kHz and the analyzer resolution is 10 kHz/16 = 625 Hz.

The author of the design made attempts to increase the speed of DFT calculations. If this transformation has N points, then we must find N2/2 values ​​of sine and cosine. For our 32 point transformation we need to find 512 sine and cosine values. But, before finding them, we need to calculate the angle (degrees), which will take some CPU time, so it was decided to use value tables for these calculations. When calculating in the microcontroller program, floating point and double precision numbers are not used, as this will take longer to process on an 8-bit microcontroller. Instead, the values ​​in the lookup tables use 16-bit integer data multiplied by 10000. Then, after the conversion is performed, the results are divided by 10000. With this approach, it is possible to perform 120 32-point conversions per second, which is more than enough for our devices.

Demonstration of the operation of a spectrum analyzer on an ATmega32 microcontroller

Downloads

Source code (microcontroller program, sine, cosine and angle data tables) -

  • It is clear that it is difficult to go further than light and music on an AVR, the parameters are not right. But 120 32-point conversions per second may be sufficient for most tasks. And you can, of course, take another sample of 625Hz, or rather lose the refresh rate. It is worth noting that the MK will feel bad; in terms of performance, there is little else you can pin on it. But here you can organize the output of the result using hardware data transfer methods. Then it will be an auxiliary microcontroller, and the main one will only receive data from it and process it compatible with other processes. By and large, it still depends on the frequency of the processor. Once upon a time it was possible to overclock the mega above 20 MHz, but for these tasks we will probably only get glitches at high frequencies. The idea is good, if only more of the math parts would be written... it’s its implementation on MK
  • I’ve also made more interesting analyzers: You Tube or a version on a color LCD: You Tube is based on the famous Chen library :)
  • “we need to calculate the angle (degrees)” Can anyone tell us in more detail how the values ​​for these tables are calculated?
  • Everything is clear with the table of sines and cosines. It’s not clear how the values ​​in the degree_lookup table are calculated?

All signals, whether you made them up or observed them in the Universe, are really just the sum of simple sine waves of different frequencies.

I made a small audio spectrum analyzer (0 - 10 kHz) from a 16x2 LCD and an ATmega32 microcontroller. I started with simple DFTs (Discrete Fourier Transform). FFT (Fast Fourier Transform) differs from DFT only in greater speed and a slightly more complex algorithm, I did not use it, maybe I will add it later.

DFT is slow compared to FFT. My LCD spectrum analyzer does not require the high speed that FFT can provide, and if the image on the screen changes at a rate of about 30 frames/sec, then this is more than enough to visualize the audio spectrum. But I can already achieve around 100 fps, however, too high a refresh rate is not recommended for an LCD. Audio sampled at 20 kHz produces 32 DFT points. Since the transformation result is symmetric, I only need to use the first 16 results. Accordingly, the maximum frequency is 10 kHz. Thus, 10kHz/16 = 625Hz.

I was trying to increase the speed of DFT calculation. If there is a point N DFT, then we need to find the sine and cosine (N^2)/2. For a 32-point DFT, we need to find the sine and cosine of 512. Before finding the sine and cosine, we need to find the angle (degrees) that occupies some CPU time. To do this, I made tables for sine and cosine. I made sine and cosine 16-bit variables by multiplying the sine and cosine values ​​by 10000. After the conversion, I have to divide each result by 10000. Now I can calculate 120 32-point DFTs per second, which is more than enough for a spectrum analyzer.

Display

I used custom LCD characters loaded into the 64 Bytes of onboard LCD memory. I saw a video online where a 16x2 LCD is used as a spectrum analyzer display and used that idea.

Audio input

One of the most important parts of a spectrum analyzer is acquiring the signal from an electret microphone. Particular attention should be paid to the development preamp for microphone. We need to set the zero level at the ADC input and the maximum level equal to half the supply voltage, i.e. 2.5V. It can be supplied with voltage from -2.5V to +2.5V. The preamplifier must be configured so as not to exceed these limits. I used an LM324 op amp as a microphone preamp.

List of radioelements

Designation Type Denomination Quantity NoteShopMy notepad
Display
MK AVR 8-bit

ATmega32

1 To notepad
Capacitor22 pF2 To notepad
Capacitor0.1 µF1 To notepad
Electrolytic capacitor100 µF1 To notepad
Resistor

100 Ohm

1 To notepad
Trimmer resistor4.7 kOhm1 To notepad
Quartz resonator16 MHz1 To notepad
LCD display16x21 To notepad
power unit5 V1 To notepad
Audio input
U1 Operational amplifier

LM324

1 To notepad
C1 Capacitor1 µF1 To notepad
C8 Capacitor0.01 µF1 To notepad
R1 Resistor

220 kOhm

1 To notepad
R2, R3 Resistor

10 kOhm

2 To notepad
R4, R9 Resistor

1 kOhm

2 To notepad
R5 Resistor

There are many specialized processors for digital signal processing (DSP), such as the DSP from Texas Instruments TMS320 series, which includes both simple integer cores and such monsters as the C6000 family subfamily that processes floating point data. There is a whole ADSP series from Analog Devices (which includes the more or less universal BlackFin), there are also more simple solutions from MicroChip - dsPIC.

However, a specialized DSP is good, but is it always so necessary? Yes, with a huge flow of information it is simply irreplaceable, but there are also simpler processing tasks. Specifically, I was interested in the task of double conversion - the audio signal is convolved, thereby obtaining a spectrum, then any operations can be performed on the spectrum and the inverse conversion can be performed, thereby obtaining a processed signal. All this needs to be done in real time and get quality no lower than telephone quality.

This is not the year 2000, there are single-chip solutions based on high-performance ARM7/Cortex-M3 cores that have dropped significantly in price; they are 32-bit, have a hardware implementation of a 32-bit multiplication operation (moreover, almost a DSP multiplication-accumulation operation and 64 bit result), and Cortex-M3 also includes hardware division.

I want to warn you right away that signal processing is not my specialty, almost all the knowledge (or rather, understanding of the principles) was preserved from the institute, but now I just wanted to test and implement it. What I mean is that there may be inaccuracies in the description, substitution of concepts, etc. Actually, academic accuracy didn’t worry me very much.

For almost any DSP, the task outlined above is simple and straightforward. But how will a general purpose RISC core behave on it? If we consider AVR or PIC, then they are unlikely to be enough. 8-bit and low clock frequency have an effect. Although, Elm-Chan has designs in which he conducts an FFT on the AVR and draws the spectrum of the signal. However, in this case, in real time, simply visualization is done (with minimal processing accuracy), and not complete signal processing with acceptable audio quality.

The LPC2146 was chosen as an experimental chip, based on the ARM7TDMI-S core and having a maximum clock frequency of 60 MHz (in practice, it does not operate at 72 or even 84 MHz). Why? Firstly, I have a debug board for it, and secondly, there is an ADC and DAC on board, i.e. minimal external trim required.

A little theory

First of all, it was interesting to evaluate the performance of FFT (Fast Fourier Transform) on ARM microcontrollers. Based on this assessment, we can conclude whether it has enough speed to process a stream of audio data, and the signal with what sampling frequency and how many channels can be processed on such a microcontroller.

Based on the Fourier transform, you can build clever filters (with very attractive characteristics). I was primarily interested in the problems of changing the tone of the signal (raising and lowering the spectrum) and “reflecting” the spectrum. The latter is required in SDR radios to listen to LSB lower sideband radio broadcasts.

I will not load you with theory and explain what the Fourier Transform is; there are quite a lot of materials on this topic, from what I used: a wiki and a chapter from a very good and informative book.

Software implementation

There are a lot of software implementations of FFT, however, I wrote my own. The main goal I pursued was optimizing the code for a specific architecture. Firstly, I immediately focused on 32-bit, secondly, only integer calculations were required and it was desirable to avoid the division operation. Finding something ready-made to meet these requirements is already problematic.

All constants that could be calculated in advance were calculated and placed in tables (mostly the values ​​of trigonometric functions). This is the main optimization of the algorithm, otherwise it almost completely repeats the described algorithm.

The most important is the requirement for integer calculations. During the implementation process, there was even an error that caused an overflow in one of the 32-bit loop variables. Moreover, it did not appear on all test data, so it caused quite a headache until it was found.

I collected all the source texts in one archive. The implementation is not final, there are duplicate calculations (spectrum and phase symmetry are not taken into account), and optimization of the use of buffers is required, since too many are currently used for calculations random access memory(almost 12k for a 1024 point conversion).

First tests

Drum roll: I’m testing the conversion speed for a sample of 1024 points, the processor core frequency is 60 MHz. Testing was carried out in an emulator, so it does not claim to be 100% accurate, but this result can be used as an indicator (in my previous experience, although the emulator lied, it wasn’t much). Test of the first version of the code, RealView MDK compiler, O3 optimization option, ARM code generation mode.

So what we see:

6ms for each conversion, for a total of just over 12ms for the round-trip conversion. It turns out that with a sampling frequency of 44100Hz (standard for audio) and samples with a resolution of up to 16 bits, pure calculations will take ~44*12ms = 528ms. And this is on an intermediate version of the firmware, when some code optimizations have not yet been completed (according to estimates, the algorithm can be accelerated by almost 2 times)! In my opinion, it’s just an excellent indicator.

In total, the core load is expected to be around 50%, another 50% remains for conversions over the spectrum and overhead costs when working with ADCs, DACs and other data transfers. If you lower the sampling frequency to the “telephone” level (about 4800-9600Hz), then the core load will be even lower (about 15-30%).

So, the mathematical part is more or less clear. You can proceed to concrete implementation.

Iron

For the test platform, we used a Keil MCB2140 development board with a speaker. A Mini-Jack cord is soldered to connect to the linear output of the device and a simple input chain is assembled. As already mentioned, the board already has a speaker connected to the analog output of the microcontroller and there are controls (button and potentiometer).

Here is a sketch of the input circuit:


Debugging of the software occurred in stages:

  1. Debugging of all necessary peripherals: ADC, DAC, timers, LED indication.
  2. Test with signal digitization: I digitize the data at the required speed and put it in a buffer, then I extract the data from the buffer and play the signal. Those. simple signal shift in time, without any transformations. At this stage, the mechanism for working with 2 buffers, necessary for further work, is tested.
  3. TO previous version direct and inverse Fourier transforms are added. This test finally verifies the correct operation of the FFT code, as well as checking that the code fits within the available performance.
  4. After this, the main skeleton of the application is done, you can move on to practical applications.

The problem arose after adding FFT to the code: extraneous noise and whistles appeared in the signal. In general, this behavior seemed quite strange to me, because... Without conversion, the signal passing through the digital path remained quite clean. The first reason for this: after the analog circuit, the signal amplitude on the ADC was not full (0-3.3V), but only within 0.5-2V at the maximum volume of the player, the second: quite strong noise due to integer calculations (+-1 unit, which turned out to be sufficient to cause audible interference).

To combat the first problem, it was decided to start adjusting the analog part. And to solve the problem with noise, try using a lowpass filter.

Application 1: changing the tone of the signal

The board has a potentiometer ( variable resistor), it can be used for control. In this case, it sets the signal spectrum to shift up and down, quite enough to “transform” your favorite compositions.

Here's what happens in the frequency domain:


In this case, the conversion result is contained in 2 buffers. One buffer is the real part, and the other is the imaginary part. The physical meaning of the numbers obtained in them: the real part contains the values ​​of the harmonics, the imaginary part contains the phase shift for these harmonics. Moreover, as you can see, the initial signal is described by N-values, and after conversion, 2N-values ​​are obtained. The amount of information does not change, and the 2-fold increase in the amount of information occurs due to the fact that the buffer data has redundancy in the form of duplication of values.




Top