0

So, Hann filter is:

H(k)=(1+cos(2*pi*k/W))/2 , W=2*kmax

and based on this, the inverse Fourier of Hann filter is supposed to be:

h(x) = 1/2delt(x) + 1/4(delta(x-1)+delta(x+1))

where delta(.) is the Dirac Delta function. So, if Hk and hx denotes H(k) and h(x), respectively:

n = 128;
Hk = hann(n,'symmetric')';
hx = ifft(ifftshift(Hk));

I tested hx and Hk on a sample 1D signal here, and the result seems to be working as I expected. However, hx does not look as what I expected which is the sum of 3 delta Dirac functions. What is missing in my code?

enter image description here

alpereira7
  • 1,522
  • 3
  • 17
  • 30
SaraG
  • 179
  • 2
  • 11
  • 2
    Apply `fftshift` to your output, it'll look more like what you expect. – Cris Luengo Jan 18 '18 at 21:42
  • 1
    Did you signal in the linked question shift by `N/2` after the convolution? That's your missing `fftshift`! – Cris Luengo Jan 18 '18 at 21:44
  • Thank you for your reply. You were right, I applied fftshift on the hx and output looks to have three delta functions with the amplitudes of 0.25,0.5, and 0.25. However, they are located at x = 1, 0, and 2. Why is there a shift? I was expecting to see them at -1,0,1. Is it because N is even? – SaraG Jan 18 '18 at 21:52
  • 1
    Oh, maybe that's the difference between `ifftshift` and `fftshift`? I always mix those two up! They're identical for odd signal length, but differ by 1 for even signal length. – Cris Luengo Jan 18 '18 at 21:53
  • Regarding your comment about my linked question, do you mean that I have to do something like this: s3 = fftshift(conv(s1,wx,'same'),n/2); Based on one of the comments in the linked question, I used cconv and it resolved the issue. – SaraG Jan 18 '18 at 21:55
  • 1
    Or, it's in how you define the 0 frequency? `fftshift` moves the value in the first bin to the middle, so if `hx(1)==0.5`, then wherever that moves to is the zero frequency. – Cris Luengo Jan 18 '18 at 21:55
  • 1
    I don't know `cconv`. But you'd do `conv(s1,fftshift(wx),'same')`. Maybe `cconv` does that? – Cris Luengo Jan 18 '18 at 21:57
  • @SaraG How are you defining your sample locations? – AnonSubmitter85 Jan 18 '18 at 22:25

0 Answers0