A few questions regarding FFTs and performance

Status
Not open for further replies.

Foaly

Member
Hello everybody!

I have some technical questions about the Teensy 3.6 in combination with the audio shield.
So I would like to do quiet lot of big FFTs, then do some spectral processing and finally iFFT the signal. If possible I would like to do it in real time, but if thats not possible at least somewhat online. I am aiming at a FFT size of 4096. Is that even in the realm of possibilities? The code and benchmarks I've red so far mostly use 512 or 1024 samples.
I know I have to write the FFT/iFFT classes myself and I understand it has to be as fast as possible, but I am wondering whats available for this purpose? Can I use the floating point unit for this and if so how? Are there SIMD instructions available?
From the code/forum posts I've been reading so far (mostly the analyze_fft1024 in the Audio lib, Teensy-ConvolutionSDR, Teensy-FFT-Convolution-Filter) most implementations seem to use the CMSIS library, which to my understanding seems to be something like an abstraction library over different ARM chips offering an interface to performance critical operations. Is that correct? In the past there seemed to be different discussions about what version of the library to use. I was unable to find the version of the library currently in use on the Teensy 3.6 (with Arduino 1.8.5 + Teensyduino 1.41). Where is this lib bundled anyway? I couldn't find it in the anywhere... :D
Another thing I was wondering is that I saw a lot of arm_q15_to_float or similar functions containing q15 in the above mentioned code. This got me confused. What data format is the Teensy using internally? I always assumend its int16_t, but I couldn't find documentation verify that anywhere. Also whats the advantage of using q15 over f32? Wouldn't floats be faster and more accurate? Or am I overlooking something here?
I was planning on using arm_cfft_f32 with arm_cfft_sR_f32_len4096 for my purposes, but with so many open questions I would like to hear from some people, who maybe have already spent a lot of time with this. I know this is quiet a lot of questions, but maybe somebody can shed some light on my confusion :D
Thank you very much in advance,
Foaly
 
Hi Foaly,

I think you are definitely on the right track. You need to use floating point, one of the new versions of the CMSIS library and maybe Brians Convolution filter routine (which already has all implemented that you probably need . . . or you program the FFTs by yourself, if you like to do so ;-)).

But in order to help you, we need more info about what kind of real time data you have, why you need such an enormously huge FFT and so on.

BTW, a real-time 4096-point FFT/iFFT chain is no problem for the Teensy 3.6 & audio shield [but definitely not with a sample rate of 192ksps ;-)]. It depends on your needed sample rate and on your processor load for the real time "spectral processing", which we do not know about.

All the best,

Frank DD4WH
 
Weeeeeeelllll hahaha :D I was actually planning on using 192kHz as sampling rate...
Thanks for the fast answer! Good to know I'm kinda on the right track. So what I want to do is to record ultra sound (at 192kHz for a resolution of 0-81kHz) and then transpose/scale it down to the audible range. In order to do so I would like to use a phase vocoder. A phase vocoder basically uses a FFT to go from time domain to frequency domain, then does some spectral processing and finally uses the iFFT to go back to time domain. The spectral processing you were asking for is in the most basic case simply shifting the frquency bins down. More advanced algorithms do $stuff$ to preserve formats or even better algorithms also preserve transients. I was being vague, because I still don't know what I can implement, it depends on how much processing power is left. So yeah the goal is to make ultrasound audible.

If you are suggesting using the CMSIS library is the way to go, then maybe you could explain to me where it is bundled/built/linked, what the current version is and which version I should use? :)
Thanks,
Foaly
 
Hi Foaly,

it would be absolutely awesome to have someone program pitch shifting/phase vocoder!

But for your goal, I think you could have it much easier ;-).

Two years ago, I programmed a bat detector, which does approximately what you want:

- record ultrasound at a sample rate of 192k --> however, not entirely reliable at that speed
- playback the ultrasound at lower sample rates to make it audible
- additionally it mixes (heterodynes) the incoming ultrasound with a local oscillator, so that the difference frequency can be heard in realtime --> the standard way of detecting bats = heterodyne detector
- it also display the sound on a spectrum display in real time

