why does my data kick up at the end after doing ifft(X)

8 次查看(过去 30 天)
I have some data that I am doing a fft one, then filtering, then want to turn it back into the original domain, but when I do there is a 'kick' at the end of the data. I've followed what I can of the help functions for fft & ifft, but this is not detailed in there (that I can determine)
This is the code:
W = data(1,1:1024);
fs = 1;
L = length(W);
f = (0:L-1. fs*/L;
Y = fft(W);
Y1 = Y(1:512); % take just first half
filt_5 = ones(1, 5)/5;
f_delay = (length(filt_5)-1)/2;
filt_W_fft = filter(filt_5, 1, Y1);
YY = ifft(filt_W_fft);
And this is what I get:
In the top subplot, the purple curve is the result of the ifft - why does it have the upkick in data at ~1000 point mark? And how do I get rid of it?
Am I doing something wrong with the fft/ifft implementation?
Thanks in advance for any help or guidance.
  3 个评论
Paul
Paul 2022-11-23
移动:Matt J 2022-11-23
Hi Joanne
It will be easier for people to help if you post the data. Use the paper clip icon to attach it to your question as a .mat file or some other format.
Having said that, it looks like you're applying a moving average filter to the FFT of W. Are you sure that's what you want to do? I'm asking because filter is typically used to filter a time domain signal, not a frequency domain signal.
Joanne
Joanne 2022-12-5
编辑:Joanne 2022-12-5
Hi Paul & Mathieu,
Thanks for your comment, I appreciate the comment about the moving average filter - it's just an example of something I want to do (i.e. manipulate the results) - the details of that step are not relevant to my question - I'm trying to better understand and learn how to use fft/ifft in matlab.
Also, I am not allowed to share the data unfortunately.
Thanks

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2022-11-23
编辑:Matt J 2022-11-23
why does my data kick up at the end
Remember, because of the circulant property of IFFTs, the values near the end of the array correspond to times just slightly prior to time t=0 (unless you apply fftshift).
By throwing away the second half of the spectrum in this line,
Y1 = Y(1:512); % take just first half
you are in effect applying a rect window to the spectrum, which is equivalent to convolving the original time signal W with a sinc kernel. So, even though your initial signal W starts at t=0, your operations will blur W so that negative times t<0 will have non-zero signal values as well. These new values are what you see at the end of YY.
And how do I get rid of it?
Don't throw away half of your spectrum.
  2 个评论
Joanne
Joanne 2022-12-5
Oh, somebody told me that I didn't need the second half of the data because it was a mirror of the first half - hence the said to just take the first half - that's why I did that.
How would I apply fft shift then? That wasn't in the steps on the Matlab guide to ifft.
I'm sorry, I'm just trying to learn how to use these functions.
Thank you
Matt J
Matt J 2022-12-5
Do you need fftshift? I'm not sure you do. I certainly never sugggested. Looking again at your code, though, it is possible that smoothdata expects Y1 to be unwrapped:
filt_W_fft = ifftshift( smoothdata(fftshift(Y1),'gaussian',5) );

请先登录,再进行评论。

类别

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

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by