Pulse signal frequency adaptive acquisition method and system based on KDE algorithm

By combining the KDE algorithm with hardware circuitry, adaptive sampling was achieved, solving the problems of frequency aliasing and data loss in traditional methods, and improving the accuracy and adaptability of pulse signal acquisition.

CN121966548APending Publication Date: 2026-05-01CHINA RAILWAY HI TECH IND CORP LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA RAILWAY HI TECH IND CORP LTD
Filing Date
2026-01-15
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

Traditional pulse signal acquisition methods with fixed sampling rates are prone to frequency aliasing, data redundancy, or missed sampling. Furthermore, high noise signals affect measurement accuracy. Existing KDE-based methods are too complex to be implemented on conventional MCUs.

Method used

A pulse signal frequency adaptive acquisition method based on the KDE algorithm is adopted. The frequency distribution of the input pulse signal is modeled by the KDE algorithm, and adaptive sampling is realized by combining hardware circuit. The peak index fast search algorithm is used to determine the sampling frequency and frequency threshold, and the sampling strategy is optimized to improve the acquisition accuracy.

Benefits of technology

It achieves high-precision pulse signal acquisition, avoids frequency aliasing and data loss, and significantly improves the system's adaptability to different application scenarios and the reliability of the acquisition module.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121966548A_ABST
    Figure CN121966548A_ABST
Patent Text Reader

Abstract

The invention provides a pulse signal frequency adaptive acquisition method and system based on a KDE algorithm, and the method comprises the steps: carrying out the isolation protection and voltage conversion of an external pulse signal, and obtaining a TTL level signal; tTL (transistor-transistor logic) level signals are accessed to a GPIO (general purpose input / output) pin with a timer multiplexing function of the MCU module for pulse counting; entering a timer interrupt function after a pulse rising edge of a TTL level signal is triggered, capturing a current timer capturing register value of two continuous rising edges, calculating a difference value, performing conversion in combination with a timer set frequency to complete primary frequency measurement, and storing frequency data into a global variable array; processing the acquired frequency data through a KDE algorithm to obtain frequency distribution of the current pulse input signal; and determining a sampling frequency and a frequency threshold by using a peak index fast search algorithm, and performing signal capture according to the sampling frequency. Through the KDE algorithm, the frequency of the input pulse signal is adaptively acquired, and the interference of the high-frequency signal is inhibited.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of automation control technology, and in particular to a pulse signal frequency adaptive acquisition method and system. Background Technology

[0002] Pulse acquisition and counting modules play a crucial role in various precision measurement and control systems, used to capture, measure, and process key parameters such as the frequency and period of pulse signals in real time. However, the frequency of the output pulse signal varies depending on the measurement scenario and object. Traditional fixed sampling rate acquisition methods are prone to frequency aliasing, data redundancy, or missed sampling, leading to decreased measurement accuracy or even loss of signal characteristics. Moreover, external interference can also generate high noise signals that affect the measurement, ultimately resulting in inaccurate counting results.

[0003] In recent years, adaptive sampling techniques based on kernel density estimation (KDE) have been increasingly applied in signal processing, such as the millimeter-wave radar point cloud target clustering method based on KDE-DBSCAN (publication number CN115047424B). However, existing methods struggle to balance sampling efficiency and frequency resolution accuracy, exhibiting high complexity and computational demands that make them difficult to implement on conventional MCUs. Furthermore, the complex algorithms used in existing high-speed acquisition research are difficult to implement on conventional MCUs, and the calculation of addition / subtraction counting, reset control, and acquisition pulse rate is also complex. Therefore, designing a pulse signal frequency adaptive acquisition method and system based on the KDE algorithm is of great significance for improving the data reliability of pulse signal acquisition. Summary of the Invention

[0004] To address the technical challenges of implementing complex algorithms for high-speed data acquisition in conventional MCUs, as well as the complexity of calculating addition / subtraction counts, reset control, and acquisition pulse rate, this invention proposes a pulse signal frequency adaptive acquisition method and system based on the KDE algorithm. By using the KDE algorithm, the frequency of the input pulse signal of the high-speed acquisition module is adaptively acquired, which solves the problem of using a fixed frequency to acquire signals in different application scenarios and suppresses interference from high-frequency signals.

[0005] To achieve the above objectives, the technical solution of the present invention is as follows: a pulse signal frequency adaptive acquisition method based on the KDE algorithm, comprising the following steps:

[0006] Step 1: Isolate and protect the external pulse signal and convert its voltage to obtain a TTL level signal;

[0007] Step 2: Connect the TTL level signal to the GPIO pin with timer multiplexing function of the MCU module to count pulses;

[0008] Step 3: After the rising edge of the TTL level signal pulse triggers, the timer interrupt function is entered, the current timer capture register value of two consecutive rising edges is captured, the difference is calculated, and the frequency is converted by combining the timer set frequency to complete one frequency measurement. The frequency data is then stored in the global variable array. This process is repeated to store a set of frequency data.

[0009] Step 4: Process the acquired frequency data using the KDE algorithm to obtain the frequency distribution of the current pulse input signal;

[0010] Step 5: Determine the sampling frequency and frequency threshold using the peak index fast search algorithm, and acquire the signal based on the sampling frequency. The KDE algorithm can be used for adaptive acquisition based on the sampling frequency of the input pulse signal.

