Hướng dẫn correlation function python numpy
Tôi nghĩ rằng có 2 điều làm tăng thêm sự nhầm lẫn cho chủ đề này:
Tôi đã tạo 5 hàm tính toán tự động tương quan của một mảng 1d, với sự khác biệt một phần và không một phần. Một số sử dụng công thức từ thống kê, một số sử dụng tương quan theo nghĩa xử lý tín hiệu, cũng có thể được thực hiện thông qua FFT. Nhưng tất cả các kết quả đều là tương quan tự động trong định nghĩa thống kê , vì vậy chúng minh họa cách chúng được liên kết với nhau. Mã bên dưới:
Đây là con số đầu ra: Chúng ta không nhìn thấy tất cả 5 dòng vì 3 trong số chúng chồng lên nhau (ở màu tím). Các phần trùng lặp là tất cả
các tương quan tự động không từng phần. Điều này là do các tính toán từ các phương pháp xử lý tín hiệu ( Cũng lưu ý rằng 21 hữu ích 0 bình luận chia sẻ Có thể bạn quan tâmCross-correlation of two 1-dimensional sequences. This function computes the correlation as generally defined in signal processing texts: \[c_k = \sum_n a_{n+k} \cdot \overline{v_n}\] with a and v sequences being zero-padded where necessary and \(\overline x\) denoting complex conjugation. Parametersa, varray_likeInput sequences. mode{‘valid’, ‘same’, ‘full’}, optionalRefer to the old_behavior was removed in NumPy 1.10. If you need the old behavior, use multiarray.correlate. Discrete cross-correlation of a and v. See also convolve Discrete, linear convolution of two one-dimensional sequences. multiarray.correlate Old, no conjugate, version of correlate. scipy.signal.correlate uses FFT which has superior performance on large arrays. Notes The definition of correlation above is not unique and sometimes correlation may be defined differently. Another common definition is: \[c'_k = \sum_n a_{n} \cdot \overline{v_{n+k}}\] which is related to \(c_k\) by \(c'_k = c_{-k}\).
Examples >>> np.correlate([1, 2, 3], [0, 1, 0.5]) array([3.5]) >>> np.correlate([1, 2, 3], [0, 1, 0.5], "same") array([2. , 3.5, 3. ]) >>> np.correlate([1, 2, 3], [0, 1, 0.5], "full") array([0.5, 2. , 3.5, 3. , 0. ]) Using complex sequences: >>> np.correlate([1+1j, 2, 3-1j], [0, 1, 0.5j], 'full') array([ 0.5-0.5j, 1.0+0.j , 1.5-1.5j, 3.0-1.j , 0.0+0.j ]) Note that you get the time reversed, complex conjugated result (\(\overline{c_{-k}}\)) when the two input sequences a and v change places: >>> np.correlate([0, 1, 0.5j], [1+1j, 2, 3-1j], 'full') array([ 0.0+0.j , 3.0+1.j , 1.5+1.5j, 1.0+0.j , 0.5+0.5j]) |