https://github.com/DD4WH/Teensy-Bat-Detector

Maybe that is useful for your purpose?

The advantage of playback at lower speed is that the sound is not just linearly shifted down a fixed frequency, but also scaled, so that with playback at 1/10th of the speed, the whole ultrasound frequency span from 20k to 100k is shifted into the audible band --> 2kHz to 10kHz. AFAIK, that is not the case with pitch shifting.

Considering your approach with the FFT-vocoder algorithm-iFFT --> I would love to see that implemented, but I doubt the Teensy would be fast enough to do that AND additionally record in realtime . . . but hopefully you can prove me wrong ;-).

All the best,

Frank DD4WH

P.S.: and this is how the heterodyne bat detector works:
https://github.com/DD4WH/Teensy-Bat-Detector/wiki/Software
 
For a single channel you should be possible to do the two real valued 1024 point FFT. You may have to run the T3.6 at 240 MHz.
The audioshield, however, may not be of use. The SGTL5000 goes only up to 96 kHz sampling.
 
The SGTL5000 goes only up to 96 kHz sampling
Yes, you are right, the data sheet allows up to 96kHz. At the moment I overclock mine as high as 234ksps for FM wideband reception ;-). But that is not recommended, because it could damage the chip!?

Have fun with the Teensy,

Frank
 
Hi Frank,

thanks for pointing me to your project. I have already seen it and it's what convinced me to buy the Teensy 3.6 + audio shield and try it for my project! :) really cool stuff! I've just got around to upload my code as well. I've already done something similiar to what you are suggesting. I've implemented a Downsampler, which simply down samples the 192kHz signal to a 24kHz signal. This shifts the ultrasonic frequencies into the audible domain, but it also introduces time streching (it shortens the signal). If you're interested you can find the code here: https://github.com/Foaly/UltrasonicHearing
For my purposes I'm mostly interested in sound quality and don't need recording. Thats why I though using a phase vocoder would yield the best results. I haven't heared of the Heterodyne technique. Very interesting and I will read up on it!
I guess I will have to play with all the parameters to see whats the best balance between performance/quality. But before implementing I wanted to check with people more experienced with using the Teensy whats the right way. The microphone I plan on using uses a PDM digital input which according to the code comments should use about 20% CPU @ 180MHz... It has the flatest frequency response though :D

@WMXZ: Thanks for the tip about overclocking. I didn't think of that yet. I assume I would also have to put on some sort of passive cooling on the CPU. The SGTL5000 has taken the overclocking to 192kHz very well in my tests so far.


I was able to uncover whats behind the arm_q15_to_float functions. According to this doc the function arm_q15_to_float converts a int16_t to float and not a q15 fixed point int to float as I imagined from the name. As always RTFM helps... :D

If somebody has any more insides or is able to pick up any of the other questions, I would be very grateful :)
Foaly
 
@WMXZ: Thanks for the tip about overclocking. I didn't think of that yet. I assume I would also have to put on some sort of passive cooling on the CPU. The SGTL5000 has taken the overclocking to 192kHz very well in my tests so far.

Any experience on the spectral ADC noise floor 192 kHz re 96 kHz say 100 Ohm resistor on input?
 
Sorry, I don't quiet understand the question. So for the first tests I have used a cheap, shitty EMY-62NL101 electret mic which only goes up to 12k. That one is quiet noisy when used with the Teensy Audio shield mic input. (could be because its cheap, could also be how I set the mic gain, not so experienced with how the audio shield behaves yet...)
For the higher sample rates and the ultra sonic reception I used a KPUS-40T-16R-K769 which is a super cheap ultrasonic transducer and only has a range of 40kHz +- 1kHz. So its also shitty, but enough for some preliminary testing. With that + my downsampler I also had quiet some noise, but I suspect my downsampling algorithm has a large part in that.
Does that help you at all? I am wondering what would the 100Ohm resistor do? Also how could I measure the noise floor?

Ultimatly I want to use MEMS ultra sound microphones. I just received some today. I will try SPU0410LR5H-QB for now. First challange will be to hook them up to the Teensy. They are TINY! :D

For the algorithm I will go with a highpass at 20k, then use a ring modulator (heterodyning) and then low pass filter the additional side band away. Eventually I still want to use a phase vocoder, because the side band processing is only a frequency shift and not a pitch shift, meaning it will destroy the harmonic relationship between sounds (affecting the timbre). But the other technique is easier to implent, so I can keep the progess going for now :) Thanks again @DD4WH for pointing this out to me!
 
Hi Foaly,

looks like you are making progress fast!

Could you explain your downsampling a little bit more? I fail to understand what you are doing in your code. As I have understood it, downsampling is a process of taking every n-th sample and discarding all the others. In order to be useful, you would have to lowpass before downsampling to prevent aliasing. But I do not get how you can transform ultrasound to audible sound by downsampling?

For the heterodyning you are probably only interested in the difference frequency of your local oscillator and your ultrasound signal (eg. 45kHz minus 44kHz = 1kHz) and you can ignore the sum (45 + 44 = 89kHz), which you cant hear anyway . . . So a lowpass filter after heterodyning is not necessary. What do you mean by ring modulator? You just need a software LO and a software mixer . . .

What kind of ultrasound signals are you interested in?

I would be very interested in your experience with the SPU0410LR5H-QB !

Have fun with the Teensy,

Frank
 
Does that help you at all? I am wondering what would the 100Ohm resistor do? Also how could I measure the noise floor?
What I mean, if you use a resister (e.g. a 100 Ohm) on the ADC input to AGND, the results you get reflects the thermal noise generated by the small current through the resistor.
what one would expect is that the spectral noise power/frequency band is independent of the bandwidth chosen (46 kHz for 96 kHz sampling and 96 kHz for 192 kHz sampling). If the spectral noise is not the same, then the performance of the ADC is changing (mostly to the worst).
Of course the ADC could be so bad that it does not measure the noise od the resistor but only presents the ADV internal noise, then increasing the resistor to a higher value may be necessary. So a couple of tests could be necessary.
 
Hi,

I was just searching the net for people using Teensy and trying to hear/record/visualize ultrasonic audio and saw your thread. I am currently still using/working on more standard bat-detector using the analog heterodyne technique but using a computer is a very attractive step upwards.

I have good experiences with the SPU0410LR5H-QB microphone, in Germany this microphone is available on an easy to use board from https://www.elv.de/elv-mikrofon-mems1-bausatz.html

kind regards
Cor
 
Hi,

I was just searching the net for people using Teensy and trying to hear/record/visualize ultrasonic audio and saw your thread. I am currently still using/working on more standard bat-detector using the analog heterodyne technique but using a computer is a very attractive step upwards.

I have good experiences with the SPU0410LR5H-QB microphone, in Germany this microphone is available on an easy to use board from https://www.elv.de/elv-mikrofon-mems1-bausatz.html

kind regards
Cor

Additionally: I was wondering if anybody thusfar has tried using a preamp-setup to improve the frequencyresponse. In the "hardware" based detectors many people are using the preamp from this design http://bertrik.sikken.nl/bat/ne612het.htm

I am sure the same can be done using an opamp but this setup is tried/tested, ive made several of these thusfar (with minor changes in the preamp but larger changes in the microphones).

regards
Cor
 
Hi Frank,
Thanks! Yes well in theory I should be able to explain why downsampling also introduces a frequency shift, as I did learn this is university... but I can't remember properly. You are definitly right that a proper downsampler has to do a LP filter to avoid aliasing. The code I wrote worked, but doesn't do that and is a crude approxiamtion, that probably shouldn't be used :D
I have now moved on to the heterodyning technique you suggested. In the DSP world this is also called ring modulation. I think the name heterodyning comes from the old analog electrical engineering days and ring modulation is more of a recent digital DSP term, but I'm not a linguist, so don't quote me on this one :D Any way I can highly recommend the book "DAFX: Digital Audio Effects" published by Udo Zölzer (ISBN: 978-0470665992) which gives an overview over a ton of DSP techniques and quotes the current DAFX papers describing them. It helped me understand ring modulation/heterodyning better.

Arrgh! @Cor If I only I had known that link to the break out board... I even looked around for them, but must have missed it. Anyway I soldered one myself.
MEMs.jpg
Like I said... they are REALLY tiny (2 euro cents for scale).

So far the results have been okish. I used the SPU0410LR5H-QB with the microphone input. I received sound in the ultrasonic range, which I have successfully made audible using the ring modulation. But the signal is really quiet. Compared to the cheap and narrow banded capsule (KPUS-40T-16R-K769) I used before, the signal is really, really weak. Even with the mic gain set to 60 its sometimes hard to make out the signal. So since its an analog signal I thought I could use an operational amplifier to boost the signal. I used a TL-072 and I tried both an inverting and a noninverting amplifier with different amplification factors, but I couldn't get it to work properly. Using my scope the output of the opamp looks fishy to me, but unfortunatelly my electical engineering voodoo is not that high... (The mic is powered from the 3,3V of the Teensy via USB and the 9V for the TL-072 comes from a lab power supply, so maybe they have a different ground potential... although I don't know...)

Here is the opamp test setup:
OPV.jpg

I will try and see if I can get an analog amplification to work. Like I mentioned earlier I also ordered some SPH0641LU4H-1 which is the same component, but with a digital output. This will burn a lot of CPU cycles when converting from the PDM format to something usable by the teensy, but I imagine the amplification can be easier done in software (for me at least, as I am a programmer :D)

As for what kind of signals I am interested: all ultrasonic signals really! In the end I would like to use this as an extended sense in a way. This is also why I am interested in keeping the harmonic realtions in the signal preserved :) I did a lighning talk at this years Linux Audio Conference in Berlin, where I discribed my project. You can find a recording at Media CCC. It was a bit rushed though and I'm only just starting out... But I will do a proper blog post / explanation once I have a prototype which works satisfyingly.

@WMXZ: Ah I actually didn't think of that yet! Very good point! Since I am currently still totally in the prototyping phase of my project I am still concerned with getting any signal processed and through to my output... :D But I will definitly keep this in mind once I get to the point of optimizing the audio quality! If I interpret your results overclocking the SGTL5000 from you other thread, the SNR at 192 kHz is not actually any worse than at regular 44.100, right?
 
If I interpret your results overclocking the SGTL5000 from you other thread, the SNR at 192 kHz is not actually any worse than at regular 44.100, right?
Yes, only the (relative) transition band seems for 192/240 kHz not as sharp for 44.1 or 48 kHz
 
Hi

Ive also just tried the SPU0410LR5H on my Teensy3.6 (using the batdetector project from Frank DD4WH). Compared to my analog bat-detector which uses an analog preamp the signal was really weak. I have a ultrasonic transducer with default frequency at 40Khz that I use as a signal(it can be used to send a sweep from 30-70Khz). Using my normal bat-detector I can hear the signal meters away, using the built-in preamp of the SGTL its hardly a meter. So I will start using a preamp on this now.

Cor
 
Hi Cor, hi Foaly,

thanks a lot for the hint on availability of the mic at ELV!

I ordered a bunch and made some experiments. I used the SMD-mic preamp also available at ELV

https://www.elv.de/smd-mikrofonvorverstaerker-komplettbausatz.html

However, I used a different OP-amp TL972, because the original TL072 does not work with 3.3Volts Vdd. I also changed some components for the cutoff frequency of the lowpass filters, so that ultrasound comes through.

Yes, the signal is weak even with the preamp! But the sound is quite clear, only some noise and some spurs visible in the spectrograms. With the help of the microSoundRecorder by WMXZ, I managed to record and identify three species of bats in my backyard last night [Teensy 3.6, sample rate 320ksps, SPU0410LR5H-QB mic & ELV preamp with TL972] :).

You can find a sound example and a spectrogram here:

https://github.com/WMXZ-EU/microSoundRecorder/wiki/Sample-recordings

Will try to optimize the setup and report back here . . .

Have fun with the Teensy,

Frank
 
Last edited:
@WMXZ: Thats great news. Thanks for confirming! And thank you again for making the effort of testing the chip and sharing your results! Much appreciated!