[0011] Preferably, the GPIO pins of the MCU module's timer are configured for multiplexing and mapped to the timer input channels; the timer's clock, prescaler, counting mode, and auto-reload value are set; the trigger edges, filtering, and mapping relationships for each input capture channel are configured; interrupts are configured, enabling edge-triggered interrupts, and after a rising edge signal is captured and an interrupt is triggered, the counting accumulation operation is performed. The sampling frequency is counted through the GPIO pin configuration.

[0012] Preferably, the method for processing the acquired frequency data using the KDE algorithm in step four is as follows:

[0013] Step S1: Calculate the initial bandwidth using the median absolute deviation instead of the standard deviation;

[0014] Step S2: In the initial density estimation stage, the kernel function K(·) of the triangular kernel is used to calculate the initial density f0 of the data points of each frequency data data;

[0015] Step S3: Calculate the density geometric mean g and combine it with the adjustment sensitivity parameter α to obtain the local adjustment factor λ. i This leads to the generation of adaptive bandwidth h. i ;

[0016] Step S4: For each sampling point corresponding to an index value in the global variable array, only consider the neighborhood data points within the adaptive bandwidth range, and use their respective adaptive bandwidth h. i Weighted calculations are performed to obtain the final probability density estimate. The KDE algorithm of this invention employs a robust initial bandwidth calculation and adaptive bandwidth adjustment strategy based on the median absolute deviation.

[0017] Preferably, the initial bandwidth Where mad(data) is the median absolute deviation of the frequency data data; n is the number of sampling points for the frequency data;

[0018] The local adjustment factor λ i for ;

[0019] The adaptive bandwidth h i for This allows for a more robust initial bandwidth.

[0020] Preferably, the method for determining the sampling frequency and frequency threshold using the peak index fast search algorithm is as follows: The obtained probability density estimation result data is smoothed and filtered to determine the maximum value and record the corresponding index; scanning backwards from the position corresponding to the index until the current value is greater than the value corresponding to the index, initially determining the current value as the peak value and recording the peak index; continuing to scan backwards from the peak index until the current value is less than the peak value corresponding to the peak index, determining the current value as the second peak value and recording the corresponding index; the index value corresponding to the maximum value is the frequency of the input signal, and the sampling frequency is determined by frequency multiplication; the value of the index corresponding to the second peak value is the minimum interference frequency, and the starting index value of the second peak value is used as the frequency threshold; the peak index fast search algorithm can quickly determine the sampling frequency and frequency threshold of the input signal.

[0021] Based on the obtained sampling frequency, update the prescaler parameter configuration.

[0022] Preferably, the sampling frequency is five times the frequency of the input signal, and the prescaler parameters configured in the timer structure are set accordingly. The sampling frequency is switched to perform normal capture and counting. A judgment flag is set in the program so that the KDE algorithm is not executed after the sampling frequency is determined, and the input pulse signal is acquired at the sampling frequency.

[0023] A high-speed pulse signal acquisition system includes a high-speed acquisition module, which comprises a power supply module, a communication module, an MCU module, and an optocoupler isolation circuit. The MCU module internally incorporates the pulse signal frequency adaptive acquisition method based on the KDE algorithm as described in any one of claims 1-6. The optocoupler isolation circuit is connected to the MCU module. The power supply module is connected to both the MCU module and the communication module. The MCU module is connected to an interface module via the communication module, and the interface module is connected to a third-party PLC module. The input pulse signal is fed into the input interface of the optocoupler isolation circuit. Through the isolation protection and voltage conversion of the optocoupler isolation circuit, the output signal is fed into the MCU module. The KDE algorithm is used to analyze the signal frequency characteristics and adjust the sampling frequency to generate a counting result, thereby achieving high-speed acquisition and counting.

[0024] Preferably, the interface module is connected to the PLC module via PN communication. During the pulse signal acquisition process, the PLC module sends the reset, invert, and set period in the form of data to the interface module by mapping the address in the interface module. The interface module transmits the reset and invert signals to the MCU module to control the execution of the corresponding operations and uses the count value and the set period to calculate the pulse sampling rate.

[0025] Preferably, the high-speed acquisition module uses the advanced HEcat communication protocol as a slave device, and is deployed together with the digital and analog I / O modules after an interface module to form an integrated and scalable I / O subsystem. In the ring network communication mode, the interface module assembles an Ethernet frame and sends it to the subsequent extended I / O modules. The output module obtains data from the message, the input module fills the message with data, and the message passes through all slave stations in sequence before finally returning to the master station.

[0026] Preferably, the MCU module is a microcontroller based on a high-performance ARM Cortex-M4 core, and integrates 256KB Flash memory and 96KB SRAM;

[0027] The power module uses a synchronous buck converter to convert the input voltage into a 3.3V system power supply to provide power to the MCU module, communication module and various peripheral circuits;

[0028] The MCU module is connected to the indicator module via an optocoupler isolation circuit;

[0029] The communication module achieves data exchange with other I / O modules and interface modules through HEcat communication; the indicator module reflects the working status, power on / off status and communication link status of each channel in real time through the visualization element of multi-color LEDs.

