This application provides a device sensing method and apparatus, offering various Gray complement pairs (GCPs) of different lengths to increase GCP capacity and meet the needs of simultaneous sensing by multiple devices. The method includes: a sensing device transmitting a sensing
signal, receiving the
echo signal of the sensing
signal, and
processing the
echo signal. The sensing
signal is generated based on a GCP of length N, where N is greater than or equal to 32. When N equals 32, 64, 128, 256, 512, or 1024, the GCP can be generated by a generalized
Boolean function mapping. When N equals 160, 320, 640, or 832, the GCP is the direct product of a first GCP and a second GCP, where the length of the first GCP is N1, the length of the second GCP is N2, and N1 × N2 = N. The first GCP is generated through a generalized
Boolean function mapping; the second GCP is any of the following: x1 = 1, 1, -1, 1, -1, 1, -1, -1, 1, 1; y1 = 1, 1, -1, 1, 1, 1, 1, 1, -1, -1; or x2 = 1, 1, 1, 1, 1, -1, 1, -1, -1, 1; y2 = 1, 1, -1, -1, 1, 1, 1, -1, 1, -1, 1, -1.