@CorBee: That is very interesting! So our results seem to line up :D If you have a working design/schematic for a pre-amp I would be very interested in trying it out! Also I would be interested in how you create the sweeps from 30-70kHz? Until now I used a ultrasonic distance sensor with only fires bursts at 40kHz. Sweeps would be much nicer.
 
Hi Frank!

Thats fantastic news! Congratulations! Sounds like you're getting some nice results. Maybe I will give the mic preamp you linked a try. Smart idea to take 3,3V opamp! :rolleyes: I had a quick look in the data sheet. I was told that for amplifying signals in the ultrasonic range the slew rate of the component was an value to pay attention to. I see that the TL072 has a (appently high) value of 13 V/μs while the TL972 you picked has a value of 5 V/μs. I have no feeling how low this number can be, before interfering. Again I would be also be very interested in the schematics/design which works best for you :)
Also what would you roughly estimate was the range of your current mic setup?

Greetings Foaly
 
@foaly: I have a TI stellaris launchpad around that I can program (using arduino) to push out a PWM based frequency. The transducer is a simple monacor 40Khz UST. Thats a device with a best response at 40Khz but you can use other frequencies easy. You dont need anything more than a simple PWMWrite command in a loop to create a sweep. On my board its directy connected to a datapin without any capacitor decoupling or so.
 
Hi Frank,

Nice from you to chime in ! Can you share how you connected your preamp ? I have tried using the preamp (double transistor amplifier with frequency highpass filtering) I normally use but I am ending up in a weird problem. WHen I use the 3.3V line from the teensy I get loads of disturbance and hardly any signal from my preamp. When I power the preamp external (battery) and create a common GND with the teensy I get a clean amplified signal from the preamp.

Cor
 
HI all,

I dont know who is trying the heterodyne setup next to Frank and me. But I found out that using AudioSynthWaveformSineHires instead of AudioSynthWaveformSine for the oscillator seems to give a better signal. I wonder why.

Cor
 
I was told that for amplifying signals in the ultrasonic range the slew rate of the component was an value to pay attention to. I see that the TL072 has a (appently high) value of 13 V/μs while the TL972 you picked has a value of 5 V/μs. I have no feeling how low this number can be, before interfering. Again I would be also be very interested in the schematics/design which works best for you :)
Also what would you roughly estimate was the range of your current mic setup?

I am not a specialist in OP amps, so I do not know what a slew rate is . . .

You can find the schematics in an old ELV journal article under the link above (you have to pay 50ct for it, so I cant post it here).

I may be misinterpreting your question on the "range", but the frequency span of the mic seems to be from audible audio to roughly 100kHz, at least I could identify bat calls in the range from 24kHz up to 100kHz in last nights´ recordings. But I have no idea how flat the frequency response is.
 
WHen I use the 3.3V line from the teensy I get loads of disturbance and hardly any signal from my preamp. When I power the preamp external (battery) and create a common GND with the teensy I get a clean amplified signal from the preamp.

Also corresponds with my observations. You could also filter the 3.3V from the Teensy with a series 2K2 resistor, a 10µF cap to GND, then another 2K2 series resistor and another 10µF to GND. But probably using a separate power supply (battery) for the preamp should be even better.
 
Also corresponds with my observations. You could also filter the 3.3V from the Teensy with a series 2K2 resistor, a 10µF cap to GND, then another 2K2 series resistor and another 10µF to GND. But probably using a separate power supply (battery) for the preamp should be even better.

Thanks for that info. I was allready hopeing it would be a power-decoupling issue. Not clear how you ment the decoupling exactly. Attached is my current setup in the analog detector. The R1/R2 is not needed for the teensy as its a resistor-dividor to bring my 5-6V down to <3.6V for the SPU-MEMS microphone.
You suggest to connect from my +rail to 3.3V on the teensy using a 2k2, you use the 10uF (higher is also OK i guess) on the preamp-side after the 3.3V series resistor to GND ? And where would you put the other 2K2 and 10uF ? My "real" electronics skills arent very developed so I need some guidance.

Thanks in advance



Screenshot from 2018-06-17 21-33-39.png
 
Status
Not open for further replies.
Back
Top