[0030] Preferably, the optocoupler isolation circuit includes an optocoupler, the power supply pin of which is connected to the output terminal of the power module, and the two input channels of the optocoupler are each connected to a bridge structure; the two output terminals of the optocoupler are grounded through filter capacitors, and the TTL level signals obtained from the two output terminals of the optocoupler are connected to the MCU module. The optocoupler isolation circuit realizes electrical isolation and level conversion of pulse signals in the industrial field, ensuring that the input pulse signal can be safely and accurately captured by the MCU module after being converted to a 3.3V TTL level.

[0031] Preferably, the bridge structure includes a first diode unit and a second diode unit. The two output terminals of the first diode unit are respectively connected to the two ends of one input channel of the optocoupler. One output terminal of the second diode unit is connected to one end of one input channel of the optocoupler through a resistor R300, and the other output terminal of the second diode unit is connected to the other end of one input channel of the optocoupler. A capacitor C304 is connected between the two ends of one input channel of the optocoupler. The input terminals of the first diode unit are respectively connected to the input signal interfaces DIX0 and COM0. The input terminals of the second diode unit are connected to the input signal interfaces DIX0 and COM0 through current-limiting resistors. The bridge structure maintains the input signal as a positive signal.

[0032] Preferably, the transmission delay and bandwidth determine the acquisition frequency of the optocoupler, while the isolation voltage and current transfer ratio determine the performance of the optocoupler. Key parameters: (1) Bandwidth ≥ 2 × highest signal frequency; (2) Transmission delay ≤ 10% of signal period; (3) Isolation voltage ≥ 1 kV. Ensure the electrical isolation function of the optocoupler.

[0033] Compared with existing technologies, the advantages of this invention are as follows: This invention combines the high-frequency signal acquisition capability of hardware circuitry with the adaptive sampling mechanism of the KDE algorithm, solving the problems of frequency aliasing, data redundancy, and missed sampling caused by the fixed sampling rate in high-frequency signal identification of traditional high-speed acquisition modules, and enabling real-time control of the high-speed acquisition module. Therefore, this invention can optimize the sampling strategy according to the frequency characteristics of the input pulse signal, achieve high-precision counting, and significantly improve the system's adaptability to different application scenarios, avoiding signal distortion or data loss caused by sampling rate mismatch. Attached Figure Description

[0034] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0035] Figure 1 This is a schematic diagram of the system of the present invention.

[0036] Figure 2 This is a flowchart of the method of the present invention.

[0037] Figure 3 This is a hardware schematic diagram of the high-speed acquisition module of the present invention.

[0038] Figure 4 This is a circuit diagram of the optocoupler isolation circuit of the present invention.

[0039] Figure 5 This is a diagram showing the effect of the KDE algorithm of this invention.

[0040] Figure 6 This is a flowchart of the peak index fast search algorithm of the present invention. Detailed Implementation

[0041] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0042] Example 1

[0043] like Figure 1 As shown, this embodiment provides a high-speed pulse signal acquisition system that can adaptively adjust the sampling frequency and accurately count signals. It uses the KDE algorithm to achieve adaptive acquisition of pulse signal frequency, thereby solving the problems of difficulty in identifying high-frequency signals and frequency aliasing caused by fixed sampling rates.

[0044] like Figure 3 As shown, the high-speed pulse signal acquisition system of this invention includes a high-speed acquisition module, which consists of a power supply module, a communication module, an MCU module, and an optocoupler isolation circuit. The MCU module's internal software design is based on a pulse signal frequency adaptive acquisition method using the KDE algorithm. The power supply module is connected to both the MCU module and the communication module, converting the input voltage to +3.3V to provide a stable power supply for the hardware circuit. The MCU module is connected to the interface module via the communication module, enabling data interaction between the MCU module and the interface module. The MCU module is the control core of the product (high-speed acquisition counting), such as... Figure 1 As shown, the interface module serves as a bridge for communication and data exchange between itself and third-party PLC modules. The optocoupler isolation circuit connects to the MCU module, capturing input pulse signals and cooperating with the MCU module to perform signal preprocessing. The input pulse signal is input to the optocoupler isolation circuit's input interface, and through the circuit's isolation protection and voltage conversion, the output signal is input to the MCU module. The high-speed acquisition module analyzes the signal frequency characteristics using the KDE algorithm and adjusts the sampling frequency to generate counting results, thus realizing a high-speed acquisition and counting module.

[0045] The interface module connects to the PLC module via PN communication. The physical connection for PN communication is based on standard industrial Ethernet (usually using a network cable), but its communication mechanism is implemented using the PROFINET protocol stack. The PROFINET protocol, in addition to the standard TCP / IP channel, establishes an independent real-time data channel, ensuring reliable transmission of I / O data within a specified time through periodic data exchange and precise clock synchronization. The logical relationships between devices need to be configured using engineering software to take effect. During pulse signal acquisition, the third-party PLC module can reset, invert, and calculate the pulse sampling rate within a set period in real time. The third-party PLC module sends the reset, inversion, and set period as data to the interface module by mapping the address in the interface module. The interface module controls the high-speed acquisition module to perform corresponding operations based on the reset and inversion signals, and uses the count value of the high-speed acquisition module and the set period to calculate the pulse sampling rate. Figure 1 The DI, DQ, AI, and AQ modules are digital input, digital output, analog input, and analog output modules, respectively. Like the high-speed acquisition module, they are all independent products with their own MCU and communication modules, supporting plug-and-play combination, and their functions do not interfere with each other. The high-speed acquisition module connects with the DI, DQ, AI, and AQ modules via HECAT communication to achieve data transmission between the modules.

[0046] This invention designs a high-speed data acquisition module primarily for demanding industrial field control and measurement scenarios. At the system integration level, the high-speed acquisition module employs the advanced HEcat communication protocol, enabling it to function as a slave device. It can be deployed alongside conventional digital and analog I / O modules within an interface module, forming an integrated and scalable I / O subsystem. In this architecture, the interface module acts as the master station, its core function being to integrate and schedule data from all backend I / O modules and encapsulate it uniformly. Using a ring network communication mode, the interface module assembles an Ethernet frame and sends it to the subsequent extended I / O modules. Output modules retrieve data from the message, input modules fill the message with data, and the message sequentially passes through all slave stations before finally returning to the master station. The integrated data communicates in real-time and deterministically with the upper-level third-party PLC module via the widely adopted PROFINET (PN) industrial Ethernet protocol, thus realizing a complete data link from field acquisition to system integration.

[0047] like Figure 3As shown, in the hardware system of this invention, the MCU module uses the GigaDevice GD32F307RCT6 microcontroller as the core processing unit. This chip is based on a high-performance ARM Cortex-M4 core, with a maximum operating frequency of 120MHz, and integrates 256KB Flash memory and 96KB SRAM. Its excellent computing power and storage resources provide a reliable hardware foundation for the real-time acquisition and processing of high-speed pulse signals. The power supply module uses an LMR51420XDDCR synchronous buck converter, which can efficiently and stably convert the input voltage to a 3.3V system power supply, providing a clean and reliable power supply for the MCU module, communication module, and various peripheral circuits. The high-speed acquisition and counting module is connected to the MCU module through an optocoupler isolation circuit, and the MCU module is connected to the indicator module through an optocoupler isolation circuit. The optocoupler isolation circuit realizes electrical isolation and level conversion of pulse signals in the industrial field, ensuring that the signal can be safely and accurately captured by the MCU module after being converted to a 3.3V TTL level.

[0048] For high-speed pulse acquisition, the system uses LTV-063L optocouplers to construct optocoupler isolation circuits, achieving electrical isolation and level conversion of pulse signals in the industrial field (electrical isolation is achieved through light as a medium, and level conversion can be completed in conjunction with external circuits), ensuring that the signal can be safely and accurately captured by the MCU module after being converted to 3.3V TTL level. The communication module is responsible for data exchange between this system and other I / O modules and interface modules, ensuring high-speed and reliable transmission of commands and acquired data through HECAT communication. The indicator module uses multi-color LEDs and other visual elements to reflect the working status of each channel, power connection status, and communication link status in real time, providing an intuitive human-machine interface for on-site debugging and operation monitoring of the system.

[0049] This invention's high-speed acquisition module is primarily used for industrial field control. It converts input ±24V high-speed digital signals into a 3.3V level signal acceptable to conventional MCU modules. An input ±24V external signal activates the optocoupler, and pins 5 and 8 of the optocoupler provide 3.3V, which determines the output signal voltage. The product is designed for multiple channels. Figure 4This is a part of a larger system containing two input channels; only one channel will be used as an example here. The optocoupler isolation circuit includes an optocoupler whose power supply pin is connected to the output of the power module. The two input channels of the optocoupler are each connected to a bridge structure, which maintains a positive input signal. The bridge structure includes a first diode unit and a second diode unit. The two outputs of the first diode unit are connected to the two ends of one input channel of the optocoupler. One output of the second diode unit is connected to one end of one input channel of the optocoupler via resistor R300, and the other output is connected to the other end of one input channel of the optocoupler. A capacitor C304 is connected between the two ends of one input channel of the optocoupler. The capacitor C304 and resistor R300 serve the functions of filtering and current limiting, respectively. The first and second diode units form a bridge circuit that can accept ±24V input signals. The input terminals of the first diode unit are connected to the input signal interfaces DIX0 and COM0, respectively. The input terminal of the second diode unit is connected to the input signal interfaces DIX0 and COM0 through a current-limiting resistor. The purpose of interfaces DIX0 and COM0 is to form a loop. The two output terminals of the optocoupler are grounded through filter capacitors, and the two output terminals of the optocoupler receive TTL level signals and are connected to the MCU module. The optocoupler achieves electrical isolation through light as a medium.

[0050] This channel uses a high-speed optocoupler (U302) as its core, along with a current-limiting resistor (RI300) to form the input stage, ensuring reliable conduction of the optocoupler under ±24V input signals (interfaces are DIX0 and COM0). The input terminal adopts a bridge structure composed of D300 and D302, enabling the circuit to respond to both positive and negative switching signals simultaneously, achieving bidirectional pulse acquisition. When a ±24V pulse signal is received, the input terminals (pins 1 and 2) of the high-speed optocoupler U302 are turned on, allowing its output side to operate under a 3.3V power supply. After the optocoupler is turned on, pin 7 of the optocoupler U302 outputs a 3.3V level signal. This signal is sent to the GPIO pin with timer multiplexing function of the MCU module via the DIX0 port for processing, completing one valid count.

