1
votes

I am using Matlab and I am trying to find the ifft of a symmetric function but I keep getting a complex result. I have tried using circshift but I can't seem to get it figured out. I was wondering if anyone could help? Here is the code:

t=0:0.001:0.119;

for i=1:120

comp1(i)=9.8*cos(2*pi*200*t(i));

comp2(i)=7.6*cos(2*pi*145*t(i)+30/57.3);

comp3(i)=5.4*cos(2*pi*93*t(i)+70/57.3);

comp4(i)=3.2*cos(2*pi*58*t(i)+160/57.3);

comp5(i)=cos(2*pi*35*t(i)+320/57.3);

YS=comp1+comp2+comp3+comp4+comp5;
end

Q=1000/(2*60)*[-59:1:60];

Box=[zeros(1,40),ones(1,5),zeros(1,30),ones(1,5),zeros(1,40)];

Box1=circshift(Box,[0,60]);

F=ifft(Box1);

Thanks in advance for any help!

1
what's the purpose of YS and Q in your example? they are not used in the expression for BoxItamar Katz
First of all, fft is padding your vector such that it is getting a length of 2^n. Then note that ifft([1,0,0,1]) does not output a real result.flawr
@flawr, Matlab's fft does not do zero-padding unless you tell it to.Itamar Katz
@ItamarKatz Oh right, sorry, for that.flawr

1 Answers

0
votes

(I am not sure what YS and Q in your code are for, so I just ignore them).

The transform X of a real signal x of length N has the property that

X(k) = X(N-k)*

for k=1,...,N-1, where * is complex conjugate. For a real transform (as in your example) you can just ignore the *. Note that the indexing goes from 0 to N-1, so for k=0 the above property is not defined, since the index of the last term is N-1 (there is no X(N)).

In your case the signal Box does not have this property, nor does Box1 (check it!). Try for example:

Box = [zeros(1,41),ones(1,5),zeros(1,29),ones(1,5),zeros(1,40)];

This signal does have this property, and its ifft is indeed real.