I am using the Hilbert function for an analysis, and I would like to use the FFT method to get the imaginary part. What I am unsure of is how the FFT function is zero padding? I would like there to be an even number of zeros on each end of my data so that when I apply a window, my data are centered. Any help on this would be greatly appreciated.
example of code I'm using (i've attached an example mat file with the variable "prox")
a= hilbert(hann(length(prox)).*prox,2^8);

 Respuesta aceptada

Matt J
Matt J el 23 de Mayo de 2019
Editada: Matt J el 23 de Mayo de 2019

3 votos

Y = fft(X,n);
is the same as
Xp=X;
Xp(length(X)+1:n)=0;
Y=fft(Xp);

8 comentarios

Avelino Amado
Avelino Amado el 23 de Mayo de 2019
Matt,
Thank you for your response. From what I'm gathering, is the fft function only zero pads the ends, and not the beginning? So if I want symmetrical padding, I would have to do it manually?
Matt J
Matt J el 23 de Mayo de 2019
Editada: Matt J el 23 de Mayo de 2019
Yes, and you would also have to incorporate ifftshift, like in the following.
Xp=ifftshift( [zeros(p,1) ; X(:) ; zeros(p,1)] );
Y=fft(Xp);
Avelino Amado
Avelino Amado el 23 de Mayo de 2019
Thank you for this quick responses. I'm not really understanding the difference between ifftshift and fftshift. If possible, could you help me understand the difference? Once again, thank you for your assistance
Matt J
Matt J el 23 de Mayo de 2019
Editada: Matt J el 23 de Mayo de 2019
They are simply inverses of one another. ifftshift is what you use if your signal origin is sampled in the center of the input array, X. In this example, the original continuous signal, before sampling, had value 4 at t=0.
X =
0 0 0 0 1 2 3 4 3 2 1 0 0 0 0
By applying ifftshift, the samples are circulantly shifted so that the t-origin is sampled at the beginning of the array, which is where fft() expects it to be.
>> ifftshift(X)
ans =
4 3 2 1 0 0 0 0 0 0 0 0 1 2 3
If we now feed this to fft(), the output spectrum will also have its origin (the frequency origin) at the beginning of the array
>> fft(ifftshift(X))
ans =
Columns 1 through 10
16.0000 12.7758 5.9786 1.0000 0.0783 1.0000 1.0000 0.1673 0.1673 1.0000
Columns 11 through 15
1.0000 0.0783 1.0000 5.9786 12.7758
But this is often not how we like to look at things, so fftshift can be used to shift the origin to the center of the array again,
>> fftshift(ans)
ans =
Columns 1 through 10
0.1673 1.0000 1.0000 0.0783 1.0000 5.9786 12.7758 16.0000 12.7758 5.9786
Columns 11 through 15
1.0000 0.0783 1.0000 1.0000 0.1673
Avelino Amado
Avelino Amado el 23 de Mayo de 2019
If I want to apply a window to my data the following be my order of operations
1) a= [zeros(p,1) ; X(:) ; zeros(p,1)]
2) b= ifft(hann(length(a).*a))
I guess my ultimate goal is to make sure my data are centered when I apply the window, because I've been trying different windows out and I think they are capturing incorrect part of my data because the fft function was only padding the end. This exchange has been very helpful
Matt J
Matt J el 23 de Mayo de 2019
This exchange has been very helpful
Does that mean you got it working? If so, please Accept-click the answer.
Avelino Amado
Avelino Amado el 23 de Mayo de 2019
I have done the fft, ifftshift, but what I'm still unsure of is when I apply a window. My understanding would be I would window after I pad with zeros, is that correct?
Matt J
Matt J el 23 de Mayo de 2019
That is something that only you can know (because it is your algorithm). But ifftshift would normally be done right before fft.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 23 de Mayo de 2019

Comentada:

el 23 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by