[0051] In the high-speed pulse signal acquisition system of this invention, the inherent defects of traditional fixed sampling rates are solved by the coordinated operation of the high-frequency signal acquisition capability of the hardware circuit and the adaptive adjustment mechanism of the software algorithm. In the software design, the kernel density estimation (KDE) algorithm is used to model the frequency distribution of the input pulse signal, adaptively matching signal characteristics to adjust the sampling interval, avoiding frequency aliasing, and reducing data redundancy or missed sampling. The PLC module can communicate with the high-speed acquisition module to invert and reset the counter, and set a time according to user requirements to calculate the pulse change rate. The third-party PLC module sends the reset, inversion, and set period as data to the interface module through the address mapped in the interface module. The interface module controls the high-speed acquisition module to perform corresponding operations based on the reset and inversion signals, and uses the high-speed acquisition module's count value and the set period to calculate the pulse sampling rate. The hardware circuit uses a high-speed optocoupler combined with signal conditioning peripheral circuits to design the acquisition circuit, achieving isolation protection against high input signal voltages and ensuring stable acquisition of high-frequency signals.

[0052] Therefore, according to the present invention, the high-frequency signal acquisition accuracy and reliability can be significantly improved by suppressing high-frequency signals through an adaptive sampling frequency adjustment mechanism, and the functions of related operations of the acquisition module can be realized.

[0053] Design a hardware circuit based on power supply, communication, MCU, and high-speed acquisition and counting, and design a lightweight signal acquisition and counting software to effectively reduce system power consumption and computational load. Implement pulse sampling, counting, clearing, inversion, and pulse rate calculation with set period on a low-cost conventional MCU.

[0054] like Figure 2 As shown, the complete acquisition process of high-speed pulse signals in the system of this invention is built on a collaborative architecture that combines "hardware signal acquisition" and "software data processing". The hardware layer is responsible for the physical conversion and electrical isolation of the signal, ensuring high-fidelity capture of the original signal; the software layer analyzes and counts the digitized signal through algorithms.

[0055] The function of an optocoupler is to isolate input signals and protect the MCU module from high voltage or noise. Several parameters need to be considered when selecting a suitable optocoupler: transmission delay, bandwidth, isolation voltage, and current transfer ratio (CTR).

[0056] For high-frequency signals, the optocoupler needs a sufficiently high bandwidth. Insufficient bandwidth will cause signal edges to become slow, potentially failing to capture high-frequency changes correctly. Generally, the bandwidth of the optocoupler should be at least twice the highest frequency of the signal (satisfying the Nyquist sampling theorem), i.e.:

[0057] ;

[0058] However, in practical applications, higher bandwidth may be required to ensure signal integrity.

[0059] The choice of optocoupler needs to be determined based on the rise time and maximum frequency of the signal. For example, if the rise time of the signal is t... r Then the highest frequency of the signal The formula is:

[0060] ;

[0061] For example, if the signal rise time is 100 ns, then the highest frequency component is 3.5 MHz.

[0062] Transmission delay is also a critical parameter. Excessive transmission delay in the optocoupler can cause a significant time shift in the signal after passing through it, affecting sampling accuracy. For a 5kHz signal, the transmission delay should be much smaller than the signal period (200 microseconds).

[0063] In this invention, the transmission delay and bandwidth determine the acquisition frequency of the optocoupler, while the isolation voltage and current transfer ratio determine the performance of the optocoupler. Key parameters: (1) Bandwidth ≥ 10 kHz (2 × signal frequency); (2) Transmission delay ≤ 10% of signal period (i.e. ≤ 20 μs); (3) Isolation voltage ≥ 1 kV (industrial grade requirement).

[0064] In the design and development of high-speed acquisition modules, accurately and systematically defining their basic information is crucial for ensuring module functionality, compatibility maintenance, and subsequent management and upgrades. The basic information definition includes setting parameters such as product number, number of channels, device name, and hardware version number. In specific implementation, the number of channels refers to the number of high-speed pulse counts the module can perform.

[0065] Example 2

[0066] like Figure 2 As shown, a pulse signal frequency adaptive acquisition method based on the KDE algorithm is described. Figure 2 As shown, in order for the product to automatically set an appropriate sampling rate, it is necessary to analyze the input signal frequency in the current application scenario. The KDE algorithm can intuitively reflect the central tendency and dispersion of the data. Based on the results of the KDE algorithm, the approximate range of the input signal frequency is obtained, and the product's sampling rate is adaptively set. At the same time, the data is analyzed to identify abnormal signal frequencies, and frequency thresholds are set to ensure data accuracy. The steps of this invention include:

[0067] Step 1: The external pulse signal is connected to the input interface of the optocoupler isolation circuit. Through the isolation protection and voltage conversion of the optocoupler isolation circuit, a TTL level signal is output and connected to the MCU module.

[0068] Step 2: Connect the TTL level signal obtained in Step 1 to the GPIO pin of the MCU module that has timer multiplexing function.

[0069] The general-purpose timer of the MCU module is selected, the GPIO pins are configured for multiplexing, and mapped to the timer input channels; the timer clock, prescaler (which determines the accuracy of signal edge capture), counting mode, and auto-reload value are set; the trigger edges, filtering, and mapping relationships of each input capture channel are configured; interrupts are configured, enabling edge-triggered interrupts, and after a rising edge signal is captured and an interrupt is triggered, the count is accumulated. The program configuration follows the standard operating steps for implementing the input capture function of the GD32 timer. Detailed steps are as follows:

[0070] 1. Clock and GPIO Pin Initialization: First, you need to enable the clock for TIMx and the corresponding GPIO pin. Configure the pin used for capture as a pull-down input.

