Clear Filters
Clear Filters

rearrange the G matrix

2 views (last 30 days)
Dhafer
Dhafer on 13 Aug 2012
Dear
I plot each point in freq. domain and I did ifft.
f=0:1/1024:1;
t=0:1/1024:1;
a=10;
for i=1:1025
if f(i)>=25/1024 && f(i)<=100/1024
v(i)=a;
else
v(i)=0;
end
end
figure;
plot(f,v);
for i=1:1025
G(i)=0;
for j=1:1025
G(i)=v(j).*cos(i*j*2*pi/1025)+G(i);
end
end
figure;
plot(t,G)
Now I would like to rearrange the G matrix so that the last half of points are put as the first half and the first half as the last half (i.e. the biggest point is now in the middle.
regards
Dhafer

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 13 Aug 2012
add this code
n=floor(size(G,2)/2)
if n==size(G,2)/2
out(1:n)=G(n+1:end);out(n+1:2*n)=G(1:n)
else
out(1:n)=G(n+2:end);
out(n+1:2*n+1)=G(1:n+1);
end
figure;plot(t,out)
Note: in your case length(G)=1025 is odd, i added a test when it's even

More Answers (2)

Walter Roberson
Walter Roberson on 13 Aug 2012
fftshift() ?

Andrei Bobrov
Andrei Bobrov on 13 Aug 2012
n = numel(G);
k = floor(n/2);
p = ceil(n/2)+~rem(n,2);
G([1:k,p:end]) = G([p:end,1:k]);

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!