How to use Teensy libraries to do signal processing

Status
Not open for further replies.

mitzi111

Member
For our project our goal is to acquire body sounds from an acoustic stethoscope and do digital 1) filtering 2) noise reduction (static + heart sounds), and 3) amplifying of signals. The frequencies we're trying to detect ranges from 20 Hz to 2kHz.

Here is a block diagram of our plan so far

ADC -> Bandpass Filter -> noise reduction (we don't know how to do this yet) -> amplify -> DAC.

Do you think this is possible and would editing the available libraries be enough?

**With regards to filters, I've been seeing that the input and output keep on using the i2s. How do we use the same input (i2s) if we don't have the audio board?

Please do suggest any possible methods/libraries/steps on how to go about this since we're new to coding and to teensy in general. thanks!
 
Last edited:
Except for the noise reduction involving unspecified algorithms, you can do all this pretty easily with the audio library.

Most of the examples use the audio board with I2S. Of course you can use the design tool to connect the analog input to an ADC pin. Details here (right side documentation panel).

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

If you're just starting and learning, it might be worthwhile to just get the audio shield so you can do the tutorial without all the fiddling of adapting to use different input & output methods. Then again, if you just watch some of the video and play with the design tool, maybe you'll understand how to use it to connect different input & output. Or take a look at this recent thread:

https://forum.pjrc.com/threads/42981-**-HOW-TO**Audio-lib-tutorial-without-using-an-audio-shield
 
thanks for the reply!

would you happen to know how the StateVariableFilter works? I'm not too sure why it's input says white noise. and where does it gets the input? Would it be safe to say that I could edit the input to make it filter our chosen input signal?

/* Example of filtering audio noise with a resonant filter,
using Mozzi sonification library.

Demonstrates StateVariable() with acute resonance,
which in this case requires the input signal level to be reduced
to avoid distortion which can occur with sharp resonance settings.

This sketch using HIFI mode is not for Teensy 3.1.

IMPORTANT: this sketch requires Mozzi/mozzi_config.h to be
be changed from STANDARD mode to HIFI.
In Mozz/mozzi_config.h, change
#define AUDIO_MODE STANDARD
//#define AUDIO_MODE HIFI
to
//#define AUDIO_MODE STANDARD
#define AUDIO_MODE HIFI

Circuit: Audio output on digital pin 9 and 10 (on a Uno or similar),
Check the Mozzi core module documentation for others and more detail

3.9k
pin 9 ---WWWW-----|-----output
499k |
pin 10 ---WWWW---- |
|
4.7n ==
|
ground

Resistors are ±0.5% Measure and choose the most precise
from a batch of whatever you can get. Use two 1M resistors
in parallel if you can't find 499k.
Alternatively using 39 ohm, 4.99k and 470nF components will
work directly with headphones.

Mozzi help/discussion/announcements:
https://groups.google.com/forum/#!forum/mozzi-users

Tim Barrass 2012, CC by-nc-sa.
*/

#include <MozziGuts.h>
#include <Oscil.h>
#include <tables/whitenoise8192_int8.h>
#include <StateVariable.h>



Oscil <WHITENOISE8192_NUM_CELLS, AUDIO_RATE> aNoise(WHITENOISE8192_DATA); // audio noise
StateVariable <BANDPASS> svf; // can be LOWPASS, BANDPASS, HIGHPASS or NOTCH


void setup(){
startMozzi();
aNoise.setFreq(1.27f*(float)AUDIO_RATE/WHITENOISE8192_SAMPLERATE); // * by an oddish number (1.27) to avoid exact repeating of noise oscil
svf.setResonance(1); // 0 to 255, 0 is the "sharp" end
svf.setCentreFreq(3500);
}


void updateControl(){
}


int updateAudio(){
int input = aNoise.next()>>1; // shift down (ie. fast /) to avoid distortion with extreme resonant filter setting
int output = svf.next(input);
return output<<4; // shift up for HIFI resolution
}


void loop(){
audioHook();
}
 
"Except for the noise reduction involving unspecified algorithms, you can do all this pretty easily with the audio library."

Would you happen to know any open source algorithms fit for teensy that can do the job?
 
There really isn't an answer to that one, since without further information everything in a signal is the signal. The noise is in the eye of the beholder so there is no magic noise suppression. From the sounds of your initial brief you want to look at various high and low pass filtering to winnow down signals you don't want, possibly with a gain control system to mute heartbeat which your vague initial description suggests isn't wanted. So part of your processing would look for the heartbeat, and then either just mute all signal while it's present, or try to get clever activly suppressing it.

Was also the reason for linking the teensy hearing aid, since there the designer is trying to extract speech from the background.

Given the questions you may also want to look at supercollider or similar computer based audio tools and try to build your filter there where seeing what you did is much easier, then look to implement said filter into the teensy. Also means a much greater pool of answers to fire a search engine into.
 
would you happen to know how the StateVariableFilter works?

Perhaps you're thinking of the Mozzi library? It's a completely separate library from the Teensy Audio Library.

You can use either of these on Teensy, but they aren't designed to work together, so it's important to understand they are not the same code base or even compatible with each other in any way.
 
"speed can be any from the ADC_SAMPLING_SPEED class enum: VERY_LOW_SPEED, LOW_SPEED, MED_SPEED, HIGH_SPEED or VERY_HIGH_SPEED.
ADC_SAMPLING_SPEED::VERY_LOW_SPEED is the lowest possible sampling speed (+24 ADCK). (ADCK is the ADC clock speed, see below).
ADC_SAMPLING_SPEED::LOW_SPEED adds +16 ADCK.
ADC_SAMPLING_SPEED::MED_SPEED adds +10 ADCK.
ADC_SAMPLING_SPEED::HIGH_SPEED adds +6 ADCK.
ADC_SAMPLING_SPEED::VERY_HIGH_SPEED is the highest possible sampling speed (0 ADCK added)."

I'm a little bit confused. Why does the very low speed gets the highest number of added ADCK? Also is there a specific value of ADCK to which you add the number based on the sampling speed you chose?

If I were to use a max of 2khz frequency, it's alright to use the 44 kHz sampling rate right? Since the nyquist theory states that it should at LEAST be 2x the max freq?


Lastly, (question's about filters, sorry if its far from the initial topic) what does stage and q means for this syntax in the filter example?

"biquad1.setLowpass(0,600,0.707); //stage, freq, Q"

thanks!
 
I'm new to this Forum, so forgive me if this is an old question. Being new, I do not know the URL for some of the libraries being discussed and where I can go to downloaded them, like:

#include <MozziGuts.h>
#include <Oscil.h>
#include <tables/whitenoise8192_int8.h>
#include <StateVariable.h>


I have a convention of placing the URL for non-standard libraries after the #include directive, like:

#include <EEPROM.h> // Standard with IDE
#include <SD.h> // Standard with IDE
#include <Wire.h> // Standard with IDE
#include <SPI.h> // Standard with IDE
include <Encoder.h> // https://github.com/PaulStoffregen/Encoder
#include "MorseCode.h" // Part of this project file. MUST be in same directory as this source file


As a newbie, should I know where the above-mentioned libraries are?
 
Last edited:
This might be helpful for your project. It is starts with low noise. I can probably help you with the signal processing also.

https://forum.pjrc.com/threads/53173-queued-USB-DAQ-with-the-Teensyhttp://

We ended up with a very nice DSP project as an addition to the µBITX amateur radio transceiver. The Teensy 3.6 and the audio board handle all of the touch screen tasks, digital processing, IF and audio filters, electronic keying and other tasks. Our rig looks like this:

SmallJackAl.jpg

11,000+ lines of code and the Teensy just plows right through it.
 
Status
Not open for further replies.
Back
Top