[0071] 2. Timer base unit configuration: Configure and enable the TIMx prescaler (TIM_Prescaler) and auto-reload value (TIM_Period).

[0072] 3. Input capture channel configuration: This is achieved by configuring the TIM_ICInitTypeDef structure.

[0073] TIM_Channel: Select the channel (e.g., TIM_Channel_1). Multiple channels can be added here.

[0074] TIM_ICPolarity: Sets the capture edge (rising edge).

[0075] TIM_ICSelection: Usually, TIM_ICSelection_DirectTI (direct input) is selected.

[0076] TIM_ICFilter: Sets the filter parameters.

[0077] 4. Interrupt Configuration and Enabling: Enable capture-compare interrupts (e.g., TIM_IT_CC1). Configure NVIC and set interrupt priorities.

[0078] 5. Start the timer: Call TIM_Cmd(TIMx, ENABLE) to start the timer, and the counter will begin running.

[0079] Step 3: After the pulse rises to trigger, the timer interrupt function is entered. The current timer capture register value (CCRx) of two consecutive rising edges is captured, and the difference is calculated. This difference is then converted using the timer set frequency (timer frequency / timer capture register difference) to complete one frequency measurement. The frequency data is then stored in a predefined global variable array. This process is repeated to store a set of frequencies for subsequent data processing.

[0080] Step 4: Process the collected frequency data using the KDE algorithm to obtain the frequency distribution of the current pulse input signal.

[0081] Kernel density estimation (KDE) estimates the probability density function of a sample distribution based on the properties of the sample itself. Let f(x) and F(x) represent the probability density function and distribution function of the random variable X, respectively. From the population, n independent and identically distributed samples are randomly drawn: X1, X2, ..., X... i ,…X n The sample values ​​are x1, x2, ..., x i ,…,x n Then the kernel density estimate of the distribution density function at point x is:

[0082] ;

[0083] In the formula: n is the number of samples; h is the fixed bandwidth; K(·) is the kernel function, representing the distance from the data point x within the influence range x∈(Xh,X+h) to the center point X. i The relationship between the distance between them and the probability weights. This represents the value of the i-th sample.

[0084] As shown in the above equation, the kernel function K(·) and bandwidth h are important elements in kernel density estimation. Commonly used kernel functions include uniform kernels, Gaussian kernels, Epanechikov kernels, and triangular kernels. To reduce the computational complexity of the MCU module, decrease its resource consumption, and improve its overall performance and real-time response capability, algorithms with lower computational complexity are preferred. The triangular kernel is chosen for this study and can be expressed as follows:

[0085] ;

[0086] Silverman's rule of thumb is a common method in statistics, particularly in kernel density estimation, for automatically selecting bandwidth. Bandwidth is the most important parameter in kernel density estimation; it controls the width of the kernel function, thus determining the smoothness of the density curve. If the bandwidth is too small, the density curve will be too "rough," including too much detail caused by random noise (overfitting). If the bandwidth is too large, the density curve will be too "smooth," masking the true structure of the data (underfitting). The purpose of Silverman's rule is to provide a computationally simple and relatively reasonable initial bandwidth estimate.

[0087] For one-dimensional data, the Silverman rule suggests the following simplified calculation of bandwidth h:

[0088] ;

[0089] In the formula: h0 is the bandwidth to be calculated. Let be the standard deviation of the sample data. Let n be the number of sample data points. -1 / 5 This is a factor dependent on sample size; as the sample size increases, the optimal bandwidth decreases. To calculate a more robust initial bandwidth (using MAD instead of standard deviation):

[0090] ;

[0091] Here, mad(data) represents the absolute deviation of the median.

[0092] In practical applications, since the adaptability of a fixed bandwidth h is poor, a bandwidth adaptation factor λ is introduced. i Adaptive bandwidth h i The structure is as follows:

[0093] ;

[0094] In the formula: h0 is the global baseline bandwidth (calculated using rules such as the Silverman rule). λ i As a local adjustment factor, with respect to point x i The density at that location is inversely proportional:

[0095] ;

[0096] Where, f(x) i Let x be a point. i The initial density estimate at point (must be calculated first). g is the geometric mean of the initial density, and α is the sensitivity parameter, which is usually taken as 0.5.

[0097] The KDE algorithm employs a robust initial bandwidth calculation method based on median absolute deviation (MAD) and an adaptive bandwidth adjustment strategy. Specific implementation methods include:

[0098] Step 1: Obtain frequency data.

[0099] Step 2: Calculate the initial bandwidth. Use MAD instead of standard deviation to calculate the initial bandwidth. The Median Absolute Deviation (mad(data)) is calculated by first determining the median of the data, then calculating the absolute deviation of each data point from the median, and finally taking the median of these absolute deviations. Standard deviation is greatly affected by extreme values ​​(outliers); a large outlier can significantly increase the standard deviation. Mad is insensitive to outliers because it is based on the median (not the mean), and the median of absolute deviations is resistant to the effects of extreme deviations.

[0100] Step 3: Calculate the initial density. The initial density estimation stage uses the kernel function K(·) of the triangular kernel to calculate the initial density f0 for each data point. Compared to the Gaussian kernel (which requires exponential operations) or the Epanechnikov kernel (which requires squaring operations), the triangular kernel only involves absolute value and linear operations, making it more computationally efficient. In the initial density estimation stage, only a coarse but reasonable density estimate may be needed to guide subsequent steps (such as adaptive bandwidth selection or clustering), so a kernel with optimal smoothness is not necessarily required.

