toeplitz2.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. %{
  2. Copyright © 2020 Alexey A. Shcherbakov. All rights reserved.
  3. This file is part of GratingFMM.
  4. GratingFMM is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. GratingFMM is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GratingFMM. If not, see <https://www.gnu.org/licenses/>.
  14. %}
  15. %% description:
  16. % return a 2D Toeplitz matrix (2D analog of the matlab function 'toeplitz')
  17. %% input:
  18. % M: vector of size (2*ny-1)*(2*nx-1)
  19. % nx, ny: block dimensions of Toeplitz matrix
  20. %% output:
  21. % T: 2D block-Toeplitz matrix of size nx*ny
  22. %% implementation:
  23. function [T] = toeplitz2(M, nx, ny)
  24. CT = cell(1,2*nx-1);
  25. ind = toeplitz(linspace(nx,2*nx-1,nx),flip(linspace(1,nx,nx)));
  26. for i = 1:2*nx-1
  27. CT{1,i} = toeplitz(M(ny:2*ny-1,i),M(ny:-1:1,i));
  28. end
  29. T = cell2mat(CT(ind));
  30. end
  31. %
  32. % end of function toeplitz2
  33. %