Continue to Site

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.

  • 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.

kind of digital filter...

Status
Not open for further replies.

ikalogic

Member
hey guys..

i need to build a kind of filter to eliminate all signal that are shorter than x seconds and only pass signals that will last more that x seconds... this is to reject false trigerring in an IR proximity sensor module i am building...

i know it will need maybe some AND gates and a 555 timer.. but i dont have a clue what this is called?? so i can do a searsh on google... or any links are wellcome too...thx

ika
 
RS-232 works by taking 16 samples per clock cycle (well, it doesnt really take 16 samples per cycle, just runs 16 times faster then the clock).

What it does to find the start bit of a signal though, is it takes 3 samples within those 16 ticks, and if the signal is still high (or low? i forget), then thinks that's the start bit and continues sampling every 16 ticks in order to land in the "middle" of the next bit to see if it's a 1 or 0.

I'd suppose you need to do something similar... if you know the rate of which the signal will be coming in, sample it at a much much higher rate.


Wow... that was really confusing... maybe it'll send you in the right direction though, look up information on RS-232 (serial communications).
 
no no, that's not exactly what i need, actualy the normal signal that i want is continuous, not pulses... but sometimes i get short pluses that i want to eliminate.. u see what i mean?
 
If you're using a digital filter, then you're not going to have a continuous signal.

Really, all you (probably) need is a low-pass filter of some kind. Depending on the magnitude and length of the signal you're trying to filter, you might be able to get away with just a capacitor between your signal line and ground.
 
have u had experience with pics? its real easy to program one to count signals and output w.e u want whenever something happens...its a way of doing it if your familiar with pics...
 
b0rna said:
have u had experience with pics? its real easy to program one to count signals and output w.e u want whenever something happens...its a way of doing it if your familiar with pics...

Hi b0rna,
I have been looking and trying to figure out how to actually program a uContoller as a filter so far without any luck, do you have any advise on how to go about it or a link to some web site for tutorial?

I guess to use a ucontroller as a low pass filter you would use an AD converter and use the clock/sampling rate to determine the cutoff frequency but what is the Q of that? would this be a brickwall filter response?

As for a highpass filter, I guess you would need 2 AD converters as lowpass filter one running at a clock rate as high as possible and the other running at the roll off sampling rate of the high pass filter then at the output of the DA converter invert the signal of the lower lowpass filter and sum both signal together to get the highpass output. But that would be like a very wide bandwidth bandpass filter used as a high pass filter, since you just can't get a true high pass filter because there will be a roll off at its sampling frequency.....

May be there is an easier way of doing this?

Thanks!
 
For the original question: If you sample the digital signal faster than the pulse you could do a sort of running AND. Each new sample you put the new sample into a queue (which will add the new element and bump off the oldest element). You then take the AND of all the bits in the queue: if the signal is longer than the minimum it will get through if its shorter it will never appear on the output. You could do this with the bitshift instruction on a microcontroller or use a shift register and a bunch of AND gates.

About the analog signal processing question:
There are two common types of digital filter: Finite Impulse Responce (FIR) and Infinite Impulse Responce (IIR). Don't worry they sound more complicated than they are. First of all: Whats an Impulse Responce? Imagine you put a very short pulse into a filter. The Pulse is the Impulse the output of the filter is the Impulse responce. Impulse Responce is a convenient way to define finters because it makes the math easy and its easy to look at and see what a filter will do.
FIR filter uses a digital representation of the impulse responce curve to do the digital filter. The digital representation is just the sampled impulse responce. Its called Finite because you only use a finite number of samples. You then have to do an operation called Convolution. Convolution is the math name for what happens when a signal goes through a filter. Say you are using 3 samples in you FIR Filter you need to keep the last 3 samples of the signal you want to process. You then multiply each input sample by the same number FIR filter sample and add all the results together:
y[n] = x[n]*FIR[n] + x[n-1]*FIR[n-1] + x[n-2]*FIR[n-2]
where n it the number of the sample, x is the input sample, FIR is the Filter sample and y is the putput sample. You just keep the last 2 samples and the new sample for each operation. The FIR sample don't change you pick them when you start to do the filter you want.

An IIR filter is of the form y[n] = y[n-1] + A*x[n]
Because you use the last output y[n-1] you take into account all the previous inputs because that output included the previous inputs. Thats why its called Infinite.

You should start off with an FIR filter - they are a bit easier to understand. Start with 3 points and try using FIR[n] = 1 FIR[n-1] = 0 FIR[n-2]= 0 this sould just dump out you signal without changing it. Try [0,0,1] this will dump out your signal but delayed by 2 samples. Try [10,5,2] this should look like a like a lowpass. Try [10,-5,2] if i remember right this should look like a high pass. Remember that if you are working with integers you have to make sure you don't overflow. You only need one A to D for all these filters.

Hope this helps
Brent
 
bmcculla said:
About the analog signal processing question:
There are two common types of digital filter: Finite Impulse Responce (FIR) and Infinite Impulse Responce (IIR).
snip>-------------------------


Hi bmcculla,
Thanks for the explaination, I wish there are more filter engineers around. I have yet to be able to digest the FIR and IIR even though its not the first time I have encountered with it......
My problem does not only include understanding it but also implementing it in either a ucontroller or a pic, I would think that you might have to use assembler embeded in C to write down all the algrithm function for the filter? I would love to be able to program my own digital filter chip with designated 4 bits for control of Q and freqeuncy roll off........ Wonder howcome non of the manufacturers produce any!???