[0101] Step 4: Calculate the adaptive bandwidth. The local adjustment factor λ is obtained by calculating the density geometric mean g and adjusting the parameter α (default 0.5). i This leads to the generation of adaptive bandwidth h. i .

[0102] Step 5: Final Density Estimation. In the final density estimation stage, for each query point (i.e., the sampling point, which is the index value of the frequency storage array), only its adaptive bandwidth h is considered. i Neighboring data points within the range are assigned their respective adaptive bandwidths h. i Weighted calculations are performed to obtain the final probability density estimate.

[0103] This design effectively balances the estimation accuracy of different density regions through local bandwidth adjustment, and the execution effect is as follows: Figure 5 As shown. Figure 5 The following figure shows the input frequency array of the external pulse signal (obtained in step three), which is obtained after the KDE algorithm. Figure 5 The data in the above figure, through Figure 5 It can be seen that the frequency of the input pulse is mainly distributed around 600Hz, while the frequency of external interference is distributed above 2500Hz.

[0104] Step 5: Use the peak index fast search algorithm to determine the sampling frequency and frequency threshold, and capture the signal based on the sampling frequency.

[0105] The results obtained from the KDE algorithm are processed and analyzed to obtain the required data information. The algorithm flow of the peak index fast search algorithm is as follows: Figure 6 As shown, the obtained probability density estimation results are smoothed and filtered to determine the maximum value and record the corresponding index. Smoothing removes glitch data and allows subsequent algorithms to more quickly locate the required index position. Starting from the position corresponding to the index, the algorithm scans backward until the current value is greater than the value corresponding to the index, initially determining the current value as the peak value and recording the peak index. The algorithm continues scanning backward from the peak index until the current value is less than the peak value corresponding to the peak index, determining the current value as the second peak and recording the corresponding index. The index value corresponding to the maximum value is the frequency of the input signal, which is then multiplied to determine the sampling frequency. The index value corresponding to the second peak is the minimum interference frequency, and the starting index value of this wave is used as the frequency threshold. The peak index fast search algorithm can quickly determine the sampling frequency of the input signal (the index value corresponding to the maximum value) and the frequency threshold (the index value corresponding to the starting point of the second wave). Based on the obtained data, the prescaler parameter configuration is updated. The input pulse frequency is obtained according to the peak index fast search algorithm, and this frequency is multiplied by 5 as the sampling frequency of the product, correspondingly setting the prescaler parameters in the timer structure configuration. Then, a sampling frequency suitable for the current application scenario is switched for normal capture and counting. In the program, a judgment flag is set so that the KDE algorithm is not executed after the sampling frequency of the product is determined, and the signal of the input pulse is acquired at the current frequency.

[0106] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A pulse signal frequency adaptive acquisition method based on the KDE algorithm, characterized in that: Includes the following steps: Step 1: Isolate and protect the external pulse signal and convert its voltage to obtain a TTL level signal; Step 2: Connect the TTL level signal to the GPIO pin with timer multiplexing function of the MCU module to count pulses; Step 3: After the rising edge of the TTL level signal pulse triggers, the timer interrupt function is entered, the current timer capture register value of two consecutive rising edges is captured, the difference is calculated, and the frequency measurement is completed by converting the difference with the timer set frequency. The frequency data is then stored in the global variable array. This process is repeated to store a set of frequency data; Step 4: Process the acquired frequency data using the KDE algorithm to obtain the frequency distribution of the current pulse input signal; Step 5: Use the peak index fast search algorithm to determine the sampling frequency and frequency threshold, and capture the signal based on the sampling frequency.

2. The pulse signal frequency adaptive acquisition method based on the KDE algorithm according to claim 1, characterized in that: The GPIO pins of the selected MCU module's timer are configured for multiplexing and mapped to the timer input channel; Configure the timer's clock, prescaler, counting mode, and auto-reload value; configure the trigger edge, filtering, and mapping relationship for each input capture channel; configure interrupts, enable edge-triggered interrupts, and perform count accumulation after capturing a rising edge signal and entering the interrupt.

3. The pulse signal frequency adaptive acquisition method based on the KDE algorithm according to claim 1 or 2, characterized in that: The method for processing the acquired frequency data using the KDE algorithm in step four is as follows: Step S1: Calculate the initial bandwidth using the median absolute deviation instead of the standard deviation; Step S2: In the initial density estimation stage, the kernel function K(·) of the triangular kernel is used to calculate the initial density f0 of the data points of each frequency data data; Step S3: Calculate the density geometric mean g and combine it with the adjustment sensitivity parameter α to obtain the local adjustment factor λ. i This leads to the generation of adaptive bandwidth h. i ; Step S4: For each sampling point corresponding to an index value in the global variable array, only consider the neighborhood data points within the adaptive bandwidth range, and use their respective adaptive bandwidth h. i Weighted calculations are performed to obtain the final probability density estimate.

4. The pulse signal frequency adaptive acquisition method based on the KDE algorithm according to claim 3, characterized in that: The initial bandwidth Where mad(data) is the median absolute deviation of the frequency data data; n is the number of sampling points for the frequency data; The local adjustment factor λ i for ; The adaptive bandwidth h i for .

