unmatched sampling frequency of accelerometer and gyroscope - accelerometer

I'm working on the IMU of mobile phones. I need to get reading from accelerometer and gyroscope at the same time.
But I find their reading frequency isn't the same. How could I to retrieve reading from them at the same interval?
Actually, the first answer to this post also find the problem, but the guy doesn't give the solution.
Any help is appreciated!

Can't you just multiply the frequency of the accelerometer by the frequency of the gyroscope?
Imagine that f1 samples every four time units and f2 samples every three time units. If the sampling is regular and they begin to sample at same time they will meet every twelve time units.
e.g.
if the accelerometer has 40 samples every 5 seconds and the gyro has 1332 samples in the same amount of time.
to calculate the frequency:
the accelerometer has 40/5 = 8 samples per second
the gyro has 1332/5 = 266.4 samples per second
to calculate the period (in milliseconds):
the accelerometer samples every 1000/8 = 125 millisecond
the gyro samples every 1000/266.4 = 3.75 millisecond
therefore they will meet every 125 * 3.75 = 469 millisecond

Related

what is the purpose of the frequency domain analysis

I had assumed that this was going to output a set frequency buckets that I could use to do pitch detection (like aubio pitch). But that doesn't seem to be what it does. I fired up the voice-omatic app and using it frequency display played various notes through my mic. Bars appear, all at the left hand end, almost no distinction between high and low notes. I upped the FFT size just to see if that changed anything, seems not. I found a picthdetect js project and saw that it used analyzer ,aha, here I will find the correct usage, but the meat of the code doesn't use frequency domain output, it feeds time domain into its own algorithm. So to solve my problem I will use that library, but I am still curious what the freqency domain data represents
It does exactly what you think it does, but the specific implementation on that site is not great for seeing that.
The values are mapped differently than is nescessary for seeing changes in pitch between high and low vocal range because the range is mapped linearly, not logrithmically. If you were to map each frequency bin in a logarithmic way you would get a far more useful diagram. Right now the right hand 3/4 of the visualizer is showing from 5000hz to 20000hz (roughly), which contains very very little data in an audio signal compared to 0-5000hz. The root frequency of the human voice (and most instruments) occupies mostly between 100-1000hz. There are harmonics above that, but at reducing amplitudes the higher you get.
I've tweaked the code to tell you the peak frequency and the size of each bucket. Use this app.js: https://puu.sh/Izcws/ded6aae55b.js - you can use a tone generator on your phone to see how accurate it is. https://puu.sh/Izcx3/d5a9d74764.png
The way the code works is it calculates how big each bucket is as described in my answer with var bucketSize = 1 / (analyser.fftSize / analyser.context.sampleRate); (and adds two spans to show the data) and then while drawing each bar calculate which bar is the biggest, and then multiply the size of each bucket by which bucket is the biggest to get the peak frequency (and write it in el2). You can play with the fftSize and see why using a small value will not work at all for determining whether you are playing A2(110 Hz) or A2#(116.5 Hz).
From https://stackoverflow.com/a/43369065/13801789:
I believe I understand what you mean exactly. The problem is not with your code, it is with the FFT underlying getByteFrequencyData. The core problem is that musical notes are logarithmically spaced while the FFT frequency bins are linearly spaced.
Notes are logarithmically spaced: The difference between consecutive low notes, say A2(110 Hz) and A2#(116.5 Hz) is 6.5 Hz while the difference between the same 2 notes on a higher octave A3(220 Hz) and A3#(233.1 Hz) is 13.1 Hz.
FFT bins are linearly spaced: Say we're working with 44100 samples per second, the FFT takes a window of 1024 samples (a wave), and multiplies it first with a wave as long as 1024 samples (let's call it wave1), so that would be a period of 1024/44100=0.023 seconds which is 43.48 Hz, and puts the resulting amplitude in the first bin. Then it multiplies it with a wave with frequency of wave1 * 2, which is 86.95 Hz, then wave1 * 3 = 130.43 Hz. So the difference between the frequencies is linear; it's always the same = 43.48, unlike the difference in musical notes which changes.
This is why close low notes will be bundled up in the same bin while close high notes are separated. This is the problem with FFT's frequency resolution. It can be solved by taking windows bigger than 1024 samples, but that would be a trade off for the time resolution.

Canceling low frequency high amplitude noise signal

I am currently collecting data from a power meter Keysight N7744A to be exact. The issue is that over the course around every 5 minutes (after collecting an hour of data) the data fluctuate over 20%. My goal is to take a single measurement and being able to guarantee that it is within 5% (>0.25dB) of the true value which can be obtained by averaging over the period of 5 minutes. However, this will impact performance by too much... A measurement is collected in 400ms.
Any thoughts on how I can cancel this extra low frequency but high amplitude noise signal? Thanks!
I have attached the data just in case I couldn't explain myself. It has 10k data points collected over 1+hours where each measurements takes ~400ms. data.dat
Perhaps a high pass filter would work.

Using low frequency data to calibrate high frequency data

