Audio frequency measurement method and device, medium and equipment
By selecting sample sets of different starting positions in the audio frequency measurement for FFT, and selecting the phase difference frequency estimation calculation method according to the phase angle, the contradiction between high precision and real-time in the prior art is solved, and frequency estimation with high precision and low calculation amount is achieved.
Patent Information
- Application Number
- CN202411770754.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-03-07
AI Technical Summary
When the existing audio frequency measurement methods improve measurement accuracy, they need to increase the number of sampling points, resulting in increased computing costs and reduced system real-time performance, making it difficult to find a balance between high accuracy and real-time performance.
By selecting the first and second sample sets with different starting positions but the same number of samples, Fast Fourier transform (FFT) is performed separately, the phase angle at the maximum spectrum amplitude is calculated, and different FFT phase difference frequency estimation calculation methods are selected based on the phase angle comparison results, and the audio frequency is calculated.
Without increasing the number of sampling points, the accuracy and anti-interference of audio frequency measurement are significantly improved, the calculation cost is reduced, and the frequency estimation with high accuracy and low calculation amount is achieved.
Smart Images

Figure CN119580774A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of audio frequency measurement, and in particular to an audio frequency measurement method, device, medium and equipment. Background Art
[0002] Audio is an important carrier in multimedia, containing a large amount of information, which effectively enriches people's perception and acquisition of sound information. Sound is recorded or reproduced by analog equipment to become analog audio, and then digitized to become digital audio. Audio analysis is the process of extracting a series of characteristics of the signal in the time domain and frequency domain by taking digital audio signals as the analysis object and digital signal processing as the analysis method. Audio analysis in various specific frequency ranges has different application fields. For example: the analysis of speech signals from 300Hz to 4kHz is mainly used in speech recognition, and its purpose is to determine the content of the speech or judge the identity of the speaker; the analysis of audio signals in the full range of 20Hz to 20kHz can be used to measure the performance of various audio devices. In the field of audio, frequency measurement has always been a challenging problem because it involves a balance between measurement accuracy and frequency estimation accuracy and computational cost. Therefore, audio frequency measurement has always been one of the focuses of the detection industry.
[0003] In the process of audio analysis, pulse counting method, zero-crossing method and fast Fourier transform (FFT) are several commonly used audio frequency measurement algorithms. However, the traditional pulse counting method and zero-crossing method are easily affected by noise, especially when measuring the frequency of dual-tone, multi-tone or intermodulation signals, the accuracy is not high and the error is large. For the traditional method of using fast Fourier transform for audio analysis, the magnitude of the frequency error depends largely on whether the actual frequency value just matches the corresponding frequency channel of the N-point fast Fourier transform. If the actual frequency falls between two adjacent frequency channels, the corresponding error will increase significantly, and this error amount cannot be controlled. In addition, the number of FFT points will also affect the magnitude of the frequency error. If the number of FFT points is small, the directly calculated frequency error will increase further and cannot meet the demand for accurate frequency measurement. When measuring frequency, if the traditional FFT algorithm wants to improve the accuracy, it must increase the number of sampling points. However, as the number of sampling points increases, the computational cost will also increase accordingly, thereby reducing the real-time performance of the system. The contradiction between high accuracy and real-time performance has always been a difficult problem in frequency estimation applications. Summary of the invention
[0004] In view of this, the present application provides an audio frequency measurement method, device, medium and equipment, the main purpose of which is to resolve the contradiction between increasing the number of sampling points and improving measurement accuracy in the current solution, and to achieve accurate measurement without increasing the sampling points.
[0005] According to one aspect of the present application, there is provided an audio frequency measurement method, comprising:
[0006] Acquire and sample audio data to obtain a sampling sequence of N samples;
[0007] In the sampling sequence, a first sample set and a second sample set with different starting positions but the same number of samples are selected;
[0008] Performing fast Fourier transform (FFT) on the first sample set and the second sample set respectively to obtain a first spectrum sequence representation and a second spectrum sequence representation, and respectively calculating the phase angles of the first spectrum sequence representation and the second spectrum sequence representation at the maximum spectrum amplitude to obtain a first phase angle and a second phase angle;
[0009] The first phase angle and the second phase angle are compared, and different FFT phase difference frequency estimation algorithms are selected according to the phase angle comparison result to calculate the audio frequency.
[0010] In one implementation, selecting, in the sampling sequence, a first sample set and a second sample set having different starting positions but the same number of samples includes:
[0011] In a sampling sequence of N samples, K samples are selected from the i-th sample as a first sample set, and K samples are selected from the j-th sample as a second sample set, wherein i is different from j, and K is less than N.
[0012] In one implementation, selecting K samples from the i-th sample as the first sample set and selecting K samples from the j-th sample as the second sample set includes:
[0013] First, K samples are selected from the i-th sample as the first sample set, and then at least one sliding window shift operation is performed on the i-th sample to determine the shift to the j-th sample, and K samples are selected from the j-th sample as the second sample set.
[0014] In one implementation,
[0015] After obtaining the first spectrum sequence representation and the second spectrum sequence representation, the method further includes: determining an index value m corresponding to a spectrum amplitude maximum value according to the first spectrum sequence representation and the second spectrum sequence representation;
[0016] The step of respectively calculating the phase angles of the first spectrum sequence representation and the second spectrum sequence at the point where the spectrum amplitude is maximum to obtain the first phase angle and the second phase angle comprises: respectively calculating the phase angles of the first spectrum sequence representation and the second spectrum sequence representation at m to obtain the first phase angle and the second phase angle.
[0017] In one implementation, comparing the first phase angle and the second phase angle, selecting different FFT phase difference frequency estimation algorithms according to the phase angle comparison result, and calculating the audio frequency includes:
[0018] If the second phase angle is ahead of the first phase angle, the audio frequency is calculated based on the absolute value of the difference between the two phase angles based on the first FFT phase difference frequency estimation algorithm. If the second phase angle lags behind the first phase angle, the audio frequency is calculated based on the absolute value of the sum of the two phase angle differences and π based on the second FFT phase difference frequency estimation algorithm.
[0019] In one implementation,
[0020] The first phase difference frequency estimation algorithm is:
[0021]
[0022] The second phase difference frequency estimation algorithm is:
[0023]
[0024] Where y0(m) is the first spectrum sequence representation, y1(m) is the second spectrum sequence representation, angle(y0(m)) is the first phase angle, angle(y1(m)) is the second phase angle, and f s is the sampling rate, and m is the index value corresponding to the maximum spectrum amplitude.
[0025] According to one aspect of the present application, there is provided an audio frequency measurement device, comprising:
[0026] A sampling unit, used for acquiring and sampling audio data to obtain a sampling sequence of N samples;
[0027] A sample set division unit, used for selecting a first sample set and a second sample set with different starting positions but the same number of samples in the sampling sequence;
[0028] An FFT calculation unit performs a fast Fourier transform FFT on the first sample set and the second sample set respectively to obtain a first spectrum sequence representation and a second spectrum sequence representation, and calculates the phase angles of the first spectrum sequence representation and the second spectrum sequence representation at the maximum spectrum amplitude to obtain a first phase angle and a second phase angle;
[0029] The phase difference frequency estimation unit is used to compare the first phase angle and the second phase angle, select different FFT phase difference frequency estimation algorithms according to the phase angle comparison result, and calculate the audio frequency.
[0030] In one implementation,
[0031] The sample set division unit is specifically used to select K samples from the i-th sample as the first sample set and select K samples from the j-th sample as the second sample set in a sampling sequence of N samples, wherein i is different from j and K is less than N.
[0032] In one implementation,
[0033] The sample set division unit is specifically used to first select K samples from the i-th sample as the first sample set, then perform at least one sliding window shift operation on the i-th sample to determine the shift to the j-th sample, and select K samples from the j-th sample as the second sample set.
[0034] In one implementation,
[0035] The FFT calculation unit is also used to determine the index value m corresponding to the maximum spectrum amplitude according to the first spectrum sequence representation and the second spectrum sequence representation; and calculate the phase angles of the first spectrum sequence representation and the second spectrum sequence representation at m respectively to obtain the first phase angle and the second phase angle.
[0036] In one implementation,
[0037] The phase difference frequency estimation unit is specifically used to calculate the audio frequency based on the absolute value of the difference between the two phase angles based on the first FFT phase difference frequency estimation algorithm if the second phase angle leads the first phase angle; and to calculate the audio frequency based on the absolute value of the sum of the difference between the two phase angles and π based on the second FFT phase difference frequency estimation algorithm if the second phase angle lags behind the first phase angle.
[0038] In one implementation,
[0039] The first phase difference frequency estimation algorithm is:
[0040]
[0041] The second phase difference frequency estimation algorithm is:
[0042]
[0043] Where y0(m) is the first spectrum sequence representation, y1(m) is the second spectrum sequence representation, angle(y0(m)) is the first phase angle, angle(y1(m)) is the second phase angle, and f s is the sampling rate, and m is the index value corresponding to the maximum spectrum amplitude.
[0044] According to one aspect of the present application, a storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned audio frequency measurement method when running.
[0045] According to one aspect of the present application, an electronic device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the above-mentioned audio frequency measurement method.
[0046] By means of the above technical scheme, the present application provides an audio frequency measurement method, device, medium and equipment, which first selects a first sample set and a second sample set with different starting positions but the same number of samples; then performs FFT on the two sample sets, and respectively calculates the phase angle at the maximum spectrum amplitude, and finally selects different FFT phase difference frequency estimation algorithms according to the phase information comparison result to calculate the audio frequency. The embodiment of the present application utilizes the phase difference information of the signal to eliminate the limitation of the search interval, which not only improves the accuracy of the audio frequency measurement, but also has a low computational cost, does not require an additional number of sampling points, and is a frequency estimation scheme that ensures high accuracy and meets the requirements of low computational complexity.
[0047] Compared with traditional frequency measurement methods, this application has obvious technical advantages. Traditional hardware pulse counting method and zero-crossing method are easily interfered by noise when measuring audio frequency, especially when measuring dual-tone, multi-tone or intermodulation signal frequency, the error is large, and the frequency measurement estimation method of this scheme significantly improves the anti-interference and accuracy. Compared with the traditional FFT, the frequency measurement estimation method based on the phase difference of FFT in this scheme takes into account the problem of leading and lagging phases of different spectrum sequences, and uses different calculation formulas to calculate the frequency. It can reach or approach the accuracy and resolution of hardware pulse counting measurement without increasing the number of sampling points, and has the advantage of fast measurement.
[0048] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0050] Figure 1 A flow chart of an audio frequency measurement method provided by an embodiment of the present application is shown;
[0051] Figure 2 A flowchart showing an example of an audio frequency measurement method provided by an embodiment of the present application is shown;
[0052] Figure 3 A schematic structural diagram of an audio frequency measurement device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0053] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only embodiments of a part of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work should fall within the scope of protection of the present application. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.
[0054] In order to solve the problems existing in the existing audio frequency measurement, the embodiment of the present application proposes a high-precision audio frequency measurement estimation method based on FFT phase difference. This method can not only ensure high precision, but also has a low amount of calculation. By determining the signal frequency by using the peak position of the fast Fourier transform amplitude spectrum after signal sampling and calculating the phase difference at the peak position of the amplitude spectrum, fast and high-precision frequency measurement can be achieved. This FFT phase difference estimation method provides a new idea, which can take into account the real-time performance of the system while ensuring accuracy. Through this method, frequency estimation can be performed more effectively, bringing more possibilities to the field of audio processing.
[0055] See also Figure 1 , is a flow chart of an audio frequency measurement method provided in an embodiment of the present application, comprising the following steps S101-S104.
[0056] S101: Acquire and sample audio data to obtain a sampling sequence of N samples.
[0057] S102: In a sampling sequence, a first sample set and a second sample set with different starting positions but the same number of samples are selected.
[0058] In order to calculate the audio frequency based on the FFT phase difference, two sample sets need to be selected and calculated respectively. Specifically, two different sample sets can be selected from the sampling sequence of N samples: a first sample set and a second sample set. The two sample sets can partially overlap, for example, the starting positions are different, but in order to calculate the phase difference later, the number of samples of the two sets must be the same, for example, both include K samples.
[0059] In one implementation, in a sampling sequence of N samples, K samples may be selected starting from the i-th sample as a first sample set, and K samples may be selected starting from the j-th sample as a second sample set, where i is different from j and K is less than N.
[0060] For example, first, K samples are selected from the i-th sample as the first sample set, then at least one sliding window shift operation is performed on the i-th sample to determine the shift to the j-th sample, and K samples are selected from the j-th sample as the second sample set.
[0061] Take N=1024 as an example, that is, a sampling sequence of 1024 samples is obtained by sampling, assuming i=0, K=1000, then select samples from 0-999, and then perform a one-bit sliding window shift operation from i backward, that is, j=1, select 1-1000. It should be noted that the more overlapping samples of the two sample sets, that is, the fewer bits of the sliding window shift operation, the higher the subsequent phase difference calculation accuracy, so in a preferred manner, j is i shifted backward by one bit, that is, j is 1 greater than i.
[0062] S103: Perform fast Fourier transform (FFT) on the first sample set and the second sample set respectively to obtain a first spectrum sequence representation and a second spectrum sequence representation, and calculate the phase angles of the first spectrum sequence representation and the second spectrum sequence representation at the maximum spectrum amplitude respectively to obtain a first phase angle and a second phase angle.
[0063] After obtaining the first spectrum sequence representation and the second spectrum sequence representation, the maximum spectrum amplitude can be easily determined based on the first spectrum sequence representation and the second spectrum sequence representation, thereby determining the index value m corresponding to the maximum spectrum amplitude; when calculating the phase angle, the phase angles of the first spectrum sequence representation and the second spectrum sequence at the index value m corresponding to the maximum spectrum amplitude are calculated respectively to obtain the first phase angle and the second phase angle.
[0064] S104: Compare the first phase angle and the second phase angle, select different phase difference frequency estimation algorithms according to the phase angle comparison result, and calculate the audio frequency.
[0065] Those skilled in the art understand that the traditional FFT method of measuring frequency is to find the position of the peak in the spectrum to calculate the required audio frequency. However, after analysis, the inventors of the present application found that due to the existence of the fence effect, when the peak of the signal spectrum cannot completely coincide with the center of the main lobe, the true frequency often falls between the two spectral lines in the main lobe, which leads to a large frequency measurement error.
[0066] Therefore, the frequency measurement method based on FFT phase difference estimation in the embodiment of the present application uses signal phase information to solve this problem. Unlike the traditional method that only uses amplitude information, the embodiment of the present application uses the phase information of the signal to eliminate the limitation of the search interval as much as possible. This can not only improve the accuracy of audio frequency measurement, but also has a low computational cost and does not require additional sampling points. It is a frequency estimation algorithm that ensures high accuracy and meets the requirements of low computational complexity.
[0067] Specifically, if the second phase angle is ahead of the first phase angle, the audio frequency is calculated based on the absolute value of the difference between the two phase angles based on the first FFT phase difference frequency estimation algorithm; if the second phase angle lags behind the first phase angle, the audio frequency is calculated based on the absolute value of the sum of the two phase angle differences and π based on the second FFT phase difference frequency estimation algorithm.
[0068] For example, the first phase difference frequency estimation algorithm is:
[0069]
[0070] The second phase difference frequency estimation algorithm is:
[0071]
[0072] Where y0(m) is the first spectrum sequence representation, y1(m) is the second spectrum sequence representation, angle(y0(m)) is the first phase angle, angle(y1(m)) is the second phase angle, and f s is the sampling rate, and m is the index value corresponding to the maximum spectrum amplitude.
[0073] Therefore, an audio frequency measurement method provided by an embodiment of the present application first selects a first sample set and a second sample set with different starting positions but the same number of samples; then performs FFT on the two sample sets, and respectively calculates the phase angle at the maximum spectrum amplitude, and finally selects different FFT phase difference frequency estimation algorithms according to the phase information comparison result to calculate the audio frequency. The embodiment of the present application utilizes the phase difference information of the signal to eliminate the limitation of the search interval, which not only improves the accuracy of the audio frequency measurement, but also has a low computational cost and does not require an additional number of sampling points. It is a frequency estimation scheme that ensures high accuracy and meets the requirements of low computational complexity.
[0074] Compared with traditional frequency measurement methods, this application has obvious technical advantages. Traditional hardware pulse counting method and zero-crossing method are easily interfered by noise when measuring audio frequency, especially when measuring dual-tone, multi-tone or intermodulation signal frequency, the error is large, and the frequency measurement estimation method of this scheme significantly improves the anti-interference and accuracy. Compared with the traditional FFT, the frequency measurement estimation method based on the phase difference of FFT in this scheme takes into account the problem of leading and lagging phases of different spectrum sequences, and uses different calculation formulas to calculate the frequency. It can reach or approach the accuracy and resolution of hardware pulse counting measurement without increasing the number of sampling points, and has the advantage of fast measurement.
[0075] The following is an illustrative introduction to the embodiments of the present application through specific principle analysis and formulas.
[0076] Those skilled in the art understand that, without considering noise pollution, based on the audio signal model, an ideal sinusoidal single tone signal is expressed as:
[0077]
[0078] In the formula, A is the amplitude of the signal, f is the frequency of the signal, unit Hz, and θ0 is the initial phase of the signal, unit rad. After N samplings, the discrete representation of this signal is obtained:
[0079]
[0080] In the traditional FFT audio analysis algorithm, an N-point fast Fourier transform (FFT) is performed on x(n) to obtain:
[0081]
[0082] By using fast Fourier transform, the peak position can be easily found in the spectrum, thereby calculating the required audio frequency. Assuming that the discrete frequency index corresponding to the maximum amplitude is m, the estimated value of the signal frequency can be obtained based on the position m of the maximum amplitude of X[k]:
[0083]
[0084] Among them, f s is the sampling rate. Due to the existence of the fence effect, when the signal spectrum peak cannot completely coincide with the center of the main lobe, the true frequency often falls between the two spectral lines in the main lobe, which leads to a large frequency measurement error.
[0085] Therefore, the frequency measurement method based on FFT phase difference proposed in the embodiment of the present application uses signal phase information to solve this problem. Unlike the traditional method that only uses amplitude information, the phase information of the signal is used to eliminate the limitation of the search interval, which can not only improve the accuracy of audio frequency measurement, but also has a lower calculation cost. It is a frequency estimation algorithm that ensures high accuracy and meets the requirements of low calculation amount.
[0086] The following introduces an audio frequency estimation algorithm based on FFT phase difference provided in an embodiment of the present application.
[0087] First, sample N-1 signals x(n), n=0, 1, 2, ..., N-2, and use fast Fourier transform (i.e. K=N-1, i=0). The spectrum sequence y0(k) is:
[0088]
[0089] Then, after a one-bit sliding window shift, the next N-1 signal samples x(n) are obtained, where n=1, 2, 3, ..., N-1, and a fast Fourier transform (i.e., K=N-1, j=1) is applied to them to obtain the spectrum sequence y1(k):
[0090]
[0091] Since the spectrum sequences y0(k) and y1(k) are obtained by performing FFT operations on sampled signals with the same frequency, the peak positions of the amplitude spectra of y0(k) and y1(k) are the same. According to the peak positions of the spectrum sequences y0(k) and y1(k), the phase angles of y0(k) and y1(k) at m are angle(y0(m)) and angle(y1(m)), respectively.
[0092] Then the first FFT phase difference method high-precision frequency estimation is:
[0093]
[0094] From (7), we can see that the phase difference between the spectrum sequences y0(m) and y1(m) is used for frequency estimation. The frequency estimation result of this method is not limited by the quantization error of the frequency search interval, thus achieving high-precision frequency estimation.
[0095] It is worth noting that the frequency calculation formula of formula (7) is close to the true value only when angle(y1(m)) is ahead of angle(y0(m)). In the actual application of audio analysis, angle(y1(m)) will not always be ahead of angle(y0(m)). Therefore, when angle(y1(m)) lags behind angle(y0(m)), the second FFT phase difference method can estimate the frequency with high precision as follows:
[0096]
[0097] In summary, in actual audio applications, the FFT phase difference method can be used to estimate the frequency with high precision:
[0098]
[0099] The phase angle problem that needs to be paid attention to when estimating audio frequency using the FFT phase difference estimation method has been pointed out above. The entire algorithm flow is given below to better understand and apply this frequency estimation method.
[0100] See also Figure 2 , shows a flowchart of an example of an audio frequency measurement method provided in an embodiment of the present application.
[0101] S201: Perform FFT on the first N-1 samples of the sampling sequence to obtain y0(k); perform FFT on the last N-1 samples of the sampling sequence to obtain y1(k);
[0102] S202: Obtain the index value m corresponding to the maximum spectrum amplitude according to y0(k) and y1(k), and calculate the phase angles angle(y0(m)) and angle(y1(m)) of y0(k) and y1(k) at m respectively;
[0103] S203: Compare the sizes of angle(y0(m)) and angle(y1(m));
[0104] S204: If angle(y0(m)) is ahead of angle(y1(m)), use formula (8) to obtain the high-precision frequency estimation of the FFT phase difference;
[0105] S205: If angle(y0(m)) lags behind angle(y1(m)), use formula (7) to obtain the FFT phase difference to estimate the frequency with high precision.
[0106] Table 1-2 shows the audio chip ES8988 used in the actual application of the embodiment of the present application. The sampling rate is set to 96kHz to collect audio signals. The audio frequency is measured using the method of the embodiment of the present application and compared with other traditional methods to obtain the performance comparison of various audio frequency estimation methods.
[0107] Table 1 Frequency measurement values
[0108]
[0109] Table 2 Frequency error values
[0110]
[0111] It can be seen from Table 1 and Table 2 that the zero-crossing method is completely distorted when measuring audio signals greater than 15kHz. The accuracy of the traditional FFT algorithm is proportional to the number of sampling points N. The larger the number of sampling points, the closer the frequency measurement of the traditional FFT algorithm is to the true value, and the smaller the error. If the number of sampling points N is increased, the calculation time will be greatly reduced. The audio frequency estimation method based on FFT phase difference in the embodiment of the present application is used, and the error with the true value is minimized when the number of sampling points is the same.
[0112] It can be seen that in the embodiment of the present application, the FFT-based phase difference estimation algorithm has the advantages of fast speed and high precision. At the same time, the algorithm is executed in a pipelined manner without any recursive or iterative process, so it is conducive to hardware implementation; and the algorithm also has the characteristics of unbiased estimation, and the measurement accuracy can be further improved by taking the average value through multiple measurements to approach the true value. It can be seen that the application of this algorithm for audio frequency measurement can show good engineering application prospects, especially suitable for audio frequency estimation.
[0113] Corresponding to the above method, the embodiment of the present application further provides an audio frequency measurement device, including:
[0114] The sampling unit 301 is used to acquire and sample audio data to obtain a sampling sequence of N samples;
[0115] A sample set division unit 302 is used to select a first sample set and a second sample set with different starting positions but the same number of samples in the sampling sequence;
[0116] The FFT calculation unit 303 performs FFT on the first sample set and the second sample set respectively to obtain a first spectrum sequence representation and a second spectrum sequence representation, and calculates the phase angles of the first spectrum sequence representation and the second spectrum sequence representation at the maximum spectrum amplitude to obtain a first phase angle and a second phase angle;
[0117] The phase difference frequency estimation unit 304 is used to compare the first phase angle and the second phase angle, select different FFT phase difference frequency estimation algorithms according to the phase angle comparison result, and calculate the audio frequency.
[0118] In one implementation,
[0119] The sample set division unit 302 is specifically configured to select K samples from the i-th sample as the first sample set and select K samples from the j-th sample as the second sample set in a sampling sequence of N samples, wherein i is different from j and K is less than N.
[0120] In one implementation,
[0121] The sample set division unit 302 is specifically used to first select K samples from the i-th sample as the first sample set, then perform at least one sliding window shift operation on the i-th sample to determine the shift to the j-th sample, and select K samples from the j-th sample as the second sample set.
[0122] In one implementation,
[0123] The FFT calculation unit 303 is also used to determine the index value m corresponding to the maximum spectrum amplitude according to the first spectrum sequence representation and the second spectrum sequence representation; and calculate the phase angles of the first spectrum sequence representation and the second spectrum sequence representation at m respectively to obtain the first phase angle and the second phase angle.
[0124] In one implementation,
[0125] The phase difference frequency estimation unit 304 is specifically used to calculate the audio frequency based on the absolute value of the difference between the two phase angles based on the first FFT phase difference frequency estimation algorithm if the second phase angle leads the first phase angle by less than π; if the second phase angle lags behind the first phase angle, calculate the audio frequency based on the absolute value of the sum of the difference between the two phase angles and π based on the second FFT phase difference frequency estimation algorithm.
[0126] In one implementation,
[0127] The first phase difference frequency estimation algorithm is:
[0128]
[0129] The second phase difference frequency estimation algorithm is:
[0130]
[0131] Where y0(m) is the first spectrum sequence representation, y1(m) is the second spectrum sequence representation, angle(y0(m)) is the first phase angle, angle(y1(m)) is the second phase angle, and f s is the sampling rate, and m is the index value corresponding to the maximum spectrum amplitude.
[0132] An embodiment of the present application further provides a storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0133] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:
[0134] Acquire and sample audio data to obtain a sampling sequence of N samples;
[0135] In the sampling sequence, a first sample set and a second sample set with different starting positions but the same number of samples are selected;
[0136] Performing fast Fourier transform (FFT) on the first sample set and the second sample set respectively to obtain a first spectrum sequence representation and a second spectrum sequence representation, and respectively calculating the phase angles of the first spectrum sequence representation and the second spectrum sequence representation at the maximum spectrum amplitude to obtain a first phase angle and a second phase angle;
[0137] The first phase angle and the second phase angle are compared, and different FFT phase difference frequency estimation algorithms are selected according to the phase angle comparison result to calculate the audio frequency.
[0138] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.
[0139] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0140] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0141] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0142] Acquire and sample audio data to obtain a sampling sequence of N samples;
[0143] In the sampling sequence, a first sample set and a second sample set with different starting positions but the same number of samples are selected;
[0144] Performing fast Fourier transform (FFT) on the first sample set and the second sample set respectively to obtain a first spectrum sequence representation and a second spectrum sequence representation, and respectively calculating the phase angles of the first spectrum sequence representation and the second spectrum sequence representation at the maximum spectrum amplitude to obtain a first phase angle and a second phase angle;
[0145] The first phase angle and the second phase angle are compared, and different FFT phase difference frequency estimation algorithms are selected according to the phase angle comparison result to calculate the audio frequency.
[0146] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0147] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0148] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0149] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0150] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0151] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0152] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0153] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for measuring audio frequency, characterized in that: include: Acquire and sample audio data to obtain a sampling sequence of N samples; In the sampling sequence, a first sample set and a second sample set with different starting positions but the same number of samples are selected; Performing fast Fourier transform (FFT) on the first sample set and the second sample set respectively to obtain a first spectrum sequence representation and a second spectrum sequence representation, and respectively calculating the phase angles of the first spectrum sequence representation and the second spectrum sequence representation at the maximum spectrum amplitude to obtain a first phase angle and a second phase angle; The first phase angle and the second phase angle are compared, and different FFT phase difference frequency estimation algorithms are selected according to the phase angle comparison result to calculate the audio frequency.
2. The method according to claim 1, characterized in that The selecting, in the sampling sequence, a first sample set and a second sample set with different starting positions but the same number of samples comprises: In a sampling sequence of N samples, K samples are selected from the i-th sample as a first sample set, and K samples are selected from the j-th sample as a second sample set, wherein i is different from j, and K is less than N.
3. The method according to claim 2, characterized in that The step of selecting K samples from the i-th sample as the first sample set and selecting K samples from the j-th sample as the second sample set includes: First, K samples are selected from the i-th sample as the first sample set, and then at least one sliding window shift operation is performed on the i-th sample to determine the shift to the j-th sample, and K samples are selected from the j-th sample as the second sample set.
4. The method according to claim 1, characterized in that After obtaining the first spectrum sequence representation and the second spectrum sequence representation, the method further includes: determining an index value m corresponding to a spectrum amplitude maximum value according to the first spectrum sequence representation and the second spectrum sequence representation; The step of respectively calculating the phase angles of the first spectrum sequence representation and the second spectrum sequence at the point where the spectrum amplitude is maximum to obtain the first phase angle and the second phase angle comprises: respectively calculating the phase angles of the first spectrum sequence representation and the second spectrum sequence representation at m to obtain the first phase angle and the second phase angle.
5. The method according to any one of claims 1 to 4, characterized in that: The method of comparing the first phase angle and the second phase angle, selecting different FFT phase difference frequency estimation algorithms according to the phase angle comparison result, and calculating the audio frequency includes: If the second phase angle is ahead of the first phase angle, the audio frequency is calculated based on the absolute value of the difference between the two phase angles based on the first FFT phase difference frequency estimation algorithm. If the second phase angle lags behind the first phase angle, the audio frequency is calculated based on the absolute value of the sum of the two phase angle differences and π based on the second FFT phase difference frequency estimation algorithm.
6. The method according to claim 5, characterized in that The first phase difference frequency estimation algorithm is: The second phase difference frequency estimation algorithm is: Where y0(m) is the first spectrum sequence representation, y1(m) is the second spectrum sequence representation, angle(y0(m)) is the first phase angle, angle(y1(m)) is the second phase angle, and f s is the sampling rate, and m is the index value corresponding to the maximum spectrum amplitude.
7. An audio frequency measuring device, characterized in that: include: A sampling unit, used for acquiring and sampling audio data to obtain a sampling sequence of N samples; A sample set division unit, used for selecting a first sample set and a second sample set with different starting positions but the same number of samples in the sampling sequence; An FFT calculation unit performs a fast Fourier transform FFT on the first sample set and the second sample set respectively to obtain a first spectrum sequence representation and a second spectrum sequence representation, and calculates the phase angles of the first spectrum sequence representation and the second spectrum sequence representation at the maximum spectrum amplitude to obtain a first phase angle and a second phase angle; The phase difference frequency estimation unit is used to compare the first phase angle and the second phase angle, select different FFT phase difference frequency estimation algorithms according to the phase angle comparison result, and calculate the audio frequency.
8. The device according to claim 7, characterized in that The sample set division unit is specifically used to select K samples from the i-th sample as the first sample set and select K samples from the j-th sample as the second sample set in a sampling sequence of N samples, wherein i is different from j and K is less than N.
9. A storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 6 when executed.
10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 6.