Un-matched SampleRate for NAO Record Buffer - wav

I am working on the process in denoise in a NAO robot for a sound localization. I call the "setClientPreferences" module with 48000kHz sample rate in all channels (interleave) for recording:
channelFlag = 0
deinterleave = 0 # deinterleave = 1
sampleRate = 48000
audio.setClientPreferences(self.getName(),sampleRate,channelFlag,deinterleave)
and obtain the buffer data by this function:
def processRemote(self,numChannels,samplesPerChannel,timeStamp,buffer):
print "channels=",numChannels," samples=",samplesPerChannel
soundDataInterleaved = np.fromstring(str(buffer),dtype=np.int16)
self.soundData = np.reshape(soundDataInterleaved,(numChannels,samplesPerChannel),'F')
The problem comes when I try to recover the data into wav file in the same sample rate (48000) by python/matlab for testing, the result plays faster than what I have recorded, but sounds more regular when it is set to be half of the sample rate (24000). The same problem exists when I set the rate to 16000kHz at first.
How can I solve this problem? It is really important as I need the accurate sample rate to apply spectrum cubtraction.
Also I am confused about the sample numbers for a single channel, which also described in here.
Thankyou!

Related

Converting between MIDI channel volume and real gain

What is the recommended way of mapping MIDI channel volume to gain?
From here [1]
It is recommended that a device use the volume value in a logarithmic manner, as specified by the following formula if only the coarse value is used:
40 log (Volume/127)
To me, this formula looks like an inverse formula. If channel volume is given in dB, then the formula should use exp instead of log. If volume already is an amplitude, then there should only be Volume/127. To clarify, this does not make sense
*output_buffer = 40*log(channel_volume/127.0) * (*input_buffer);
(Testcase: channel_volume=0 will give infinite gain) The following on the other hand is better (provided that channel_volume is the real gain and not the gain in dB):
*output_buffer = channel_volume * (*input_buffer)/127.0;
[1] http://www.blitter.com/~russtopia/MIDI/~jglatt/tech/midispec/vol.htm
The MIDI specification itself does not specify the volume response.
However, the General MIDI Level 1 Developer Guidelines show this formula, because it's actually used by most implementations.
The channel volume is given as a value from 0 to 127.
The result of that formula is measured in dB; you have to convert it into a gain value afterwards:
gain = 10 ^ (dB / 20)
See the same document for how to handle interactions with the expression controller.

How to use the EMG Raw Data in Myo Armband

I'm working on a project to try to recognize some movements/poses for use in rehabilitation therapy using Myo Gesture Control Armband.
I have three questions:
Which is the maximum and minimum value that EMG Raw Data returns?
How do you interpret the EMG Raw Data?
The minimum value returned by the EMG Raw Data is for a relaxed muscle and the maximum value is a fully contracted muscle?
PS1: Question in Myo Developer Forum
PS2.: The most important to me is learn how interpret the EMG Raw Data. With some didactic sample. I want to create my own gestures.
This is from my looking results and understanding:
EMG Raw Data return value from -128 to 127 (8-bit value).
We don't really know what is EMG Raw Data. We can't say it's mV directly from muscles intensity. Sensors measure mV and convert to 8-bit data.
This is signal. Around 0 is "relaxed muscle" not minimum. But converting from mV to 8-bit data can make strange values too. Soo 2. and 3. question I can't really answer how it's work, because Myo don't show own hardware for converting values (or I don't find that).
I recommend visit Myo diagnostic page and see what happend in EMG graphs while you relaxed and contracted muscle.

i don't really understand FFT and sample rates

Im really confused over here. I am a ai programmer working on a game that is designed to detect beats in songs and some more. I have no previous knowledge about audio and just reading through whatever material i can find. While i got fft working and stuff I simply don't understand the way samples are transferred to different frequencies. Question 1, what does each frequency stands for. For the algorithm i got. I can transfer for example 1024 samples into 512 outcomes. So are they a description of the strength of each spectrum at the current second? it doesn't really make sense since what i remember is that there are 20,000hz in a 44.1khz audio recording. So how does 512 spectrum samples explain what is happening in that moment? Question 2, from what i read, its a number that represent the sound wave at this moment. However i read that by squaring both left channel and right channel, and add them together and you will get the current power level. Both these seems incoherent to my understanding, and i am really buff led so please explain away.
DFT output
the output is complex representation of phasor (Re,Im,Frequency) of basis function (usually sin wave). First item is DC offset so skip it. All the others are multiples of the same fundamental frequency (sampling rate/N). The output is symmetric (if the input is real only) so use just first half of results. Often power spectrum is used
Amplitude=sqrt(Re^2+Im^2)
which is the amplitude of basis function. If phase is needed then
phase=atan2(Im,Re)
beware DFT results are strongly dependent on the input signal shape,frequency and phase shift to your basis functions. That causes the output to vibrate/oscillate around the correct value and produce wide peaks instead of sharp ones for singular frequencies not to mention aliasing.
frequencies
if you got 44100Hz then the max output frequency is half of it that means the biggest frequency present in data is 22050Hz. The DFFT however does not contain this frequency so if you ignore the mirrored second half of results then:
for 4 samples DFT outputs frequencies are { -,11025 } Hz
for 8 samples frequencies are: { -,5512.5,11025,16537.5 } Hz
The output frequency is linear to its address from start so if you got N=512 samples
do DFFT on it
obtain first N/2=256 results
i-th sample represents frequency f=i*samplerate/N Hz
where i={ 1,...,(N/2)-1} ... skipping i=0
the image shows one of mine utility apps tighted together with
2-channel sound generator (top left)
2-channel oscilloscope (top right)
2-channel spectral analyzer (bottom) ... switched to linear frequency scale to make obvious what I mean in above text
zoom the image to see the settings ... I made it as close to the real devices as I could.
Here DCT and DFT comparison:
Here the DFT output dependency on input signal frequency aliasing by sampling rate
more channels
Summing power of channels is more safe. If you just add the channels then you could miss some data. For example let left channel is playing 1 Khz sin wave and the right exact opposite so if you just sum them then the result is zero but you can hear the sound .... (if you are not exactly in the middle between speakers). If you analyze each channel independently then you need to calculate DFFT for each channel but if you use power sum of channels (or abs sum) then you can obtain the frequencies for all channels at once , of coarse you need to scale the amplitudes ...
[Notes]
Bigger the N nicer the result (less aliasing artifacts and closer to the max frequency). For specific frequencies detection are FIR filter detectors more precise and faster.
Strongly recommend to read DFT and all sublinks there and also this plotting real time Data on (qwt) Oscillocope

50hz Sine lookup table using PWM

Can someone please guide me how to generate lookup table for generating 50 hz sine wave using PWM in Atmega32.
This is what i have done so far but confused of what to do.
50 Hz sine wave so 20 ms time period
256 samples (No. of divisions)
step i need to increase = 20 ms/256 = 0.078125 ms (Period of PWM signal)
angle step rate = 360/256 = 1.40625
Amplitude of sine wave should be 1.
I think you are starting from the wrong end and getting lost because of that.
Ignoring the lookup table, can you generate a 50 Hz PWM signal usign explicit calls to sin() ? Good. Now the lookup table saves you those expensive sin calls. sin is a periodic function, so you need to store only one period (*). How many points that are depends on your digital output frequency, which is going to be much more than 50 Hz. How much more defines the number of points in your lookup table.
To fill your lookup table, you don't send the result of your PWM function to the digital output but youwrite it to the lookup table. To use the lookup table, you don't call the expensive function but you just copy the table entries straight to your output.
There is one common optimization: A since function has a lot of repetition. You don't need to store the send half, that's just the inverse of the first half, and the second quarter is just the first quarter mirrored.

Data propagation time (single link)

this is not Home work!
I preparing my self to test in Networking :
i had this questen in the midterm test and i got half the points i cant figure it out
in this question i got reciver-sender connection.
link data rate is R(b/s)
Packet size is S(b)
Window Size is W(pkts)
Link distance is D(m)
medium propagation speed is p(m/s)
i need to write the utilisation Formula using those Letters
this is what i wrote:
Tp-Propagation time is D/p ===>this got me a big X on test page
i wrote that frame transmition (Tt) time is window size in bits (W*S)
divided by link Data Rate i.e (W*S)/R
thats why the formula is U=Tt/(Tt+2*tp)==>((W*S)/R)/(((W*S)/R)+2*(D/p))
(again X)
i guess somthing is wrong with the Propagation time calculation .
all the slides refaring to sliding window do not mention the utilisation
in referande to distance and propagation delay
i would love some help with this.
thank you .
It depends on how propagation time is supposed to be measured1, but the general formula is:
Propagation time = (Frame Serialization Time) + (Link Media Delay)
Link Media Delay = D/p
Frame Serialization Time = S/R
I don't see the relevance of TCP's sliding window in this question yet; sometimes professors include extra data to discern how well you understand the principles.
END-NOTES:
Does the professor measure propagation time at the bit-level or at the frame-level? My answer assumes it is a frame-level calculation (measured from first bit transmitted until the last bit in the frame is received), so I include frame serialization time.

Resources