I have a 10 Hz time series measured by a fast instrument and a 1 minute time series measured by a slow reference instrument. The data consists of a fluctuating meteorological parameter. The slow reference instrument is used to calibrate the fast instrument measurements. Both time series are synchronised.
My idea:
Average the 10 Hz data into 1 minute blocks.
Take 5 one minute block from each time series and calculate the linear regression equations.
Use the regression equations to calibrate the 10 Hz data in 5 minute blocks (3000 data points).
What would be the best way to match (calibrate) the high frequency data using the low frequency data? I use MATLAB.
More background: The fast instrument outputs a fluctuating voltage signal while the slow instrument outputs the true value of a trace gas concentration in ppb (parts per billion). The slow instrument samples every ten seconds and outputs the average every one minute.
In short I would like to have my fast signal also in ppb but without losing it's integrity (I need the turbulent fluctuations to remain unfiltered), hence the need to use a linear fit.
Here's my approach and the results I got...
I modelled the problem as there being
a real (unmeasured by instruments) signal.
Let's call this real.
a slow signal - which is just the real signal sampled once a minute.
Let's call this lf (short for low frequency).
a fast signal - real signal + noise + signal drift.
Let's call this hf (short for high frequency).
The task was to take the slow and fast signals and try to reconstruct the real signal.
(Using least squares as a scoring metric)
Strategy:
Define a "piecewise linear filter" - this takes a signal, and returns a piecewise version of it. (With each piecewise part occurring where the slow signal is measured.)
NOTE: The slow signal is considered piecewise anyway.
Define a forwards-backwards low pass filter.
Define "uncertainty" to be 0 at the points where the low frequency signal is measured. It linearly increases to 1 when the timestamp is halfway between low frequency signal measurements.
Now, take your high frequency signal and filter it with the low pass filter.
Let's call this hf_lp
Take hf_lp and apply the "piecewise linear filter" to it.
Let's call this hf_lp_pl
Subtract the last two from each other.
I.e. hf_diff = hf_lp - hf_lp_pl.
You now want to find some function that estimates how by how much hf_diff should be added to the low frequency signal (lf) such that the squared error between real_estimated and real is minimized.
I fitted a function along the lines of real_estimated = lf + diff.*(a1*uncertainty + a2*uncertainty.^2 + a3*uncertainty.^3)
Use fminsearch or other optimization techniques to get a1, a2, a3...
Here is a sample plot of my results - you can see that real_estimated is much closer to real than the slow signal lf.
Closing thoughts...
The fast signal contains too much very low frequency (drift) and too much
very high frequency (noise) components.
But it has valuable medium frequency info.
The slow signal has perfect low frequency information, but no medium frequency info.
The strategy above is really just one way of extracting the medium frequencies from the fast signal and adding it to the low frequency signal.
This way, we get the best of all worlds: low frequencies, medium frequencies and low noise.

Pitch Period & Fundamental Frequency of Soundwave in MATLAB

I have just recorded a tiny section of audio in MatLab using the >> x = wavrecord( 2*fs, fs, ‘double’); command.
So far I have figured out how to playback the audio using soundsc(x, fs); and to plot to a graph using plot(x).
Here is a zoomed in screen capture of my wave:
Does the x-axis display the duration in milliseconds and the y-axis display the amplitude?
I think I may have switched off the axis names by accident.
I need to confirm this before i try to calculate the Fundamental Period and Fundamental Frequency of the wave.
If I've guessed my axis correct, am I right in thinking the fundamental period is the amount of time it takes for one periodic wave to repeat itself, making it (T)? So in this case approximately 0.0050 seconds?
And, the fundamental frequency is f0 = 1/T = 1/0.0050?
I have been playing around all day and reading so much. I hope i havent confused myself and just embarrassed myself on this site. Thanks.
Your x-axis is just sample number. This would go from 1 to the number of samples your sound recording contains. The sample time which is the time period between two samples is 1/fs. fs is your sampling frequency. So the time period for 50 samples would be 50/fs.
For most waveforms you cannot find Fundamental period easily by looking at it. As #duffymo mentions you need to compute FFT or PSD and then find the location of your first peak which is not DC. This would be your fundamental frequency.
This time trace looks pretty noise to me. It's not "frequency"; it's "frequencies".
If you do an FFT on this, you'll find that there are lots of frequencies involved. You may be able to reproduce the main signal with a smaller number of harmonics, but I doubt that it'll be just one.

Explanation of the details of an accelerometer data sheet

i'm working on samsung galaxy accelerometer SMB380.
This is the data sheet: http://www.bosch-sensortec.com/content/language1/downloads/SMB380_Flyer_Rev1.3.pdf
Can someone explain me technical data on the right?
I'm especially interested in the noise and precision data.
Thx
Noise is 0.5 mg/Hz^-1, which tells you how much noise there will be for a given measurement bandwidth, e.g. if you filter your signal with a 100 Hz low pass filter you can expect 5 mg of noise.
As for sensitivity, there are 3 programmable ranges. The most sensitive range is 2 g. The output is 10 bits (signed, presumably) so you get 4 mg per bit, i.e. the smallest signal you can detect at a level of +/- 1 bit is 4 mg.
you can use the butterworth filter in matlab, the result will be perfect especially if you use this parametrer [B,A]=butter(2, 0.05)