Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Frequency domain filtering in Matlab

  1. Apr 22, 2017 #1
    I am trying to implement several filters in Matlab for Fourier domain filtering. They are the cosine, Shepp-Logan, and Hann/Hamming window filters. These filters are defined as multiplying the ramp filter by the cosine function, sinc function, and Hann/Hamming windows respectively.

    This is how the responses of these filters should look like:


    However, this is what I am getting:


    I have defined the filters exactly as they are defined in this Matlab function, with a parameter ##d## that stretches the filters:

    Code (Text):
    w=linspace(0, 1, 181).'; % Frequency axis


    Hr = abs(w); % Ramp filter

    H=Hr.* cos(w/(d)); % Cosine filter
    H(H<0) = 0;

    H=Hr.* (sin(w/d)./(w/d)); % Shepp-Logan filter
    H(H<0) = 0;

    H=Hr.* (1+cos(w./d)) / 2; % Hann filter
    H(H<0) = 0;

    H=Hr.* (.54 + .46 * cos(w/d)); % Hamming filter
    H(H<0) = 0;
    For instance, if I change it to ##d=0.3##, the Hann/Hamming filters start to look correct. And at ##d=0.65##, the cosine filter looks more correct:


    So, what is the justification for using the parameter ##d##? And is there an algorithm for calculating it accurately for each filter?

    Any explanation would be greatly appreciated.
  2. jcsd
  3. Apr 27, 2017 #2
    Thanks for the thread! This is an automated courtesy bump. Sorry you aren't generating responses at the moment. Do you have any further information, come to any new conclusions or is it possible to reword the post? The more details the better.
  4. Apr 28, 2017 #3


    User Avatar
    Gold Member

    What do you get for d=1? I am guessing it might have to do with normalization?
  5. Apr 28, 2017 #4


    User Avatar
    Science Advisor
    Gold Member
    2017 Award

    The second plot above is d=1. I suspect there is a degree/radian/frequency units issue.
  6. Apr 29, 2017 #5
    I tried to plot the graphs without the ##d## but instead using some kind of normalization. This is the combination that produced the correct results:

    $$H=|\omega| \cos \left( \frac{\omega}{2 \pi} \right)$$

    $$H=|\omega| \left( \frac{\sin \left( \frac{\omega}{2 \pi} \right)}{\left( \frac{\omega}{2 \pi} \right)} \right)$$

    $$H = |\omega| \frac{1+\cos(\omega \pi)}{2}$$

    $$H = |\omega| (0.54 + 0.46 \cos (\omega \pi))$$

    Is there any reason why we need to divide the frequency in the first two by ##2 \pi##, but multiply it by ##\pi## in the Hann and Hamming window?

    It was a trial and error approach, so I am not sure. :confused:
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted