Getting back to time domain ifft

I am trying to filter random data in the frequency domain, and then converting the data back to the time domain, however when I use the following code, I am getting the output of ifft still as imaginary numbers. Any insight would be greatly appreciated.
srate=500;
time=500;
numdatapoints=srate*time;
x=rand(1,numdatapoints);
avgx=mean(x);
x=x-avgx;
Y=fft(x);
fftphase=angle(Y);
fftmag=abs(Y);
k=linspace(1, 250, numdatapoints);
j=1./k;
%filter to follow 1/f
for i=1:length(Y)
fftmag(i)=fftmag(i)*j(i);
end
z=fftmag.*exp(1i.*(fftphase));
y=ifft(z);

Réponses (1)

Wayne King
Wayne King le 8 Mar 2013
Modifié(e) : Wayne King le 8 Mar 2013

0 votes

The problem is you are violating the conjugate symmetry property of a real-valued signal.
You are scaling the magnitude of the Fourier coefficient at K and N-K+2 differently. Those coefficients should just be complex conjugates of each other which means they should NOT differ in magnitude.
Like this:
x = randn(8,1);
xdft = fft(x);
xdft(2)
xdft(8-2+2)
So if you want to scale by 1/K you have to scale both K and N-K+2 by 1/K and not the latter by 1/(N-K+2)

1 commentaire

James
James le 9 Mar 2013
Modifié(e) : James le 9 Mar 2013
So I changed
for i=1:length(Y)
fftmag(i)=fftmag(i)*j(i);
end
to
k=linspace(1, 250, numdatapoints);
for i=2:length(ffterp)
l=k(i);
ffterpmag(i)=ffterpmag(i)*(1/l);
ffterpmag(numdatapoints-i+2)=ffterpmag(numdatapoints-i+2)*(1/l);
end
It did make ifft values to be real, but this is just going to make the first and last datapoints and everything across the mean to be scaled the same way, so that it will fit more of a parabola shape, rather than a geometric distribution. I probably misinterpreted what you initially meant, any help would be greatly appreciated.

Connectez-vous pour commenter.

Question posée :

le 8 Mar 2013

Community Treasure Hunt

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

Start Hunting!

Translated by