Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: How to use Amplifier and Bandpass Filter in Teensey-3.6 + Arduino?

  1. #1
    Junior Member
    Join Date
    Mar 2019
    Posts
    4

    How to use Amplifier and Bandpass Filter in Teensey-3.6 + Arduino?

    We have been using Teensey + Arduino in designing a IIOT product for our customer. The deployment time is near, and we have just come across a problem around Analog design we had. We can overcome that if we can have Amplifier and Bandpass Filter acting within Teensey through the software library. We have seen the tutorial and also tried through Audio GUI web tool of Teensey, but not able to map against our need.

    Technical Problem Statement - 1:
    We are using Teensey-3.6. We will be having Input Analog Signal coming to the A22 pin of Teensey. The Amplitude of signal is going to be vary, and we are deriving a resistance of a field instrument out of this. Right now with increasing value of resistance we see much lower amplitude and values are also adjacent Ė ADC count has minor variation, and it makes us unable to distinguish the resistance of a field instrument.

    Solution Needed:
    If we can have a Amplification block internal to Teensey, which can be introduced before we read the ADC resolution in software then we are seeing a hope here.

    Technical Problem Statement - 2:
    Adding further to the problem statement-1, the signal is going to come from field so there would be high chances for noise in the signal. We donít have a scope lately to have a filter in the hardware board to overcome this.

    Solution Needed:
    On the same ADC input, if we can have a bandpass filter block internal to Teensey, which can be introduced before we read the ADC resolution in software then we are seeing a hope here.

    Please help us with the problem statements mentioned above, and it would be great if you can same further reference or code-snippets which can help us to move forward.

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,296
    In opposite to the Teensy 3.2 which has internal PGAs which might optionally amplify an input signal up to 64 times, the Teensy 3.6 doesn‘t have these, thus you have to find other ways to optimize the ADC resolution, for example by using a lower reference like the internal 1.2V bandgap instead of the default 3.3V, and/or by using the ADC in differential mode.
    Unfortunately, you do not tell enough exact specifications about your project, so helping by guessing around is very limited. If it‘s really about measuring resistance variations, an external Wheatstone bridge with an op amp would be the state of the art solution.
    Noise filtering can be implemented in several ways, but impossible to give you more precise hints without more specs. Common approaches are oversampling with following averaging or a digital band pass filter, or an active band pass filter combined with the external Wheatstone bridge circuit.
    Forget about the amplifier block in the audio library. It is a simple digital software attenuator, not able to get back or restore resolution which was previously lost.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,536
    I'm not sure I fully understand your questions....

    Quote Originally Posted by AalokShah View Post
    If we can have a Amplification block internal to Teensey, which can be introduced before we read the ADC resolution in software then we are seeing a hope here.
    There is no analog amplifier hardware inside the chip.

    If you need multiple ranges, you'll probably need to add an opamp to boost your signal.

    The chip on Teensy 3.2 does have a programmable gain amplifier. We don't have any software support built into Teensyduino, but you can use the PGA if you directly access the hardware register. The PGA only works on signals from specific pins (as I recall, only A10 & A11). If Teensy 3.2 will meet your needs, maybe you could make use of its PGA?


    On the same ADC input, if we can have a bandpass filter block internal to Teensey, which can be introduced before we read the ADC resolution in software then we are seeing a hope here.
    Again, this analog hardware simply does not exist inside the chip.

    If you need filtering before the ADC, you will have to add the analog circuitry to process your signals before sending it to Teensy.

    Of course digital filtering is possible. Even if you can't use the audio library, perhaps the open source code from that library will give you a good starting point for crafting the code you need?

  4. #4
    Junior Member
    Join Date
    Mar 2019
    Posts
    4
    Thanks guys for reverting, it is helpful.

    As Teensey-3.6 doesn't have gain amplifier, I won't have any way there through firmware.

    Regarding digital filtration, I have found bandpass related code at Arduino\hardware\teensy\avr\libraries\Audio\exampl es\Effects. And also come across - 'https://github.com/jbir789/FilterFIR/blob/master/README.md'.

    I am seeing a need of co-efficient there, and not sure how it can be achieved. I am firmware guy, and won't have good understanding of filtration concepts. My need is like, I would be having an analog input signal of 16KHZ on A22 (ADC), and I want to make sure that I cancel-out the noises which have been introduced over that signal (as the signal is going to come from field) before the ADC block.

    Please notify how can I move forward, it would be great if any other simpler library/API calls which can also solve my purpose.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,536
    We can help you much more if you are more specific with details....

    Quote Originally Posted by AalokShah View Post
    Regarding digital filtration, I have found bandpass related code at Arduino\hardware\teensy\avr\libraries\Audio\exampl es\Effects.
    There are 2 filter examples in that folder, "Filter" and "Filter_FIR". I'm guessing you're asking about Filter_FIR?


    And also come across - 'https://github.com/jbir789/FilterFIR/blob/master/README.md'.

    I am seeing a need of co-efficient there, and not sure how it can be achieved. I am firmware guy, and won't have good understanding of filtration concepts.
    Usually you would use a software tool to generate the FIR coefficients for your desired filter response. MATLAB is the most popular program, and it's specifically mentioned in that readme file. However, MATLAB is expensive and requires quite a bit of knowledge to use.

    If you look at the FIR filter documentation, at this page (right side panel)

    https://www.pjrc.com/teensy/gui/?info=AudioFilterFIR

    You will see a link in the "Notes" section to "TFilter Design Tool", which is a free FIR filter calculator. Rather than copy this link, I want you to go to the design tool and take notice of the right-side documentation panel. You will find important documentation for all of Teensy's audio library features in that panel.


    My need is like, I would be having an analog input signal of 16KHZ on A22 (ADC), and I want to make sure that I cancel-out the noises which have been introduced over that signal (as the signal is going to come from field) before the ADC block.
    Again, we can help more if you are more specific with details.

    I do not fully understand what "an analog input signal of 16KHZ" means. Does this mean you have a sine wave that is 16 kHz frequency? If it is a pure sine wave, why would you need filtering of any kind?

    You say you want to "cancel-out the noises which have been introduced over that signal", but that tells us almost nothing about the signal or the noises. The words "cancel-out" are also difficult to understand. Filters don't cancel anything. They attenuate certain frequency ranges. They also introduce frequency dependent phase shift. Details matter!


    Please notify how can I move forward, it would be great if any other simpler library/API calls which can also solve my purpose.
    We have tried very hard to make the audio library easy to use. It has 2 other filters, biquad and state variable, where you can simply call functions to configure the filter. But we don't have anything like the TFilter tool built into the library for FIR. Someday I hope we can make FIR as easy to use as the others, but that will require a tremendous amount of work. So many other features are higher priority.

    If you're looking for simple and easy, I highly recommend using the biquad or state variable filters. Just call the functions. You might also try doing the tutorial. There is a section in the tutorial specifically about the filters, where you turn knobs and hear the change in filtering effect.

    https://www.pjrc.com/store/audio_tutorial_kit.html

    Earlier you said you could not use the audio library. I still do not understand why. But I can tell you, while it certainly is possible to craft your own signal acquisition and processing code, doing so requires quite a lot of skill and work to achieve good results. Maybe you can make use of some of the code already in the audio library, at least as a starting point. But without fully understanding why you can not simply use the already-written library, very difficult to give you any helpful guidance. Even if we do know this, I hope you can understand we can only help to a limited degree. If you embark on such a large project, we might be able to assist with some suggestions and tips, but you really need to understand it is a huge project. Ultimately you will need to write and debug that code. The audio library is already written and works well. We created it to help you and everyone else, to be able to achieve these sorts of projects without the tremendous work to craft all that code from scratch.

  6. #6
    Junior Member
    Join Date
    Mar 2019
    Posts
    4
    Hi Paul,

    Thanks for reverting.

    Briefing on project:
    We are reading a resistance of an field instrument. The output from the field instrument is sine wave of 16 KHZ, and the peak of the sine wave will be in proposition to the resistance of the field instrument. The signal will be input to A22 pin, where we will get the peak from ADC and derive the resistance.

    As the signal is going to traverse through field, it increases the chances of additional noises. So my need of interest is 16 KHZ, and I would like to attenuate all the other frequencies/noise.

    I have tried the TFilter tool, but won't able to configure to attenuate up to 0-14KHZ or something like that.

    I will look for biquad or state if they can help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •