From: Peng Liang on
Hi experts,

I am using matlab to do the FFT convolution which take the fft of the signal and filter, multiply them in frequency domain. There is a problem. the ifft gives me complex numbers which is weird. since I multiplied the fft of the input signal with a filter kernel which is after fft. both data after fft are complex number. It should be turned back to real number after ifft. but I still get the complex numbers.

is my question clear? Please give me a hand.
thanks in advance.
From: TideMan on
On Jun 16, 8:04 am, "Peng Liang" <madokaauk...(a)hotmail.com> wrote:
> Hi experts,
>
> I am using matlab to do the FFT convolution which take the fft of the signal and filter, multiply them in frequency domain. There is a problem. the ifft gives me complex numbers which is weird. since I multiplied the fft of the input signal with a filter kernel which is after fft. both data after fft are complex number. It should be turned back to real number after ifft. but I still get the complex numbers.
>
> is my question clear? Please give me a hand.
> thanks in advance.

How large are the imaginary parts?
If they are very small, you can ignore them. They are the result of
floating point operations. Use real(y) to discard them.
If they are not negligible, then you have screwed up your processing
in the frequency domain. Without more detail of what you are doing,
we cannot tell what you have screwed up.
From: Peng Liang on
TideMan, thank you for your response and helps. You might know what is going wrong in my code.

I checked the imaginary part of data. they are sometimes very significant. I have my code below. Please let me know where I go wrong.

clear;

fs = 8000;
t = [0.000125:1/fs:1];
A_1 = 10;
A_2 = 4;

f_1 = 350;
s_1 = A_1*sin(2*pi*f_1*t); % generates a sine wave with 350Hz frequency

f_2 = 700;
s_2 = A_2*sin(2*pi*f_2*t); % generates a sine wave with 700Hz frequency

s_3 = s_1+s_2; % mixed 350 and 700Hz sine wave

S_3 = fft(s_3); % get dft data using fft algorithm, now the data is complex number


%% design a high pass filter which only have ones and zeros
filter = ones(size(S_1));
filter(1:500) = 0;
filter(7501:8000) = 0;

S3_f = S_3.*filter; % filter the low frequency in frequency domain.

s3_f = ifft(S3_f); % convert back to time domain using ifft, s3_f is time domian signal and gives significant imaginary part.

anyone has idea why my ifft generates very large imaginary part?
Need helps.

Thanks in advance.



