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);

 采纳的回答

Matt J
Matt J 2019-5-23
编辑:Matt J 2019-5-23
Y = fft(X,n);
is the same as
Xp=X;
Xp(length(X)+1:n)=0;
Y=fft(Xp);

8 个评论

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?
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);
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
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
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
This exchange has been very helpful
Does that mean you got it working? If so, please Accept-click the answer.
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?
That is something that only you can know (because it is your algorithm). But ifftshift would normally be done right before fft.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by