5. The pulse signal frequency adaptive acquisition method based on the KDE algorithm according to claim 1 or 4, characterized in that: The method for determining the sampling frequency and frequency threshold using the peak index fast search algorithm is as follows: The obtained probability density estimation result data is smoothed and filtered to determine the maximum value and record the corresponding index; scanning backwards from the position corresponding to the index until the current value is greater than the value corresponding to the index, initially determining the current value as the peak value and recording the peak index; continuing to scan backwards from the peak index until the current value is less than the peak value corresponding to the peak index, determining the current value as the second peak value and recording the corresponding index; the index value corresponding to the maximum value is the frequency of the input signal, and the sampling frequency is determined by frequency multiplication; the value of the index corresponding to the second peak value is the minimum interference frequency, and the starting index value of the second peak value is used as the frequency threshold; Based on the obtained sampling frequency, update the prescaler parameter configuration.

6. The pulse signal frequency adaptive acquisition method based on the KDE algorithm according to claim 5, characterized in that: The sampling frequency is obtained by multiplying the frequency of the input signal by 5. The prescaler parameters configured in the timer structure are set accordingly, and the sampling frequency is switched to perform normal capture and counting. A judgment flag is set in the program so that the KDE algorithm is not executed after the sampling frequency is determined, and the input pulse signal is acquired at the sampling frequency.

7. A high-speed pulse signal acquisition system, characterized in that: The system includes a high-speed acquisition module, which comprises a power supply module, a communication module, an MCU module, and an optocoupler isolation circuit. The MCU module internally incorporates the pulse signal frequency adaptive acquisition method based on the KDE algorithm as described in any one of claims 1-6. The optocoupler isolation circuit is connected to the MCU module. The power supply module is connected to both the MCU module and the communication module. The MCU module is connected to an interface module via the communication module, and the interface module is connected to a third-party PLC module. The input pulse signal is fed into the input interface of the optocoupler isolation circuit. Through the isolation protection and voltage conversion of the optocoupler isolation circuit, the output signal is fed into the MCU module. The KDE algorithm is used to analyze the signal frequency characteristics and adjust the sampling frequency to generate counting results, thus achieving high-speed acquisition and counting.

8. The high-speed pulse signal acquisition system according to claim 7, characterized in that: The interface module is connected to the PLC module via PN communication. During the pulse signal acquisition process, the PLC module sends the reset, invert, and set period in the form of data to the interface module by mapping the address in the interface module. The interface module transmits the reset and invert signals to the MCU module to control the execution of the corresponding operations and uses the count value and the set period to calculate the pulse sampling rate.

9. The high-speed pulse signal acquisition system according to claim 8, characterized in that: The high-speed acquisition module uses the advanced HEcat communication protocol as a slave device. It is deployed together with digital and analog I / O modules on an interface module to form an integrated and scalable I / O subsystem. In ring network communication mode, the interface module assembles an Ethernet frame and sends it to the subsequent extended I / O modules. The output module obtains data from the message, the input module fills the message with data, and the message passes through all slave stations in sequence before finally returning to the master station.

10. The high-speed pulse signal acquisition system according to claim 8 or 9, characterized in that: The MCU module is a microcontroller based on a high-performance ARM Cortex-M4 core, and integrates 256KB Flash memory and 96KB SRAM; The power module uses a synchronous buck converter to convert the input voltage into a 3.3V system power supply to provide power to the MCU module, communication module and various peripheral circuits; The MCU module is connected to the indicator module via an optocoupler isolation circuit; The communication module achieves data exchange with other I / O modules and interface modules through HEcat communication; the indicator module reflects the working status, power on / off status and communication link status of each channel in real time through the visualization element of multi-color LEDs.

11. The high-speed pulse signal acquisition system according to claim 7, characterized in that: The optocoupler isolation circuit includes an optocoupler, the power supply pin of which is connected to the output of the power module, and the two input channels of the optocoupler are connected to a bridge structure respectively; the two outputs of the optocoupler are grounded through filter capacitors, and the TTL level signals obtained from the two outputs of the optocoupler are connected to the MCU module respectively.

12. The high-speed pulse signal acquisition system according to claim 11, characterized in that: The bridge structure includes a first diode unit and a second diode unit. The two output terminals of the first diode unit are respectively connected to the two ends of one input channel of the optocoupler. One output terminal of the second diode unit is connected to one end of one input channel of the optocoupler through a resistor R300, and the other output terminal of the second diode unit is connected to the other end of one input channel of the optocoupler. A capacitor C304 is connected between the two ends of one input channel of the optocoupler. The input terminal of the first diode unit is connected to the input signal interface DIX0 and interface COM0 respectively. The input terminal of the second diode unit is connected to the input signal interface DIX0 and interface COM0 through a current-limiting resistor.

13. The high-speed pulse signal acquisition system according to claim 11 or 12, characterized in that: Transmission delay and bandwidth determine the acquisition frequency of the optocoupler, while isolation voltage and current transfer ratio determine its performance. Key parameters: bandwidth ≥ 2 × highest signal frequency; transmission delay ≤ 10% of signal period; Isolation voltage ≥ 1 kV.

Citation Information

Patent Citations

  • A method for clustering millimeter-wave radar point cloud targets based on KDE-DBSCAN

    CN115047424B