rearrange the G matrix

1 次查看(过去 30 天)
Dhafer
Dhafer 2012-8-13
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

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2012-8-13
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

更多回答(2 个)

Walter Roberson
Walter Roberson 2012-8-13
fftshift() ?

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

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by