Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
organized scrambling of matrix

Subject: organized scrambling of matrix

From: Juliette Salexa

Date: 19 Apr, 2010 09:18:06

Message: 1 of 5

Hi all,
I was wondering if there's a cleaner way to get:

K=vertcat(kron(U,conj(U)),
              kron(flipud(U),conj(U)),
              kron(U,flipud(conj(U))),
              kron(flipud(U),flipud(conj(U))));

where U is a column vector.

Of course, I could save conj(U)=A, and flipud(U)=B, and flipud(conj(U))=C,

but it would still involve 4 kroneker products, even though it looks like there's a lot of symmetry and repetition in the command.

It would be neat to see if there's a clean alternative,
Cheers!

Subject: organized scrambling of matrix

From: Roger Stafford

Date: 19 Apr, 2010 10:34:06

Message: 2 of 5

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <hqh74e$2ml$1@fred.mathworks.com>...
> Hi all,
> I was wondering if there's a cleaner way to get:
>
> K=vertcat(kron(U,conj(U)),
> kron(flipud(U),conj(U)),
> kron(U,flipud(conj(U))),
> kron(flipud(U),flipud(conj(U))));
>
> where U is a column vector.
>
> Of course, I could save conj(U)=A, and flipud(U)=B, and flipud(conj(U))=C,
>
> but it would still involve 4 kroneker products, even though it looks like there's a lot of symmetry and repetition in the command.
>
> It would be neat to see if there's a clean alternative,
> Cheers!
----------
  Yes, it does seem a shame to do four times as many multiplications as are really necessary. Try this:

 K = kron(U,conj(U)); % First block
 K = vertcat(K,reshape(flipud(reshape(K,[],length(U))),[],1)); % Add 2nd block
 K = vertcat(K,flipud(K)); % Add 3rd & 4th blocks

I don't know that this could be considered "cleaner", but it does have only one 'kron' operation. The last step by itself would probably save some execution time but I am not sure of the middle step with its two reshapes.

Roger Stafford

Subject: organized scrambling of matrix

From: Bruno Luong

Date: 19 Apr, 2010 11:12:05

Message: 3 of 5

I would avoid calling kronecker altogether:

n=1000;
U=rand(n,1)+1i*(rand(n,1));

tic
V1=conj(U*U');
V3=flipud(V1);
V2=conj(V3).';
V4=fliplr(V3);
K=[V1(:); V2(:); V3(:); V4(:)];
toc; % Elapsed time is 0.143288 seconds.

tic
K=vertcat(kron(U,conj(U)), ...
    kron(flipud(U),conj(U)), ...
    kron(U,flipud(conj(U))), ...
    kron(flipud(U),flipud(conj(U))));
toc % Elapsed time is 0.376012 seconds.


% Bruno

Subject: organized scrambling of matrix

From: Bruno Luong

Date: 19 Apr, 2010 11:22:05

Message: 4 of 5

Slightly improved:

n=1000;
U=rand(n,1)+1i*(rand(n,1));

tic
V1=conj(U)*U.';
V3=flipud(V1);
V2=V3';
V4=fliplr(V3);
K=[V1(:); V2(:); V3(:); V4(:)];
toc; % 0.125384 seconds

% Bruno

Subject: organized scrambling of matrix

From: Juliette Salexa

Date: 22 Apr, 2010 14:29:20

Message: 5 of 5

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hqhect$m1$1@fred.mathworks.com>...


These are excellent alternatives, thank you very much both Bruno and Roger!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us