Created
September 19, 2025 13:57
-
-
Save kumanna/e41523311d7680149b2f1f219caef28e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| M = 8 | |
| N = 8 | |
| T = 1 | |
| Delta_F = 1 | |
| triplets = [(1, 0, 0), (0.5, 1 * T / M, 0.4 * Delta_F / N)] | |
| H_tilde = np.zeros((M * N, M * N), dtype='complex') | |
| for k_ in range(N): | |
| for l_ in range(M): | |
| for k in range(N): | |
| for l in range(M): | |
| i1, i2 = k_ * M + l_, k * M + l | |
| for i in triplets: | |
| hi, tau_i, nu_i = i | |
| sinc1_val = (k_ / N - k / N - nu_i / Delta_F) | |
| sinc2_val = (l_ / M - l / M - tau_i / T) | |
| H_tilde[i1, i2] += hi * np.exp(1j * 2 * np.pi * nu_i / Delta_F * (l_ / M - tau_i / T)) \ | |
| * np.exp(-1j * np.pi * (N - 1) * (k_ / N - k / N - nu_i / Delta_F)) \ | |
| * np.exp(1j * 2 * np.pi * (k_ / N - nu_i / Delta_F) * (l_ / M - tau_i / T - l / M)) \ | |
| * np.exp(-1j * 2 * np.pi * np.floor(k_ / N - nu_i / Delta_F) * (l_ / M - tau_i / T - l / M)) \ | |
| * np.exp(1j * np.pi * (M - 1) * (l_ / M - tau_i / T - l / M)) \ | |
| * M * N \ | |
| * np.sinc(sinc1_val * N) / np.sinc(sinc1_val) \ | |
| * np.sinc(sinc2_val * M) / np.sinc(sinc2_val) | |
| #print((k_, l_, k, l), (i1, i2, np.abs(H_tilde[i1, i2]))) | |
| #plt.imshow(np.abs(H_tilde)) | |
| plt.imsave("out.pdf", np.abs(H_tilde)) | |
| #plt.show() | |
| import numpy as np | |
| import numpy as np | |
| def is_block_toeplitz(matrix, block_size, rtol=1e-05, atol=1e-08): | |
| """ | |
| Checks if a matrix is block Toeplitz for a given block size, with tolerance. | |
| Args: | |
| matrix (np.ndarray): The input matrix (must be 2D). | |
| block_size (tuple): A tuple (rows, cols) representing the size of the blocks. | |
| rtol (float): The relative tolerance parameter for floating-point comparison. | |
| atol (float): The absolute tolerance parameter for floating-point comparison. | |
| Returns: | |
| bool: True if the matrix is block Toeplitz within the specified tolerance, | |
| False otherwise. | |
| """ | |
| if not isinstance(matrix, np.ndarray) or matrix.ndim != 2: | |
| raise ValueError("Input 'matrix' must be a 2D NumPy array.") | |
| if not isinstance(block_size, tuple) or len(block_size) != 2: | |
| raise ValueError("Input 'block_size' must be a tuple of two integers.") | |
| block_rows, block_cols = block_size | |
| mat_rows, mat_cols = matrix.shape | |
| if mat_rows % block_rows != 0 or mat_cols % block_cols != 0: | |
| return False # Matrix dimensions aren't a multiple of the block size | |
| num_blocks_rows = mat_rows // block_rows | |
| num_blocks_cols = mat_cols // block_cols | |
| # Iterate through all blocks except the first row and column | |
| for i in range(1, num_blocks_rows): | |
| for j in range(1, num_blocks_cols): | |
| # Extract the current block | |
| current_block = matrix[i*block_rows : (i+1)*block_rows, | |
| j*block_cols : (j+1)*block_cols] | |
| # Extract the block diagonally above and to the left | |
| diagonal_block = matrix[(i-1)*block_rows : i*block_rows, | |
| (j-1)*block_cols : j*block_cols] | |
| # If the blocks are not "close," the matrix is not block Toeplitz | |
| if not np.allclose(current_block, diagonal_block, rtol=rtol, atol=atol): | |
| return False | |
| return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment