Detect frequency from microphone Java - java

I would like to make a program that can transfer data as pulses of a certain frequency but am unsure on how to detect if a frequency is present.
I would assume I need to filter out all unneeded frequencies but I can't seem to find anything on how to do this.
Are there any libraries that already do this or would I have to build my own? Are there any examples of this or something similar being done?

It looks as though you're trying to implement a Modem, and would be well advised to look at the proven modulation techniques used for this purpose - usually QPSK and QAM. The technique you imply in your question is a crude from of amplitude modulation - essentially modulating a carrier of a given frequency with a bit-stream. Heterodyning might be a good place to start when demodulating this. Using an FFT will yield poor results because of the sampling effect of windowing, which will result in a poor bandwidth.
Another practical problem you will face once you've demodulated the signal is clock recovery. It is highly probable that the original bitstream clock will be asynchronous with the sample clock at the receiver. In order to decode the data-stream, you will need to recover the sender's clock (that is to say, the relationship between it and a local clock). A Phased Lock Loop is the usual way of achieving this.
You will also need to work out how to detect the start of the bit-stream - e.g. some kind framing.

You'll want to apply a Fourier transform to the signal data to look it in the frequency domain. JTransforms is an open source library you can use to do that.

Related

Advice on ultrasonic transmission protocol

I am working on an application that will receive ultrasonic waves and it will perform different actions based on the input. At some point, I am going to need that this ultrasonic waves to be unique for my application in the sense that I don't want other waves to interfere. Can you please give me some guidance on the protocols for making a wave sound "unique"? There are commercials applications for that like cue audio. I am planning to write the application using Android. Thanks in advance.
"Direct sequence spread spectrum" (DSSS) transmission is used to make communication resistant to jamming and interference, which seems to cover your use case as well.
It's reasonably easy to implement digitally. See: https://en.wikipedia.org/wiki/Direct-sequence_spread_spectrum
This might be more of a dsp question, but you could use frequency shift keying, where you encode a pattern as a series of frequencies and then recover them: https://www.tutorialspoint.com/digital_communication/digital_communication_frequency_shift_keying.htm
If its for rangefinding, have a look at chirp signals used in radar: http://www.dspguide.com/ch11/6.htm Not exactly what you asked I know but probably of interest as well. These are commonly used in radar systems.

Does any know how to extract a tensorflow DNNRegressor model and evaluate manually?

I am trying to use a DNNRegressor model in a java realtime context, unfortunately this requires a garbage free implementation. It doesn't look like tensorflow-light offers a GC free implementation. The path of least resistance would be to extract the weights and re-implement the NN manually. Has anyone tried extracting the weights from a regression model and implementing the regression manually, and if so could you describe any pitfalls?
Thanks!
I am not quite sure if your conclusion
The path of least resistance would be to extract the weights and re-implement the NN manually.
is actually true. It sounds to me like you want to use the trained model in an Android mobile application. I personally do not know much about that, but I am sure there are efficient ways to do exactly that.
However, assuming you actually need to extract the weights there are multiple ways to do this.
One straight forward way to do this is to implement the exact network you want yourself with Tensorflows low level API instead of using the canned DNNRegressor class (which is deprecated btw.). That might sound unnecessarily complex, but is actually quite easy and has the upside of you being in full control.
A general way to get all trainable variables is to use Tensorflows trainable_variables method.
Or maybe this might help you.
In terms of pitfalls I don't really believe there are any. At the end of the day you are just storing a bunch of floats. You should probably make sure to use an appropriate file format like hdf5 and sufficient float precision.

Identify sound clip in a wav file using Java

