Generating Toeplitz Matrix which Matches the Convolution Shape Same

조회 수: 6 (최근 30일)
Royi Avital
Royi Avital 2020년 1월 11일
댓글: Royi Avital 2020년 4월 21일
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
Steven Lord
Steven Lord 2020년 1월 13일
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
Royi Avital 2020년 1월 14일
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().

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2020년 1월 14일
편집: Matt J 2020년 1월 14일
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
Matt J
Matt J 2020년 1월 14일
편집: Matt J 2020년 1월 14일
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

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Matt J
Matt J 2020년 1월 13일
편집: Matt J 2020년 1월 14일
Using interpMatrix (Download),
nH=numel(vH);
nX=numel(vX);
ic=ceil( (nH+1)/2);
mH = interpMatrix(vH,ic , nX,1);
  댓글 수: 3

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2020년 1월 13일
편집: Matt J 2020년 1월 13일
Using func2mat (Download),
mH=func2mat(@(vX) conv(vX, vH, 'same'), ones(length(vX),1));
  댓글 수: 1
Royi Avital
Royi Avital 2020년 1월 14일
Hi Matt,
I can generate the matrix in other ways.
I am specifically asking about using the function toeplitz().

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by