Generating Toeplitz Matrix which Matches the Convolution Shape Same
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Royi Avital
le 11 Jan 2020
Réponse apportée : Chris Turnes
le 20 Nov 2025
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 commentaires
Steven Lord
le 13 Jan 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.]
Réponse acceptée
Matt J
le 14 Jan 2020
Modifié(e) : Matt J
le 14 Jan 2020
I am specifically asking about using the function toeplitz().
If it must be with toeplitz, then:
nH=numel(vH);
nX=numel(vX);
ic=ceil( (nH+1)/2);
kC=vH(ic:end);
kR=vH(ic:-1:1);
[vC,vR]=deal(sparse(1,nX));
vC(1:length(kC))=kC;
vR(1:length(kR))=kR;
1 commentaire
Matt J
le 14 Jan 2020
Modifié(e) : Matt J
le 14 Jan 2020
vH=1:12;
vX=rand(1,6000);
nH=numel(vH);
nX=numel(vX);
ic=ceil( (nH+1)/2);
kC=vH(ic:end);
kR=vH(ic:-1:1);
vC=sparse(1,1:numel(kC),kC,1,nX);
vR=sparse(1,1:numel(kR),kR,1,nX);
tic;
mH1=toeplitz(vC,vR);
toc; %Elapsed time is 0.652667 seconds.
tic;
nH=numel(vH);
nX=numel(vX);
ic=ceil( (nH+1)/2);
mH2 = interpMatrix(vH,ic , nX,1);
toc; %Elapsed time is 0.004266 seconds.
>> isequal(mH1,mH2)
ans =
logical
1
Plus de réponses (3)
Chris Turnes
le 20 Nov 2025
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
0 commentaires
Voir également
Catégories
En savoir plus sur Digital Filter Analysis dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!