Also, howcome no one has attempted to utilize Spice simulation and burn the filter spice algrithm onto a chip? eg. on an EEPROM then just run it with a ucontroller, man...that would make the DSP programming so much easier if there is any programming at all....... just simulate and play with the passive values and try out with various filter layout, look at the sim outcome before burning onto the chip....... :D

Sorry guys, not trying to be lazy but it seems that we are all doing it the hard way?

Surely I would love to be able to learn the programs and the theorem inside out BUT quite often I find the lectrures themselves have problem explaining in a way that's easily understood....... :roll:
 
Learner: I'm sure there are tools that do what you are asking. I think Simulink from Matlab will let you design filters in a more abstract method. The problem is that it takes a huge amount of computation.

You could write some C code (or assembler) that implements a FIR filter on your microcontroller. You then calculate the coefficients on your PC and then download them to your microcontroller. You can implement all sorts of filters with an FIR.

The big manufacturers do produce something like that its called a DSP :wink: . All you need to do is shell out ~$10k for the development tools.
 
bmcculla said:
Learner: I'm sure there are tools that do what you are asking. I think Simulink from Matlab will let you design filters in a more abstract method. The problem is that it takes a huge amount of computation.

Well, looking at the netlist of spice they could be short enough to implement a 4 pole filter and yes..... it is inavoidable for a huge amount of computation when it comes to DSP, that's just the way it is since there is no free lunch.......that's the cost for eliminating the hardware.


You could write some C code (or assembler) that implements a FIR filter on your microcontroller. You then calculate the coefficients on your PC and then download them to your microcontroller. You can implement all sorts of filters with an FIR.


Right, but the problem is knowing the concept of using FIR well enough in the first place to be able to apply it......... it requires a thorough understanding before you can utilizing it proficiently to customize a solution to accomodate any problem and that's where I am stuck :roll: :oops:

Still pulling my hair out trying to take it all in.....:oops:

Again, not try to be lazy but I am suprised that no one is selling preprogrammed FIR filters on EPROM like the good'ol monolithic filters?

Would be AWSOME to be able to buy them with motherboard and able to use it with the latest P4, just modularise your EPROM filter to suit your needs. Now that would be some powerful DSP!!!! as oppose to the pee wee pics and ucontrollers........

Sorry about the vent but I just don't understand why we are still dealing with such "primitive" CPUs when we already have P4 and left the age of 8085, commodore 64 and the likes.... :?

Sure they are useful for simple functions like control switches and keep time, generate LED patterns, sensors etc.... but when it comes down to computations I don't think these chips are powerfull enough with 8 bit bus...... It could probably accomodate and works as a single filter but when you want to do more than that, which often you would; you'll need like 3 ucontrollers just to make an audio state variable filter with seperate Q, frequency and amplitude adjustment........

I know I need a lot more work on my programming........ but often I find myself calculation the instruction to see if it will be fast enough to computate the data and instruction. :roll:
 
The reason people still use little 8 bit controllers is they're cheap - less than a dollar compared to $200-$700. You don't need a P4 to flash a LED.

But like all problem you have to use the right tools for the problem. If need more processing power there are solutions available. 32 bit ARM processors are fairly common now if you need a bit more power. ATMEL has a SOC ARM processor that would be fairly easy to get running. I also mentioned DSPs (digital signal processors) which are actually a class of processors specificly designed for signal processoing. They have multiple data busses and can do a bunch of computations each clock. TI sells a 1Ghz DSP that can do 8 Multiply-accumulates each clock cycle. The tools I was refering to let you specify a filter and they build the software for the Digital Signal Processor.

If you just want to test things out on your PC do a google search for FIR code - you should find tons of code.

If you just want a simple filter solution take a look at Anadigm's FPAA. It's a programmable analog device with free tools for filter design.
 
This is all very well, and I agree the way to make a digital filter is to use a DSP, basically a processor designed for that exact job.

BUT! - this isn't what the thread is about, it's not a filter in that sense at all, so there's no real 'signal processing' required. As I understand it he just wants to trigger something when a DC signal stays high for longer than a certain time - it could easily be done with a PIC, or in hardware, but a PIC would take almost no components to do it!.
 
bmcculla said:
The tools I was refering to let you specify a filter and they build the software for the Digital Signal Processor.

If you just want to test things out on your PC do a google search for FIR code - you should find tons of code.

If you just want a simple filter solution take a look at Anadigm's FPAA. It's a programmable analog device with free tools for filter design.

COOL! :D

I will definitely look into that and most likely be back to look for more guidance if you don't mind! :)

It's nice to meet someone that's actually into this stuff, for some reason you just don't seem to find anyone talking about it ANY WHERE........ may be they are too busy occupied pulling their hair out!? :shock:

Just kiddin....... :D
 
Nigel Goodwin said:
This is all very well, and I agree the way to make a digital filter is to use a DSP, basically a processor designed for that exact job.

BUT! - this isn't what the thread is about, it's not a filter in that sense at all, so there's no real 'signal processing' required. As I understand it he just wants to trigger something when a DC signal stays high for longer than a certain time - it could easily be done with a PIC, or in hardware, but a PIC would take almost no components to do it!.


Sorry Nigel and everyone, didn't mean to go off topic with the whole DSP thingy........ I guess I got too excited to be able to find someone that's actually willing to discuss about FIR and IIR!!!! :shock:
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top