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

8 vues (au cours des 30 derniers jours)
Joanne
Joanne le 23 Nov 2022
Commenté : Matt J le 5 Déc 2022
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 commentaires
Paul
Paul le 23 Nov 2022
Déplacé(e) : Matt J le 23 Nov 2022
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 le 5 Déc 2022
Modifié(e) : Joanne le 5 Déc 2022
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

Connectez-vous pour commenter.

Réponses (1)

Matt J
Matt J le 23 Nov 2022
Modifié(e) : Matt J le 23 Nov 2022
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 commentaires
Joanne
Joanne le 5 Déc 2022
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 le 5 Déc 2022
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) );

Connectez-vous pour commenter.

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by