Generating Toeplitz Matrix which Matches the Convolution Shape Same

17 views (last 30 days)
Royi Avital
Royi Avital on 11 Jan 2020
Commented: Royi Avital on 21 Apr 2020
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 Comments
Royi Avital
Royi Avital on 14 Jan 2020
I just want to generate the matrix specifically with the toeplitz() function.
I acutally can create larger matrix (Matching the full option) and then take a subset of that. But I wonder if I miss something about generating it directly with toeplitz().

Sign in to comment.

Accepted Answer

Matt J
Matt J on 14 Jan 2020
Edited: Matt J on 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 Comment
Matt J
Matt J on 14 Jan 2020
But note that interpMatrix will be much, much faster than toeplitz for building a sparse mH:
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

Sign in to comment.

More Answers (2)

Matt J
Matt J on 13 Jan 2020
Edited: Matt J on 14 Jan 2020
Using interpMatrix (Download),
nH=numel(vH);
nX=numel(vX);
ic=ceil( (nH+1)/2);
mH = interpMatrix(vH,ic , nX,1);
  3 Comments

Sign in to comment.


Matt J
Matt J on 13 Jan 2020
Edited: Matt J on 13 Jan 2020
Using func2mat (Download),
mH=func2mat(@(vX) conv(vX, vH, 'same'), ones(length(vX),1));
  1 Comment
Royi Avital
Royi Avital on 14 Jan 2020
Hi Matt,
I can generate the matrix in other ways.
I am specifically asking about using the function toeplitz().

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by