TideMan <mulgor(a)gmail.com> wrote in message <d06620a7-8ec4-480d-9458-4d6c22f1e964(a)y18g2000prn.googlegroups.com>...
> On Jun 16, 8:04 am, "Peng Liang" <madokaauk...(a)hotmail.com> wrote:
> > Hi experts,
> >
> > I am using matlab to do the FFT convolution which take the fft of the signal and filter, multiply them in frequency domain. There is a problem. the ifft gives me complex numbers which is weird. since I multiplied the fft of the input signal with a filter kernel which is after fft. both data after fft are complex number. It should be turned back to real number after ifft. but I still get the complex numbers.
> >
> > is my question clear? Please give me a hand.
> > thanks in advance.
>
> How large are the imaginary parts?
> If they are very small, you can ignore them. They are the result of
> floating point operations. Use real(y) to discard them.
> If they are not negligible, then you have screwed up your processing
> in the frequency domain. Without more detail of what you are doing,
> we cannot tell what you have screwed up.
From: Wayne King on
"Peng Liang" <madokaaukawa(a)hotmail.com> wrote in message <hvbdjg$asl$1(a)fred.mathworks.com>...
> TideMan, thank you for your response and helps. You might know what is going wrong in my code.
>
> I checked the imaginary part of data. they are sometimes very significant. I have my code below. Please let me know where I go wrong.
>
> clear;
>
> fs = 8000;
> t = [0.000125:1/fs:1];
> A_1 = 10;
> A_2 = 4;
>
> f_1 = 350;
> s_1 = A_1*sin(2*pi*f_1*t); % generates a sine wave with 350Hz frequency
>
> f_2 = 700;
> s_2 = A_2*sin(2*pi*f_2*t); % generates a sine wave with 700Hz frequency
>
> s_3 = s_1+s_2; % mixed 350 and 700Hz sine wave
>
> S_3 = fft(s_3); % get dft data using fft algorithm, now the data is complex number
>
>
> %% design a high pass filter which only have ones and zeros
> filter = ones(size(S_1));
> filter(1:500) = 0;
> filter(7501:8000) = 0;
>
> S3_f = S_3.*filter; % filter the low frequency in frequency domain.
>
> s3_f = ifft(S3_f); % convert back to time domain using ifft, s3_f is time domian signal and gives significant imaginary part.
>
> anyone has idea why my ifft generates very large imaginary part?
> Need helps.
>
> Thanks in advance.
>
>
>
> TideMan <mulgor(a)gmail.com> wrote in message <d06620a7-8ec4-480d-9458-4d6c22f1e964(a)y18g2000prn.googlegroups.com>...
> > On Jun 16, 8:04 am, "Peng Liang" <madokaauk...(a)hotmail.com> wrote:
> > > Hi experts,
> > >
> > > I am using matlab to do the FFT convolution which take the fft of the signal and filter, multiply them in frequency domain. There is a problem. the ifft gives me complex numbers which is weird. since I multiplied the fft of the input signal with a filter kernel which is after fft. both data after fft are complex number. It should be turned back to real number after ifft. but I still get the complex numbers.
> > >
> > > is my question clear? Please give me a hand.
> > > thanks in advance.
> >
> > How large are the imaginary parts?
> > If they are very small, you can ignore them. They are the result of
> > floating point operations. Use real(y) to discard them.
> > If they are not negligible, then you have screwed up your processing
> > in the frequency domain. Without more detail of what you are doing,
> > we cannot tell what you have screwed up.

Hi, Peng, I think what Tideman told you is absolutely correct. When I run your example, the largest imaginary part I get is on the order of 10^(-15). I'm not sure why you think that is significant. Tideman explained to you why that happens. Either take his advice, or use the 'symmetric' option with ifft().

Also, you should not name your variable filter. filter is a Matlab function. You will cause yourself a lot of problems naming variables the same name as Matlab functions, classes, methods, etc.

Wayne
From: Greg Heath on
On Jun 16, 4:53 pm, "Peng Liang" <madokaauk...(a)hotmail.com> wrote:
> TideMan, thank you for your response and helps. You might
>know what is going wrong in my code.
>
> I checked the imaginary part of data. they are sometimes
>very significant. I have my code below. Please let me know
>where I go wrong.
>
> clear;
> fs = 8000;
> t = [0.000125:1/fs:1];

%Not consistent with

t = dt*(0:N-1); % dt = 1/fs
t = 0:dt:T-dt; % T = N*dt
t = linspace(0,T-dt,N);


> A_1 = 10;
> A_2 = 4;
>
> f_1 = 350;

% fs/f1 = 22.857 Not an integer

> s_1 = A_1*sin(2*pi*f_1*t); % generates a sine wave with 350Hz frequency
>
> f_2 = 700;

% fs/f2 = 22.857 Not an integer

> s_2 = A_2*sin(2*pi*f_2*t); % generates a sine wave with 700Hz frequency
>
> s_3 = s_1+s_2; % mixed 350 and 700Hz sine wave
>
> S_3 = fft(s_3); % get dft data using fft algorithm, now the data is complex number
>
> %% design a high pass filter which only have ones and zeros
> filter = ones(size(S_1));

% "filter" is a MATLAB function
% Uppercase S_1 undefined.

> filter(1:500) = 0;
> filter(7501:8000) = 0;
>
> S3_f = S_3.*filter; % filter the low frequency in frequency domain.
>
> s3_f = ifft(S3_f); % convert back to time domain using ifft, s3_f is time domian signal and gives significant imaginary part.
>
> anyone has idea why my ifft generates very large imaginary part?

%It doesn't

[ maxabs(real(s3_f)) maxabs(imag(s3_f))] % [4 2.8228e-015]

Hope this helps.

Greg