Generating Toeplitz Matrix which Matches the Convolution Shape Same
Mostrar comentarios más antiguos
Given a filter vH I'm looking for vectors vR and vC such that:
toeplitz(vC, vR) * vX = conv(vX, vH, 'same');
For instance, for vH = [1, 2, 3, 4] and length(vX) = 7; the matrix is given by:
mH =
3 2 1 0 0 0 0
4 3 2 1 0 0 0
0 4 3 2 1 0 0
0 0 4 3 2 1 0
0 0 0 4 3 2 1
0 0 0 0 4 3 2
0 0 0 0 0 4 3
3 comentarios
Royi Avital
el 13 de En. de 2020
Steven Lord
el 13 de En. de 2020
The convmtx function from Signal Processing Toolbox comes close to doing what you want. I don't know offhand if there's a function in any MathWorks product that comes closer.
Is there a reason you don't want to simply call conv? [If you're expecting multiplying by the convolution matrix to be faster than calling conv, make sure you time the two operations using timeit to test if you're correct in your expectation.]
Royi Avital
el 14 de En. de 2020
Respuesta aceptada
Más respuestas (3)
I'm very late to this question, but this is what I'd do:
% Even-sized filter smaller than input:
[vC, vR] = get_toeplitz_vectors(7, 1:4)
% Odd-sized filter smaller than input:
[vC, vR] = get_toeplitz_vectors(7, 1:5)
% Even-sized filter bigger than input:
[vC, vR] = get_toeplitz_vectors(3, 1:4)
% Odd-sized filter bigger than input:
[vC, vR] = get_toeplitz_vectors(3, 1:5)
function [vC, vR] = get_toeplitz_vectors(n, vH)
vC = zeros(n,1);
vR = zeros(1,n);
nh = numel(vH);
f = 1 + floor(nh/2);
vC(1:(nh-f+1)) = vH(f:nh);
vR(1:f) = vH(f:-1:1);
end
nH=numel(vH);
nX=numel(vX);
ic=ceil( (nH+1)/2);
mH = interpMatrix(vH,ic , nX,1);
3 comentarios
Royi Avital
el 14 de En. de 2020
Royi Avital
el 21 de Abr. de 2020
Royi Avital
el 21 de Abr. de 2020
mH=func2mat(@(vX) conv(vX, vH, 'same'), ones(length(vX),1));
1 comentario
Royi Avital
el 14 de En. de 2020
Categorías
Más información sobre Digital Filter Analysis en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!