I am working on a personal project. Basically I have a collection of small sound clips, like a clap or a beep noise. I want to create a program that listens for the sounds via a mic or some form of audio input, and when I play sound clip it should identify that clip.
I have tried looking into this myself and have found this article.
http://www.redcode.nl/blog/2010/06/creating-shazam-in-java/
I tried replicating it, but I have found that it doesn't work as expected. I am guessing the sound clips I am using to create my hash from are too small to create enough values to compare.
Wondering if there any well know programs or algorithms that are capable of doing this.
Dan Ellis' slides are probably a good start. They explain the principal task of audio fingerprinting and the two best known approaches:
The Shazam algorithm by A. Wang (paper)
The Philips (now Gracenote) algorithm by Haitsma/Kalker (paper)
As you have already tried the landmark (Shazam) approach, perhaps it's worth your time to fiddle around with the stream-based approach. Since your queries are very short, you might also want to tweak the analysis frame length and overlap. Shorter frames and greater overlap may improve your results for very short samples. If you want to delve even deeper into the Haitsma/Kalker algorithm, you might also be interested in this unfortunately paywalled paper (by me).

Detect frequency of audio input - Java?

I've been researching this off-and-on for a few months.
I'm looking for a library or working example code to detect the frequency in sound card audio input, or detect presence of a given set of frequencies. I'm leaning towards Java, but the real requirement is that it should be something higher-level/simpler than C, and preferably cross-platform. Linux will be the target platform but I want to leave options open for Mac or possibly even Windows. Python would be acceptable too, and if anyone knows of a language that would make this easier/has better pre-written libraries, I'd be willing to consider it.
Essentially I have a defined set of frequency pairs that will appear in the soundcard audio input and I need to be able to detect this pair and then... do something, such as for example record the following audio up to a maximum duration, and then perform some action. A potential run could feature say 5-10 pairs, defined at runtime, can't be compiled in: something like frequency 1 for ~ 1 second, a maximum delay of ~1 second, frequency 2 for ~1 second.
I found suggestions of either doing an FFT or Goertzel algorithm, but was unable to find any more than the simplest example code that seemed to give no useful results. I also found some limitations with Java audio and not being able to sample at a high enough rate to get the resolution I need.
Any suggestions for libraries to use or maybe working code? I'll admit that I'm not the most mathematically inclined, so I've been lost in some of the more technical descriptions of how the algorithms actually work.
If you are aiming at detecting frequency pairs then your job is very similar to a DTMF detector.
Try searching for DTMF in places like sourgeforge, you'll find detectors in many programming languages. The frequency pairs placing along the spectrum seems to be even more stringent than your specs so you should be fine adapting a DTMF detector to your input.
Check out SNDPeek, its a cross-platform C++ application that extracts all kinds of information from live audio; https://github.com/RobQuistNL/sndpeek

Audio analyzer for finding songs pitch

Is there anyway to analyze the audio pitches programmatically. For example, i know most of the players show a graph or bar & if the songs pitch is high # time t, the bar goes up at time t .. something like this. Is there any utility/tool/API to determine songs pitch so that we interpolate that to a bar which goes up & down.
Thanks for any help
Naive but robust: transform a modest length segment into Fourier space and find the peaks. Repeat as necessary.
Speed may be an issue, so choose the segment length as a power of 2 so that you can use the Fast Fourier Transform which is, well, fast.
Lots of related stuff on SO already. Try: https://stackoverflow.com/search?q=Fourier+transform
Well, unfortunately I'm not really an expert on audio with the iPhone, but I can point you towards a couple good resources.
Core Audio is probably going to be a big thing in what you want to do: htp://developer.apple.com/iphone/library/documentation/MusicAudio/Conceptual/CoreAudioOverview/Introduction/Introduction.html
As well, the Audio Toolbox may be of some help: htp://developer.apple.com/iphone/library/navigation/Frameworks/Media/AudioToolbox/index.html
If you are have a developer account, there are plenty of people on the forums that can help you: htps://devforums.apple.com/community/iphone
You'll have to add in a 't' in the http portion of those URLs, as I cannot post more than one hyperlink (sorry!).
To find the current pitch of a song, you need to learn about the Discrete Time Fourier Transform. To find the tempo, you need autocorrelation.
I think what you may be speaking of is a graphic equalizer, which displays the amplitude of different frequency ranges at a given time in an audio signal. It normally equipped with controls to modify the amplitudes between the given frequency ranges. Here's an example. Is that sort of what you're thinking of?
EDIT: Also, your numerous tags don't really give any indication of what language you might be using here, so I can't really suggest any specific techniques or libraries.

Categories