1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Working of Digital filters...

Discussion in 'Homework Help' started by koolguy, Oct 31, 2011.

  1. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    Location:
    NJ
    Hi,

    Yes, the response that we code could be a filter, and the values that are coded are the values of that particular filter's unit sample response.

    In continuous time we might use a resistor and capacitor to make a filter. In the sampled system, we would find that filter's unit sample response and code that into memory.
    For the continuous time system with R and C we would have to convolve the input with the filter's impulse response to get the output (mathematically).
    For the sampled system, we would convolve the input with the filter's unit sample response.

    So it's all about finding the unit sample response of the filter we want to use, then coding it into memory.
     
    • Like Like x 1
  2. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi again,

    But if we can change the output of input signal according to x(n) so how we will choose h(n0 value?????
     
  3. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    Location:
    NJ
    Hi,


    The choice of what h(n) to use varies as widely as the application it is going to be used in.

    For example, if you are going to build a display that displays your music audio to light up different LEDs depending on the frequency band of the audio, you would probably want to make h(n) that of a bandpass filter. But if you wanted to build a DC voltmeter you might want to make h(n) that of a low pass filter so it averages out small variations in the input DC level.
    So the choice of what h(n) to use varies as much as your choice when you need a regular passive or active filter. You make h(n) the same as the filter's response of the passive or active filter you would have chosen had you done it in all analog. This is one reason why i demonstrated the use of the digital low pass filter, so you can get an idea what you use this for.

    You should also keep in mind that the number of ways to approach these designs varies widely too. There are many ways to design filters, and more ways to design digital filters. We've just touched the surface here, but there is probably much much more on the web with a little searching.

    Just to show a simple example of how varied the digital filter applications are, consider the application of copying files on your computer from one hard drive to another. Not really an electronic application? That's right, but the digital filter can still be used here as follows...
    When you select a very large number of files lets say, say 100000 files, and click "Copy". Then you click "Paste" (to the new hard drive). The files begin to be copied from one location to the other, but they dont copy in zero time. It takes considerable time to copy that many files. In the mean time, you probably want to know what the progress is in say percent. 0 percent means no files were copied, 100 percent means all the files were copied. While they are copying, the percentage should increase, 0, 1, 2, 3, ....10, 11, 12, etc., until it reaches 100 percent. That's not too much of a problem, as you just look at say the number of bytes and do a little division for how many bytes have already been copied over all the bytes that have to be copied.
    But say you also want to know how much time remains to copy ALL of the files?
    You can estimate based on the total number of bytes to be copied and the time to copy say 1000 bytes, but unfortunately the software isnt that predictable because there are a number of variables that constantly change the time it might take to copy 99999 files after 1 has already been copied lets say.
    Because of this, we have to constantly update the time remaining to copy the remaining files. This varies quite a bit on an actual PC computer. For 100000 files it may calculate out as 10 minutes (im making this simple) but then later it goes down to 9 minutes 5 seconds for say 90000 files, but the variation is so unpredictable that sometimes it takes longer to copy 1000 files and sometimes it happens faster, so this time display might go like this:
    9 mins 5 secs
    8 mins 45 seconds
    8 mins 40 seconds
    8 mins 30 seconds
    8 mins 55 seconds
    7 mins 34 seconds

    From this little example we can see that the time goes up AND down, because the estimate changes over time because the error in the estimate changes.

    Now notice that if those were voltage values instead of time values we could use an RC low pass filter to make the fluctuations smaller and smoother. This would be more presentable to the user like you or me who is copying all these files. This is where the low pass digital filter comes in.

    We design a digital filter that takes as input the actual time values, convolve them with an h(n) that is a low pass filter, then display the output time values rahter than the original time values. The above might then look like this:
    9 mins 5 secs
    8 mins 45 seconds
    8 mins 40 seconds
    8 mins 30 seconds
    8 mins 25 seconds
    8 mins 02 seconds
    8 mins 03 seconds

    Note that this makes much more sense to somebody copying files. Also note that the time did go up a little there at the last sample, but it was much less than it was before we applied the filter.

    If you really want to know how this works, try that little example out on your computer using some programming language that you are comfortable with. Enter in the input data and do the math in the program and see how the output looks after filtering. I think you will be very happy with the results and you'll then have a really good idea how this works.
     
    Last edited: Nov 12, 2011
    • Like Like x 1
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9

    Which software is used for this application...........
     
  6. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    Location:
    NJ
    Hello,

    You can use any language compiler. A simple one is Euphoria, which is free. Easy to learn too if you've never done any programming.

    What you can do with this is set up your own experiments, where you transform your filter using whatever method you choose, then enter the values into the program and calculate the output values.

    I'll try to get back here with an example. It's really quite easy to do.

    I should first ask, does this make any sense to you...

    constant e=2.718281828459
    atom V,v1,R,C,t

    v1=5
    t=0.001
    R=1000
    C=1e-6
    V=v1*(1-power(e,-t/(R*C)))
    printf(1,"%f\n",V)

    In the first two lines above we declare a constant 'e', then declare some variables to be used in the program.
    In the next line v1=5 we simply set v1 equal to 5 (volts).
    In the next line we set the time t to 1ms.
    In the next line we make R be 1k ohms.
    In the next line we make C be 1uf.
    In the next line we calculate the voltage V using that expression.
    In the next line we print the value of V that we calculated.

    Make sense so far?
     
    Last edited: Nov 14, 2011
    • Like Like x 1
  7. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    yes, but i think you are using analog RC filter as we are talking about digital filters ( exactly unit response)
     
  8. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    Location:
    NJ
    Hi,

    Yes, but i just wanted to ask you if you understand the program that's all. If you do then you can use that language and do your own experiments that way.
    So you understand what all the lines mean basically?
     
    • Like Like x 1
  9. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi again,

    But why RC in digital filters.....??



    in this we are defining the constant values...
    what does atom mean here??



    and solving the equation from above parameters..



    at last watching the answer on screen...

    I am not sure that C or other lang..
     
  10. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    Location:
    NJ
    Hi,

    I am just talking RC because that's JUST an example of a *program*, not a *digital* equation or related.

    The constant is declared because the language does not know what 'e' is yet, so we have to tell it that.

    "atom" just means "float" like in C more or less, but it could be an integer like 123.00000.

    The language is similar to C, but it is an interpreted language not a compiled language, although there are options to compile too.
    By using the interpreter, we can type in program lines and get them to work within seconds and if there is an error the interpreter (part of the language) will tell us and we can correct it.

    "atom x,y,A"

    That line just tells the interpreter that we will be using a variable called "x", another one called "y", and another one called "A".

    "constant R1=10000"

    That line just tells the interpreter that we have a variable R1 that will ALWAYS be equal to 10000. Later in the program we want to use this resistor value so we can declare it as a constant, or we can do this:

    "atom R1"
    "R1=10000"

    and that allows us to change the value of R1 later if we want too.

    Again, R1 here is just for example of the language, not anything digital.
     
    • Like Like x 1
  11. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    HI,

    but i want to know about impulse of digital filter not analog..........How to get H(n) discrete values.??
     
  12. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    Location:
    NJ
    Hi,

    I thought i explained that with the low pass filter example. One way is to run a unit sample through the transfer function H(z). Or is it the transfer function you want to get?

    To get H(z) from H(s) we can use the Bilinear Transform.
    To get h(n) from H(z) we can convolve H(z) with the unit sample.

    We can do another example i guess...i was thinking maybe a second order low pass filter this time around.
     
    Last edited: Nov 19, 2011
    • Like Like x 1
  13. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hi again,

    The problem is that if we see a problem of digital filter or signal which use X(n) which seems to be normal to me, but how to set value or get value of h(n) on what value or condition it value depends.....

    I have asked this question to many guys they said it depend on system........etc
    but i want to know what are does limits??
     
  14. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    Location:
    NJ
    Hi again,

    Not sure what you are asking here again.

    It's like you are asking how to design every possible thing you can possibly design using digital processing. The scope of that task is way too wide so would take too long to discuss and we would still never exhaust all the possibilities. I was trying to limit this discussion to digital filters, and even within that area limiting to a certain technique which i happen to think is very informative and illustrative of some kinds of digital system design.

    Also i think you need some 'hands on' design such as what you might call a "Lab". This would involve doing some computations and using those results in calculations which simulate your system. The calculations involved usually run into some procedures which have to be repeated over and over again, and so knowing a higher level computer language would help quite a bit too. The language i suggested is easy to learn and so you can start programming your own filters and doing simulations without needing any special software.
    Alternately if you can find some software that will convolve your input with a prospective h(n) that's good too i guess.
     
    Last edited: Nov 19, 2011
    • Like Like x 1
  15. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Going through it again, i think i am getting you what you want to tell about H(n)...
    similar to this video in analog from.

     
  16. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    Location:
    NJ
    Hi again,

    I have to highly recommend that you try a couple of these filters using a computer language or even a hand calculator so you get a feel for what they are all about. Im sure you'll get going once you do a couple, and find it much easier to do then to actually explain how to do :)
     
    • Like Like x 1
  17. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Hello,

    I am trying to learn E. Lang but how to use it.......??
    here is the images of it.
     

    Attached Files:

    • 1.JPG
      File size:
      197.7 KB
      Views:
      114
    Last edited: Nov 20, 2011
  18. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    Location:
    NJ
    Hi again,

    Im happy to see you are trying this out. You'll find it very useful and you can do lots of experiments with it.

    To start, you should do a simple program. Also, do you have your Euphoria directory set up under say drive "C" ? You should have another directory called:
    C:\Euphoria\Include
    and that directory should have several files under it that came with the package you must have downloaded for this language.
    You then also set your environment variable to point to that include directory.

    For now ill assume you dont have that set up yet. For your first program you can start a text file say called "FirstProgram.exw" (that name exactly and that extension). Open that file with a text editor like Notepad and type this:

    printf(1,"%s\n",{"First Program"})
    while 1 do
    end while

    (in fact copy and paste that into the text file rather than type it again)

    Now when you start the interpreter (what you must have done for your last post) you type in the name of that program FirstProgram.exw.
    If it cant find that program you might need to move the program to under the C:\Euphoria\bin directory first.
    This is just to get you started, as you will be able to use it more effectively soon.

    Next you can try:

    atom a,b,x

    a=1.234
    b=2.345

    x=a+b

    printf(1,"%f\n",x)
    while 1 do
    end while

    That will print the addition result to screen.

    Eventually once you get your system set up for the language you will only have to double click the .exw file to get it to run for you. It may be set up already if you installed, but im assuming it is not for now. You can check it by double clicking your text file above and see if it runs ok.
     
    Last edited: Nov 20, 2011
    • Like Like x 1
  19. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I am not understanding how to use it??

    where to write this program , exactly what??
    Even, when i was solving this problem with this formula:-

    y(n)=x(k)*h(n-k) where n=-1 to 5

    X(n)= 1234 ( for X(n) 0 to 3)
    and h(n) = 1234 ( for h(n) -1 to 2)

    and another method was graphical method shifting the sequence.........
    by graphical answer was 3 and by using above formula it was 1.., why???
    The value of y(n) sequence should be same...
     
  20. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,029
    Likes:
    951
    Location:
    NJ
    Hi,

    I told you to type that into a text editor like Notepad, then save it to a file named something like "MyFile.exw" making sure it has .exw file extension.
    That will get you started.

    The formula you presented is not convolution. You need to use convolution to get the correct answer, i think that's what the problem is with the calculation you did. When we write:
    y(n)=x(k)*h(n-k)
    the little asterisk "*" is not multiplication, it stands for convolution, which is an entirely different operation. Did you do it that way or use regular multiplication?

    Show me what x(n) you are using and what h(n) you are using and we can compare notes.
     
    Last edited: Nov 20, 2011
  21. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I have saved the file in Bin and when i double click or type in win its shows first program and do nothing....even i can't write any thing on it.??
     

Share This Page