Disclosure of Invention
The embodiment of the application provides a digital signal filtering method, a device, equipment and a storage medium, which solve the problems that waveforms obtained by adopting an FIR filter or an IIR filter in the related technology are easy to generate distortion, and are only applicable to signal filtering in a special frequency spectrum range, the filtering granularity is rough, and the filtering effect is relatively poor.
In a first aspect, an embodiment of the present application provides a digital signal filtering method, including:
acquiring a discrete data sequence corresponding to a signal to be processed and acquiring a period time corresponding to a target suppression frequency point;
Calculating to obtain sampling time based on the first length of the discrete data sequence and the sampling rate corresponding to the set analog-to-digital converter, and dividing the sampling time by the period time to obtain a reference quantity value;
under the condition that the reference quantity value is an integer, performing fast Fourier transform on the discrete data sequence to obtain a target frequency spectrum, and updating the frequency spectrum values corresponding to the target suppression frequency points and the associated image frequency points in the target frequency spectrum to a first target frequency spectrum value corresponding to the nearest neighboring frequency point positioned on the right side of the target suppression frequency point;
and carrying out inverse fast Fourier transform on the updated target frequency spectrum to obtain a first target waveform.
Optionally, the digital signal filtering method further includes:
calculating a first data sequence number corresponding to a maximum whole period in the discrete data sequence based on the first length, the sampling rate and the period time under the condition that the reference number value is a non-integer, and dividing the discrete data sequence into a first subsequence and a second subsequence based on the first data sequence number;
Performing fast Fourier transform on the first subsequence and the second subsequence to obtain a first frequency spectrum and a second frequency spectrum;
Calculating a second target frequency spectrum value based on the period time, the sampling rate, the first length, the first data sequence number, the frequency spectrum values corresponding to the target suppression frequency point and the nearest frequency point on the right side of the target suppression frequency point, and updating the frequency spectrum values corresponding to the target suppression frequency point, the associated mirror frequency point and the nearest frequency point in the first frequency spectrum and the second frequency spectrum to be the second target frequency spectrum value;
And respectively carrying out inverse fast Fourier transform on the updated first frequency spectrum and the updated second frequency spectrum to obtain a first waveform and a second waveform, and combining the first waveform and the second waveform to obtain a second target waveform.
Optionally, the calculating, based on the first length, the sampling rate, and the period time, a first data sequence number corresponding to a maximum whole period in the discrete data sequence includes:
Multiplying the sampling rate by the cycle time to obtain a first calculation result;
dividing the first length and the first calculation result to obtain a second calculation result, and rounding down the second calculation result to obtain a first integer result;
And multiplying the first integer result with the first calculation result to obtain a third calculation result, and rounding down the third calculation result to obtain a first data sequence number corresponding to the maximum integer period in the discrete data sequence.
Optionally, the dividing the discrete data sequence into the first sub-sequence and the second sub-sequence based on the first data sequence number includes:
Determining a data sequence from a start data point to a first target data point corresponding to the first data sequence in the discrete data sequence as a first subsequence;
subtracting the first length from the first data sequence number to obtain a second data sequence number;
and determining a data sequence from a second target data point corresponding to the second data sequence to an end data point in the discrete data sequence as a second subsequence.
Optionally, the calculating, based on the period time, the sampling rate, the first length, the first data sequence number, the spectrum values corresponding to the target suppression frequency point and the nearest neighboring frequency point on the right side of the target suppression frequency point, includes:
Calculating to obtain the amplitude ratio of the target suppression frequency point relative to the nearest neighboring frequency point on the right side of the target suppression frequency point based on the cycle time, the sampling rate, the first length and the first data sequence number;
Multiplying the frequency spectrum value corresponding to the target suppression frequency point by the amplitude ratio to obtain a leakage frequency spectrum value, and subtracting the frequency spectrum value corresponding to the nearest frequency point on the right side of the target suppression frequency point from the leakage frequency spectrum value to obtain a second target frequency spectrum value.
Optionally, the calculating, based on the cycle time, the sampling rate, the first length, and the first data sequence number, an amplitude ratio of the target suppression frequency point to a nearest neighboring frequency point on the right side of the target suppression frequency point includes:
multiplying the sampling rate and the cycle time to obtain a first calculation result, dividing the first length by the first calculation result to obtain a second calculation result, and rounding down the second calculation result to obtain a first integer result;
Dividing the product of the first integer result and the sampling rate by the first data sequence number to obtain a measurement frequency, taking the reciprocal of the cycle time to obtain a suppression frequency, and dividing the difference between the suppression frequency and the measurement frequency by the measurement frequency to obtain a frequency offset proportion;
And calculating the amplitude ratio of the target suppression frequency point relative to the nearest neighboring frequency point on the right side of the target suppression frequency point based on the frequency offset proportion and the set sampling function.
Optionally, the calculating, based on the frequency offset ratio and the set sampling function, an amplitude ratio of the target suppression frequency point relative to a nearest neighboring frequency point on the right side of the target suppression frequency point includes:
Substituting the sum of the frequency offset proportion and a preset value into a set sampling function to calculate so as to obtain a first intermediate result;
substituting the frequency spectrum proportion into a set sampling function to calculate to obtain a second intermediate result;
And dividing the first intermediate result by the second intermediate result to obtain the amplitude ratio of the target suppression frequency point relative to the nearest neighboring frequency point on the right side of the target suppression frequency point.
Optionally, after the performing inverse fast fourier transform on the updated target spectrum to obtain a first target waveform, the method further includes:
The method comprises the steps of outputting the first target waveform to a display unit so that the display unit displays the first target waveform, and outputting the first target waveform to an FPGA unit so that the FPGA unit performs preset measurement processing and preset operation processing on the first target waveform.
In a second aspect, an embodiment of the present application further provides a digital signal filtering apparatus, where the digital signal filtering apparatus includes:
the acquisition unit is configured to acquire a discrete data sequence corresponding to the signal to be processed and acquire a period time corresponding to the target suppression frequency point;
the reference quantity value calculation unit is configured to calculate a sampling time based on the first length of the discrete data sequence and a sampling rate corresponding to the set analog-to-digital converter, and divide the sampling time by the period time to obtain a reference quantity value;
The first frequency spectrum updating unit is configured to perform fast Fourier transform on the discrete data sequence to obtain a target frequency spectrum under the condition that the reference quantity value is an integer, and update the frequency spectrum values corresponding to the target suppression frequency points and the associated image frequency points in the target frequency spectrum to first target frequency spectrum values corresponding to the nearest neighboring frequency points positioned on the right side of the target suppression frequency points;
and the first waveform determining unit is configured to perform inverse fast Fourier transform on the updated target frequency spectrum to obtain a first target waveform.
Optionally, the digital signal filtering device further includes:
The second spectrum updating unit is configured to calculate a first data sequence number corresponding to the maximum whole period in the discrete data sequence based on the first length, the sampling rate and the period time under the condition that the reference quantity value is a non-integer, divide the discrete data sequence into a first subsequence and a second subsequence based on the first data sequence number, respectively perform fast Fourier transform on the first subsequence and the second subsequence to obtain a first spectrum and a second spectrum, calculate a second target spectrum value based on the period time, the sampling rate, the first length, the first data sequence number, the target suppression frequency point and spectrum values corresponding to the nearest frequency point on the right side of the target suppression frequency point, and update the first spectrum and the second spectrum with the target suppression frequency point, the associated mirror frequency point and spectrum values corresponding to the nearest frequency point;
and the second waveform determining unit is configured to respectively perform inverse fast Fourier transform on the updated first frequency spectrum and the updated second frequency spectrum to obtain a first waveform and a second waveform, and combine the first waveform and the second waveform to obtain a second target waveform.
Optionally, the second spectrum updating unit includes:
The sequence number calculation module is configured to multiply the sampling rate with the cycle time to obtain a first calculation result, divide the first length by the first calculation result to obtain a second calculation result, and round down the second calculation result to obtain a first integer result, multiply the first integer result with the first calculation result to obtain a third calculation result, and round down the third calculation result to obtain a first data sequence number corresponding to the maximum whole cycle in the discrete data sequence.
Optionally, the second spectrum updating unit includes:
the sequence splitting module is configured to determine a data sequence from a first target data point corresponding to the first data sequence number to be a first subsequence in the discrete data sequence, subtract the first length from the first data sequence number to obtain a second data sequence number, and determine a data sequence from a second target data point corresponding to the second data sequence number to a terminal data point in the discrete data sequence to be a second subsequence.
Optionally, the second spectrum updating unit includes:
The frequency spectrum value calculation module is configured to calculate an amplitude ratio of the target suppression frequency point relative to the nearest neighboring frequency point on the right side of the target suppression frequency point based on the cycle time, the sampling rate, the first length and the first data sequence number, multiply the frequency spectrum value corresponding to the target suppression frequency point with the amplitude ratio to obtain a leakage frequency spectrum value, and subtract the frequency spectrum value corresponding to the nearest neighboring frequency point on the right side of the target suppression frequency point with the leakage frequency spectrum value to obtain a second target frequency spectrum value.
Optionally, the spectral value calculation module is further configured to:
multiplying the sampling rate and the cycle time to obtain a first calculation result, dividing the first length by the first calculation result to obtain a second calculation result, and rounding down the second calculation result to obtain a first integer result;
Dividing the product of the first integer result and the sampling rate by the first data sequence number to obtain a measurement frequency, taking the reciprocal of the cycle time to obtain a suppression frequency, and dividing the difference between the suppression frequency and the measurement frequency by the measurement frequency to obtain a frequency offset proportion;
And calculating the amplitude ratio of the target suppression frequency point relative to the nearest neighboring frequency point on the right side of the target suppression frequency point based on the frequency offset proportion and the set sampling function.
Optionally, the spectral value calculation module is further configured to:
Substituting the sum of the frequency offset proportion and a preset value into a set sampling function to calculate so as to obtain a first intermediate result;
substituting the frequency spectrum proportion into a set sampling function to calculate to obtain a second intermediate result;
And dividing the first intermediate result by the second intermediate result to obtain the amplitude ratio of the target suppression frequency point relative to the nearest neighboring frequency point on the right side of the target suppression frequency point.
Optionally, the device further comprises a result output unit configured to:
The method comprises the steps of outputting the first target waveform to a display unit so that the display unit displays the first target waveform, and outputting the first target waveform to an FPGA unit so that the FPGA unit performs preset measurement processing and preset operation processing on the first target waveform.
In a third aspect, an embodiment of the present application further provides an electronic device, where the device includes one or more processors, and a storage configured to store one or more programs, where the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the digital signal filtering method according to the embodiment of the present application.
In a fourth aspect, embodiments of the present application also provide a non-volatile storage medium storing computer-executable instructions that, when executed by a computer processor, are configured to perform the digital signal filtering method of embodiments of the present application.
In the embodiment of the application, a discrete data sequence corresponding to a signal to be processed is obtained, a period time corresponding to a target suppression frequency point is obtained, a sampling time is calculated based on a first length of the discrete data sequence and a sampling rate corresponding to a set analog-to-digital converter, the sampling time and the period time are divided to obtain a reference quantity value, under the condition that the reference quantity value is an integer, the discrete data sequence is subjected to fast Fourier transform to obtain a target frequency spectrum, the frequency spectrum values corresponding to the target suppression frequency point and an associated mirror frequency point in the target frequency spectrum are updated to a first target frequency spectrum value corresponding to a nearest adjacent frequency point positioned on the right side of the target suppression frequency point, and the updated target frequency spectrum is subjected to fast Fourier inverse transform to obtain a first target waveform. In the above scheme, the reference quantity value is obtained by dividing the calculated sampling time and the period time, so that whether the signal corresponding to the target inhibition frequency point is sampled in the whole period or not can be effectively judged, reliable data reference is provided for the filtering operation to be subsequently adopted, under the condition that the reference quantity value is an integer, the time domain signal corresponding to the target inhibition frequency point can be sampled in the whole period, the discrete data sequence is subjected to fast Fourier transform to obtain the target frequency spectrum, the filtering processing on the specific frequency point in the frequency domain can be realized, the filtering granularity is refined, the frequency spectrum values corresponding to the target inhibition frequency point and the image frequency point related to the target inhibition frequency point in the target frequency spectrum are updated to be the first target frequency spectrum value corresponding to the nearest frequency point positioned on the right side of the target inhibition frequency point, the complete recovery waveform can be effectively ensured while the target inhibition frequency point is removed, the signal distortion is reduced, and the filtering effect is improved.
Detailed Description
Embodiments of the present application will be described in further detail below with reference to the drawings and examples. It should be understood that the particular embodiments described herein are illustrative only and are not limiting of embodiments of the application. It should be further noted that, for convenience of description, only some, but not all of the structures related to the embodiments of the present application are shown in the drawings.
The terms first, second and the like in the description and in the claims, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged, as appropriate, such that embodiments of the present application may be implemented in sequences other than those illustrated or described herein, and that the objects identified by "first," "second," etc. are generally of a type, and are not limited to the number of objects, such as the first object may be one or more. Furthermore, in the description and claims, "and/or" means at least one of the connected objects, and the character "/", generally means that the associated object is an "or" relationship.
In the digital signal filtering method provided by the embodiment of the present application, the execution main body of each step may be a computer device, where the computer device refers to any electronic device having data computing, processing and storage capabilities, for example, a terminal device such as a PC (Personal Computer ) or a device such as a server.
The inventors found that, in a process of separating signals of various frequency components using an FIR filter or an IIR filter in particular, since the FIR filter or the IIR filter is used to convolve a specific impulse response with an original signal, a filtered waveform is obtained, and the data at the forefront is unstable and error data is easy to occur, so that signal distortion occurs in the initial part of the filtered waveform. Second, the use of FIR filters or IIR filters can only remove signals in certain specific frequency ranges, e.g., signals above a certain frequency or below a certain frequency, and cannot be specific to removing signals at a certain frequency point or points. Furthermore, when the frequencies of the desired signal and the interference signal are close, the FIR or IIR filter cannot provide a good filtering effect. Therefore, the application aims to provide a digital signal filtering method, a device, equipment and a storage medium, which solve the problems that waveforms obtained by adopting an FIR filter or an IIR filter in the related technology are easy to generate distortion, can only be suitable for signal filtering in a special frequency spectrum range, have rough filtering granularity and relatively poor filtering effect.
Fig. 1 is a flowchart of a digital signal filtering method according to an embodiment of the present application, where the digital signal filtering method may be implemented by using a processor as an execution body. As shown in fig. 1, the digital signal filtering method specifically includes the following steps:
Step S110, a discrete data sequence corresponding to a signal to be processed is obtained, and a period time corresponding to a target suppression frequency point is obtained.
The discrete data sequence may be a digital signal obtained by converting a signal to be processed by an analog-to-digital converter, and specifically includes a plurality of discrete data points in a time domain. It should be noted that, the cycle time of the target suppression frequency point may be a cycle time corresponding to a power frequency signal to be suppressed, which is preset by a developer according to a specific requirement of an actual application scenario, for example, for a 50Hz power frequency signal, the corresponding cycle time is 0.02s.
Step S120, calculating a sampling time based on the first length of the discrete data sequence and the sampling rate corresponding to the set analog-to-digital converter, and dividing the sampling time by the period time to obtain a reference quantity value.
Specifically, the first length represents the number of data points of the discrete data sequence, and the sampling rate corresponding to the analog-to-digital converter represents the number of sample data points acquired by the analog-to-digital converter per second, so that a correlation formula of sampling time is calculated as follows:
ts=L/Fs,
where t s is the sampling time, L is the first length, and F s is the sampling rate of the analog-to-digital converter. It can be appreciated that the sampling time needs to ensure a period time corresponding to the target suppression frequency point greater than 2 times, so as to effectively collect and remove the time domain signal corresponding to the target suppression frequency point.
In addition, in order to effectively remove the time domain signal corresponding to the target suppression frequency point, it is necessary to determine whether the frequency point signal is sampled in the whole period, so as to take a corresponding filtering operation. Specifically, the reference quantity value can be obtained by dividing the sampling time by the period time, and the correlation formula is as follows:
num=ts/T1,
wherein num is a reference quantity value, T s is a sampling time, and T 1 is a period time corresponding to the target suppression frequency point. If the reference number value is an integer, it indicates that the time domain signal corresponding to the target suppression frequency point can be sampled by integer multiple, and if the reference number value is a non-integer, it indicates that the time domain signal corresponding to the target suppression frequency point cannot be sampled by integer multiple, so that different filtering processes can be adopted for different judging results.
Step S130, under the condition that the reference quantity value is an integer, performing fast Fourier transform on the discrete data sequence to obtain a target frequency spectrum, and updating the frequency spectrum values corresponding to the target suppression frequency point and the associated mirror frequency point in the target frequency spectrum to a first target frequency spectrum value corresponding to the nearest neighboring frequency point positioned on the right side of the target suppression frequency point.
If the reference data value is an integer, it is indicated that the time domain signal corresponding to the target suppression frequency point may be sampled by an integer multiple, so that the discrete data sequence may be directly subjected to fast fourier transform to obtain the target frequency spectrum, and the discrete data sequence may be converted into the frequency domain for processing. Although the filtering purpose can be achieved by directly removing the frequency spectrum values corresponding to the target suppression frequency points and the image frequency points related to the target suppression frequency points in the target frequency spectrum, part of the effective components are easy to filter out, so that the integrity of the finally obtained target waveform is affected. Therefore, the frequency spectrum values corresponding to the target inhibition frequency points and the associated image frequency points can be updated to the first target frequency spectrum value corresponding to the nearest frequency point positioned on the right side of the target inhibition frequency points, so that the integrity of the finally obtained target waveform can be ensured while the target inhibition frequency points are filtered. Specifically, fig. 2 is a schematic diagram of filtering out a target suppression frequency point on a frequency domain according to an embodiment of the present application, as shown in fig. 2, F1 is a target suppression frequency point, F2 is a nearest frequency point located on the right side of the target suppression frequency point, and the purpose of filtering out the target suppression frequency point is achieved by updating a frequency spectrum value corresponding to the target suppression frequency point F1 to a first target frequency spectrum value of the nearest frequency point F2, where it is required to be noted that an updating process of a frequency spectrum value corresponding to an associated mirror frequency point is not shown in fig. 2.
And step 140, performing inverse fast fourier transform on the updated target spectrum to obtain a first target waveform.
It can be understood that in this embodiment, the discrete data sequence corresponding to the signal to be processed is converted into the frequency domain through the fft, and is filtered, and is restored to the time domain through the fft, so that the distortion of the target waveform can be reduced, and meanwhile, the signal of the individual frequency point or several discrete individual frequency points can be removed without affecting the nearby frequency points.
Optionally, after performing inverse fast fourier transform on the updated target spectrum to obtain the first target waveform, the method further includes:
The method comprises the steps of outputting a first target waveform to a display unit so that the display unit displays the first target waveform, and outputting the first target waveform to an FPGA unit so that the FPGA unit performs preset measurement processing and preset operation processing on the first target waveform.
It should be noted that, the display unit may display the first target waveform to display the waveform after filtering the target suppression frequency point to the user, and the FPGA unit may perform a preset measurement process and a preset operation process on the first target waveform, where the preset measurement process may be frequency measurement, amplitude measurement, phase measurement, and the like, and the preset operation process may be smoothing process, enhancement process, and the like, and the application is not limited herein.
According to the method, the discrete data sequence corresponding to the signal to be processed is obtained, the period time corresponding to the target suppression frequency point is obtained, the sampling time is calculated based on the first length of the discrete data sequence and the sampling rate corresponding to the set analog-to-digital converter, the sampling time and the period time are divided to obtain the reference quantity value, under the condition that the reference quantity value is an integer, the discrete data sequence is subjected to fast Fourier transform to obtain a target frequency spectrum, the frequency spectrum values corresponding to the target suppression frequency point and the associated mirror frequency point in the target frequency spectrum are updated to be the first target frequency spectrum value corresponding to the nearest adjacent frequency point positioned on the right side of the target suppression frequency point, and the updated target frequency spectrum is subjected to fast Fourier inverse transform to obtain the first target waveform. In the above scheme, the reference quantity value is obtained by dividing the calculated sampling time and the period time, so that whether the signal corresponding to the target inhibition frequency point is sampled in the whole period or not can be effectively judged, reliable data reference is provided for the filtering operation to be subsequently adopted, under the condition that the reference quantity value is an integer, the signal corresponding to the target inhibition frequency point can be sampled in the whole period, the discrete data sequence is subjected to fast Fourier transform to obtain the target frequency spectrum, the filtering processing on the frequency domain for the specific frequency point can be realized, the filtering granularity is refined, and the frequency spectrum values corresponding to the target inhibition frequency point and the image frequency point associated with the target inhibition frequency point in the target frequency spectrum are updated to be the first target frequency spectrum value corresponding to the nearest frequency point positioned on the right side of the target inhibition frequency point, so that the complete reduction waveform can be effectively ensured while the target inhibition frequency point is removed, the signal distortion is reduced, and the filtering effect is improved.
Fig. 3 is a flowchart of another digital signal filtering method according to an embodiment of the present application, as shown in fig. 3, where the digital signal filtering method specifically includes the following steps:
Step S210, obtaining a discrete data sequence corresponding to a signal to be processed, and obtaining a period time corresponding to a target suppression frequency point.
Step S220, calculating to obtain sampling time based on the first length of the discrete data sequence and the sampling rate corresponding to the set analog-to-digital converter, and dividing the sampling time by the period time to obtain a reference quantity value.
Step S230, under the condition that the reference quantity value is an integer, performing fast Fourier transform on the discrete data sequence to obtain a target frequency spectrum, and updating the frequency spectrum values corresponding to the target suppression frequency point and the associated mirror frequency point in the target frequency spectrum to a first target frequency spectrum value corresponding to the nearest neighboring frequency point positioned on the right side of the target suppression frequency point.
Step S240, performing inverse fast Fourier transform on the updated target frequency spectrum to obtain a first target waveform.
Step S250, under the condition that the reference quantity value is a non-integer, calculating a first data sequence number corresponding to the maximum whole period in the discrete data sequence based on the first length, the sampling rate and the period time, and dividing the discrete data sequence into a first sub-sequence and a second sub-sequence based on the first data sequence number.
If the reference number value is a non-integer, it indicates that the time domain signal corresponding to the target suppression frequency point cannot be sampled by integer multiple, and the discrete data sequence needs to be split into two subsequences for separate processing, so as to ensure that the target suppression frequency point can be completely filtered. By combining the first length, the sampling rate and the period time, the first data sequence number corresponding to the maximum whole period in the discrete data sequence can be calculated and determined, so that the discrete data sequence is effectively split.
In an alternative embodiment, a specific implementation process of calculating a first data sequence number corresponding to a maximum integer period in a discrete data sequence based on a first length, a sampling rate and a cycle time is described, please refer to fig. 4, which is a flowchart of a specific implementation process of determining a first data sequence number corresponding to a maximum integer period in a discrete data sequence according to an embodiment of the present application, and as shown in fig. 4, the specific implementation steps of calculating a first data sequence number corresponding to a maximum integer period in a discrete data sequence based on a first length, a sampling rate and a cycle time are as follows:
step S251, multiplying the sampling rate by the cycle time to obtain a first calculation result.
Step S252, dividing the first length by the first calculation result to obtain a second calculation result, and rounding down the second calculation result to obtain a first integer result.
Step 253, multiplying the first integer result with the first calculation result to obtain a third calculation result, and rounding down the third calculation result to obtain a first data sequence number corresponding to the maximum integer period in the discrete data sequence.
It should be noted that, in combination with the related descriptions in steps S251-S253, the related formula of the first data sequence number corresponding to the maximum whole period in the discrete data sequence is calculated as follows:
Wherein numsimple is a first data sequence number, F s is a sampling rate corresponding to the analog-to-digital converter, T 1 is a period time corresponding to the target suppression frequency point, L is a first length of the discrete data sequence, Is a round down function.
In an alternative embodiment, a specific implementation process of dividing a discrete data sequence into a first sub-sequence and a second sub-sequence based on a first data sequence number is described, please refer to fig. 5, which is a flowchart of a specific implementation process of dividing a discrete data sequence into a first sub-sequence and a second sub-sequence according to an embodiment of the present application, as shown in fig. 5, the specific implementation steps of dividing a discrete data sequence into a first sub-sequence and a second sub-sequence based on a first data sequence number are as follows:
Step S254, determining a data sequence from a start data point to a first target data point corresponding to the first data sequence number in the discrete data sequence as a first sub-sequence.
Step S255, subtracting the first length from the first data sequence number to obtain a second data sequence number;
step S256, determining a data sequence from a second target data point corresponding to the second data sequence to the tail end data point in the discrete data sequence as a second sub-sequence.
It should be noted that, the correlation formula for determining the first subsequence and the second subsequence is as follows:
Data_adc1=Data_adc[:numsimple],
Data_adc2=Data_adc[L-numsimple:],
Wherein, data_adc1 is a first sub-sequence, data_adc2 is a second sub-sequence, data_adc is a discrete Data sequence, L is a first length, numsimple is a first Data sequence number, numsimple is a first Data sequence number from a start Data point to a first target Data point, it is understood that the first length L and the first Data sequence number numsimple can obtain a second Data sequence number, and L-numsimple is a Data sequence number from the second target Data point to an end Data point. Specifically, fig. 6 is a schematic diagram of splitting a discrete data sequence into a first sub-sequence and a second sub-sequence according to an embodiment of the present application, and as shown in fig. 6, a discrete data sequence 101 may be split into a first sub-sequence 102 and a second sub-sequence 103 based on a first data sequence number.
Step S260, performing fast Fourier transform on the first sub-sequence and the second sub-sequence to obtain a first frequency spectrum and a second frequency spectrum.
The first sub-sequence and the second sub-sequence are subjected to fast Fourier transform, and can be converted into a frequency domain for processing.
Step S270, based on the cycle time, the sampling rate, the first length, the first data sequence number, the frequency spectrum values corresponding to the target suppression frequency point and the nearest frequency point on the right side of the target suppression frequency point, a second target frequency spectrum value is obtained through calculation, and the frequency spectrum values corresponding to the target suppression frequency point, the associated mirror frequency point and the nearest frequency point in the first frequency spectrum and the second frequency spectrum are updated to be the second target frequency spectrum value.
In an alternative embodiment, a specific implementation process of calculating a second target spectrum value based on a period time, a sampling rate, a first length, a first data sequence number, a target suppression frequency point, and spectrum values corresponding to the nearest frequency point on the right side of the target suppression frequency point is described, please refer to fig. 7, which is a flowchart of a specific implementation process of calculating a second target spectrum value provided in an embodiment of the present application, as shown in fig. 7, and the specific implementation steps of calculating a second target spectrum value based on a period time, a sampling rate, a first length, a first data sequence number, spectrum values corresponding to the target suppression frequency point, and spectrum values corresponding to the nearest frequency point on the right side of the target suppression frequency point are as follows:
In step S271, the amplitude ratio of the target suppression frequency point to the nearest neighboring frequency point on the right side is calculated based on the cycle time, the sampling rate, the first length and the first data sequence number.
In a specific embodiment, fig. 8 is a flowchart of a specific implementation process for calculating an amplitude ratio of a target suppression frequency point to a nearest neighboring frequency point on the right side of the target suppression frequency point according to the embodiment of the present application, as shown in fig. 8, and specifically includes the following steps:
Step S2711, multiplying the sampling rate by the cycle time to obtain a first calculation result, dividing the first length by the first calculation result to obtain a second calculation result, and rounding down the second calculation result to obtain a first integer result.
Step S2712, dividing the product of the first integer result and the sampling rate by the first data sequence number to obtain a measurement frequency, taking the reciprocal of the cycle time to obtain a suppression frequency, and dividing the difference between the suppression frequency and the measurement frequency by the measurement frequency to obtain a frequency offset ratio.
Specifically, the calculation formula of the suppression frequency is as follows:
Wherein F 1 is the suppression frequency, and T 1 is the cycle time of the target suppression frequency point.
The calculation formula of the measurement frequency is as follows:
Wherein F m is the measurement frequency, F s is the sampling rate corresponding to the analog-to-digital converter, T 1 is the period time corresponding to the target suppression frequency point, L is the first length of the discrete data sequence, numsimple is the first data sequence number corresponding to the maximum whole period in the discrete data sequence, Is a round down function. The measurement frequency is obtained by converting a discrete data sequence into a frequency domain by a fast fourier transform, and is deviated from a theoretical suppression frequency.
The calculation formula of the frequency offset proportion is as follows:
Where k is the frequency offset ratio, F 1 is the suppression frequency, and F m is the measurement frequency.
Step S2713, calculating the amplitude ratio of the target suppression frequency point relative to the nearest neighboring frequency point on the right side based on the frequency offset ratio and the set sampling function.
Specifically, the sampling function may adopt a sin c () function, and a specific calculation process for calculating the amplitude ratio based on the frequency offset ratio and the set sampling function is as follows:
And substituting the sum of the frequency offset proportion and the preset numerical value into the set sampling function to obtain a first intermediate result, substituting the frequency spectrum proportion into the set sampling function to obtain a second intermediate result, and dividing the first intermediate result and the second intermediate result to obtain the amplitude ratio of the target suppression frequency point relative to the nearest neighbor frequency point on the right side of the target suppression frequency point.
Correspondingly, the magnitude ratio is calculated as follows:
where k amp is the amplitude ratio and k is the frequency offset ratio.
Step S272, multiplying the frequency spectrum value corresponding to the target suppression frequency point by the amplitude ratio to obtain a leakage frequency spectrum value, and subtracting the frequency spectrum value corresponding to the nearest frequency point on the right side of the target suppression frequency point from the leakage frequency spectrum value to obtain a second target frequency spectrum value.
It should be noted that, because the reference value is a non-integer, the time domain signal of the target suppression frequency point may not be completely sampled, and the energy corresponding to the target suppression frequency point may leak to the nearest neighboring frequency point, so that the component of the frequency spectrum value corresponding to the target suppression frequency point leaking to the nearest neighboring frequency point can be obtained by calculating the leakage frequency spectrum value, and the component needs to be removed, so that the real frequency spectrum value of the nearest neighboring frequency point can be restored, otherwise, the distortion of the target waveform obtained later may be caused.
Specifically, fig. 9 is another schematic diagram of filtering out a target suppression frequency point on a frequency domain, as shown in fig. 9, where F1 is a target suppression frequency point, F2 is a nearest frequency point located on the right side of the target suppression frequency point, a leakage spectrum value Δ may be obtained by multiplying a spectrum value corresponding to the target suppression frequency point F1 by an amplitude ratio k amp, a second target spectrum value may be obtained by subtracting the leakage spectrum value Δ from an amplitude value corresponding to the nearest frequency point F2, and the purpose of filtering out the target suppression frequency point F1 is achieved by updating the spectrum value corresponding to the target suppression frequency point F1 to the second target spectrum value of the nearest frequency point F2.
Step S280, performing inverse fast Fourier transform on the updated first frequency spectrum and second frequency spectrum to obtain a first waveform and a second waveform, and combining the first waveform and the second waveform to obtain a second target waveform.
In one embodiment, the correlation formula for combining the first waveform and the second waveform is as follows:
Data_highfir[]=Data_highfir1[:]+Data_highfir2[2*numsimple-L:],
Wherein, data_ highfir [ ] is the second target waveform, data_ highfir [ ] is the first waveform, and data_ highfir2[ ] is the second waveform, it is noted that, in order to recover the second target waveform of length L, data_ highfir1[: ] represents all Data points extracting the first waveform, data_ highfir2[2×numsimple-L: ] represents all Data points extracting from the middle Data point to the end Data point of Data sequence number 2×numsimple-L in the second waveform.
In another embodiment, the first waveform and the second waveform may be weighted and combined to obtain the second target waveform with the first length, which is not limited in this application.
Optionally, after combining the first waveform and the second waveform to obtain a second target waveform, the method further includes:
and outputting the second target waveform to a display unit so that the display unit displays the second target waveform, and outputting the second target waveform to an FPGA unit so that the FPGA unit performs preset measurement processing and preset operation processing on the second target waveform.
It should be noted that, the display unit may display the second target waveform to display the waveform after filtering the target suppression frequency point to the user, and the FPGA unit may perform a preset measurement process and a preset operation process on the second target waveform, where the preset measurement process may be frequency measurement, amplitude measurement, phase measurement, and the like, and the preset operation process may be smoothing process, enhancement process, and the like, and the application is not limited herein.
In the above-mentioned case, when the reference number value is a non-integer, it may be considered that the time domain signal corresponding to the target suppression frequency point is not sampled in the whole period, the discrete data sequence needs to be intercepted before and after the whole period of the target suppression frequency point, and after the discrete data sequence is processed in the frequency domain respectively, the frequency spectrum value corresponding to the target suppression frequency point is updated to the second target frequency spectrum value corresponding to the nearest neighboring frequency point while the leakage amount of the target suppression frequency point is removed from the nearest neighboring frequency point, so that the frequency spectrum leakage is not generated, the target suppression frequency point is removed, the waveform is completely restored, and the signal distortion is reduced.
Fig. 10 is a block diagram of a digital signal filtering device according to an embodiment of the present application, where the device is configured to execute the digital signal filtering method according to the foregoing embodiment, and has functional modules and beneficial effects corresponding to the execution method. As shown in fig. 10, the digital signal filtering apparatus specifically includes:
an obtaining unit 201, configured to obtain a discrete data sequence corresponding to a signal to be processed, and obtain a cycle time corresponding to a target suppression frequency point;
A reference number value calculating unit 202 configured to calculate a sampling time based on the first length of the discrete data sequence and a sampling rate corresponding to the set analog-to-digital converter, and divide the sampling time by a period time to obtain a reference number value;
A first spectrum updating unit 203, configured to perform fast fourier transform on the discrete data sequence to obtain a target spectrum under the condition that the reference number value is an integer, and update the spectrum values corresponding to the target suppression frequency point and the associated image frequency point in the target spectrum to the first target spectrum value corresponding to the nearest neighboring frequency point located on the right side of the target suppression frequency point;
The first waveform determining unit 204 is configured to perform inverse fast fourier transform on the updated target spectrum to obtain a first target waveform.
According to the method, the discrete data sequence corresponding to the signal to be processed is obtained, the period time corresponding to the target suppression frequency point is obtained, the sampling time is calculated based on the first length of the discrete data sequence and the sampling rate corresponding to the set analog-to-digital converter, the sampling time and the period time are divided to obtain the reference quantity value, under the condition that the reference quantity value is an integer, the discrete data sequence is subjected to fast Fourier transform to obtain a target frequency spectrum, the frequency spectrum values corresponding to the target suppression frequency point and the associated mirror frequency point in the target frequency spectrum are updated to be the first target frequency spectrum value corresponding to the nearest adjacent frequency point positioned on the right side of the target suppression frequency point, and the updated target frequency spectrum is subjected to fast Fourier inverse transform to obtain the first target waveform. In the above scheme, the reference quantity value is obtained by dividing the calculated sampling time and the period time, so that whether the signal corresponding to the target inhibition frequency point is sampled in the whole period or not can be effectively judged, reliable data reference is provided for the filtering operation to be subsequently adopted, under the condition that the reference quantity value is an integer, the signal corresponding to the target inhibition frequency point can be sampled in the whole period, the discrete data sequence is subjected to fast Fourier transform to obtain the target frequency spectrum, the filtering processing on the frequency domain for the specific frequency point can be realized, the filtering granularity is refined, and the frequency spectrum values corresponding to the target inhibition frequency point and the image frequency point associated with the target inhibition frequency point in the target frequency spectrum are updated to be the first target frequency spectrum value corresponding to the nearest frequency point positioned on the right side of the target inhibition frequency point, so that the complete reduction waveform can be effectively ensured while the target inhibition frequency point is removed, the signal distortion is reduced, and the filtering effect is improved.
In one possible embodiment, the method further comprises:
The second spectrum updating unit is configured to calculate a first data sequence number corresponding to the maximum whole period in the discrete data sequence based on the first length, the sampling rate and the cycle time under the condition that the reference quantity value is a non-integer, divide the discrete data sequence into a first subsequence and a second subsequence based on the first data sequence number, respectively perform fast Fourier transform on the first subsequence and the second subsequence to obtain a first spectrum and a second spectrum, calculate a second target spectrum value based on the cycle time, the sampling rate, the first length, the first data sequence number, the target suppression frequency point and the spectrum value corresponding to the nearest frequency point on the right side of the target suppression frequency point, and update the spectrum value corresponding to the target suppression frequency point, the associated mirror frequency point and the nearest frequency point in the first spectrum and the second spectrum to the second target spectrum value;
And the second waveform determining unit is configured to perform inverse fast Fourier transform on the updated first frequency spectrum and the updated second frequency spectrum respectively to obtain a first waveform and a second waveform, and combine the first waveform and the second waveform to obtain a second target waveform.
In one possible embodiment, the second spectrum updating unit includes:
The serial number calculating module is configured to multiply the sampling rate and the cycle time to obtain a first calculation result, divide the first length by the first calculation result to obtain a second calculation result, and round down the second calculation result to obtain a first integer result, multiply the first integer result by the first calculation result to obtain a third calculation result, and round down the third calculation result to obtain a first data serial number corresponding to the maximum whole cycle in the discrete data sequence.
In one possible embodiment, the second spectrum updating unit includes:
the sequence splitting module is configured to determine a data sequence from a first target data point corresponding to a first data sequence number to be a first subsequence in the discrete data sequence, subtract the first length from the first data sequence number to obtain a second data sequence number, and determine a data sequence from a second target data point corresponding to the second data sequence number to a terminal data point in the discrete data sequence to be a second subsequence.
In one possible embodiment, the second spectrum updating unit includes:
The frequency spectrum value calculating module is configured to calculate the amplitude ratio of the target inhibition frequency point relative to the nearest adjacent frequency point on the right side based on the cycle time, the sampling rate, the first length and the first data sequence number, multiply the frequency spectrum value corresponding to the target inhibition frequency point with the amplitude ratio to obtain a leakage frequency spectrum value, and subtract the frequency spectrum value corresponding to the nearest adjacent frequency point on the right side of the target inhibition frequency point with the leakage frequency spectrum value to obtain a second target frequency spectrum value.
In one possible embodiment, the spectral value calculation module is further configured to:
multiplying the sampling rate and the cycle time to obtain a first calculation result, dividing the first length by the first calculation result to obtain a second calculation result, and rounding down the second calculation result to obtain a first integer result;
Dividing the product of the first integer result and the sampling rate by the first data sequence number to obtain a measurement frequency, taking the reciprocal of the period time to obtain a suppression frequency, and dividing the difference between the suppression frequency and the measurement frequency by the measurement frequency to obtain a frequency offset proportion;
And calculating the amplitude ratio of the target suppression frequency point relative to the nearest adjacent frequency point on the right side of the target suppression frequency point based on the frequency offset ratio and the set sampling function.
In one possible embodiment, the spectral value calculation module is further configured to:
substituting the sum of the frequency offset proportion and the preset value into a set sampling function to calculate so as to obtain a first intermediate result;
Substituting the frequency spectrum proportion into the set sampling function to calculate to obtain a second intermediate result;
And dividing the first intermediate result by the second intermediate result to obtain the amplitude ratio of the target suppression frequency point relative to the nearest adjacent frequency point on the right side of the target suppression frequency point.
In a possible embodiment, the device further comprises a result output unit configured to:
The method comprises the steps of outputting a first target waveform to a display unit so that the display unit displays the first target waveform, and outputting the first target waveform to an FPGA unit so that the FPGA unit performs preset measurement processing and preset operation processing on the first target waveform.
Fig. 11 is a schematic structural diagram of an electronic device according to an embodiment of the present application, where, as shown in fig. 11, the device includes a processor 301, a memory 302, an input device 303, and an output device 304, where the number of processors 301 in the device may be one or more, in fig. 11, one processor 301 is taken as an example, and the processor 301, the memory 302, the input device 303, and the output device 304 in the device may be connected by a bus or other manners, in fig. 11, which is taken as an example by bus connection. The memory 302 is a computer readable storage medium, and may be configured to store a software program, a computer executable program, and modules, such as program instructions/modules corresponding to the digital signal filtering method in the embodiment of the present application. The processor 301 executes various functional applications of the device and data processing, i.e., implements the digital signal filtering method described above, by running software programs, instructions, and modules stored in the memory 302. The input means 303 may be configured to receive input numeric or character information and to generate key signal inputs related to user settings and function control of the device. The output device 304 may include a display device such as a display screen. Specifically, the electronic device may be an oscilloscope, where the oscilloscope may include an analog conditioning unit, an analog-to-digital converter, an FPGA unit, a processor unit, a first storage unit, a second storage unit, and a display device, where the analog conditioning unit may be configured to receive a signal to be processed and transmit the signal to be processed to the analog-to-digital converter, the analog-to-digital converter may convert the signal to be processed into a discrete data sequence and transmit the discrete data sequence to the FPGA unit, the FPGA unit may store the discrete data sequence to the first storage unit and transmit the discrete data sequence to the processor unit, the processor unit may perform filtering processing on the discrete data sequence and transmit an obtained waveform result to the display device and the FPGA unit, and the display device may display the waveform result, and the FPGA unit may perform measurement processing and operation processing on the waveform result.
The electronic device provided by the above can be used for executing the digital signal filtering method provided by any embodiment, and has corresponding functions and beneficial effects.
The embodiment of the application also provides a nonvolatile storage medium containing computer executable instructions, wherein the computer executable instructions are configured to execute a digital signal filtering method described in the above embodiment when executed by a computer processor, the digital signal filtering method comprises the steps of obtaining a discrete data sequence corresponding to a signal to be processed, obtaining a period time corresponding to a target suppression frequency point, calculating to obtain a sampling time based on a first length of the discrete data sequence and a sampling rate corresponding to a set analog-to-digital converter, dividing the sampling time by the period time to obtain a reference quantity value, performing fast Fourier transform on the discrete data sequence to obtain a target frequency spectrum under the condition that the reference quantity value is an integer, updating spectrum values corresponding to each of the target suppression frequency point and an associated image frequency point in the target frequency spectrum to a first target spectrum value corresponding to a nearest frequency point positioned on the right side of the target suppression frequency point, and performing fast Fourier transform on the updated target frequency spectrum to obtain a first target waveform.
Storage media-any of various types of memory devices or storage devices. The term "storage medium" is intended to include mounting media such as CD-ROM, floppy disk or tape devices, computer system memory or random access memory such as DRAM, DDR RAM, SRAM, EDO RAM, lanbas (Rambus) RAM, etc., non-volatile memory such as flash memory, magnetic media, and optical storage, registers or other similar types of memory elements, etc. The storage medium may also include other types of memory or combinations thereof. In addition, the storage medium may be located in a first computer system in which the program is executed, or may be located in a second, different computer system connected to the first computer system through a network such as the internet. The second computer system may provide program instructions to the first computer for execution. The term "storage medium" may include two or more storage media residing in different locations (e.g., in different computer systems connected by a network). The storage medium may store program instructions (e.g., embodied as a computer program) executable by one or more processors.
Of course, the storage medium containing the computer executable instructions provided in the embodiments of the present application is not limited to the above digital signal filtering method, and may also perform the related operations in the digital signal filtering method provided in any embodiment of the present application.
It should be noted that, in the embodiment of the digital signal filtering apparatus, each unit and module included are only divided according to the functional logic, but not limited to the above-mentioned division, as long as the corresponding functions can be implemented, and the specific names of the functional units are only for convenience of distinguishing from each other, and are not configured to limit the protection scope of the embodiment of the present application.
It should be noted that, the numbers of the steps in the solution are only used to describe the overall design framework of the solution, and do not represent the necessary sequence relationship between the steps. On the basis that the whole implementation process accords with the whole design framework of the scheme, the method belongs to the protection scope of the scheme, and the literal sequence during description is not an exclusive limit on the specific implementation process of the scheme. It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product. In one typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory. The memory may include volatile memory in a computer-readable medium, random Access Memory (RAM) and/or nonvolatile memory, etc., such as Read Only Memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises an element.
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.