Bluetooth Low Energy RSSI Calculation - bluetooth-lowenergy

I wanted to calculate the RSSI of the received signal. I am working on a program to find the distance between two nodes using BLE RSSI in LabVIEW.
RSSI = -10nlog(d/d0)+A
where d is unknown distance
d0 is reference distance (1 meter)
A is RSSI calculated at 1 meter.
n is path attenuation factor.
I want to know the formula to calculate RSSI. I came across this formula :
RSSI = Txpower (dBm) - PathLoss of the receiving signal(dBm).
I calculated path loss PL(d) at reference distance 1 meter. then I calculated RSSI from this equation.my transmit power was 0dBm and the path loss is 4 dBm. so RSSI is -4 dBM.
Is this method to calculate RSSI is correct? I wanted to calculate RSSI, rather than reading RSSI value from packet. Can anybody help me to how to calculate RSSI of received signal.

Related

sinusoidal signals with frequency of 5 hertz

I want to generate and plot two sinusoidal signals with a frequency of 5 hertz and a phase difference of 60 degrees between them.
The sampling frequency should be 500 hertz and the signal length should be 1 second.
After drawing the signals, I should print the phase difference between the signals by calculating the number of samples and seconds. I have made it with seaborn library but I want to make it without library anyone can help me please ?
and my codes in figure

How to determine optimal sampling frequency for an ADC to reduce noise?

Besides iterating through values, is there a good method for determining what the optimal sampling frequency/ averaging period is when sampling a voltage through an ADC to reduce noise?

Filter out power frequency from signal with low sample rate

I have some recorded signal with 100Hz sample rate. I want to filter out 60Hz frequency from the signal. I am using the butter() filter from the signal package in R. But it does not allow us to filter out frequencies greater than the Nyquist frequency. So when I try to apply the Butterworth filter
butter(5,W=c(58,62)/100*2,type="stop")
I get the
Error in butter.default(5, W = c(58, 62)/100 * 2, type = "stop") :
butter: critical frequencies must be in (0 1)
The manual page for Chebyshev's filters mentions the same requirement on the filtered frequencies.
Can I do anything here without upsampling the signal? Which other filters may I use?
You can't filter out the 60Hz frequency, because there's no such frequency in the sampled signal, due to the Nyquist sampling theorem.
However, what you can find in the sampled signal is an alias of the 60Hz frequency. It's located at 40Hz, because of the folding effect at 50Hz (half the sampling rate). You can filter out this frequency, but you will lose the information of the original signal 40Hz frequency too.

Right formula for calculating temperature sensor using STMF401RE Nucleo?

I'm using STM32F401RE Nucleo board to measure the ambient temperature. After the sampling process, I receive a digital value from ADC_CHANNEL_TEMPERATURE and I want to convert this digital value into C°. I searched on the internet for this and I found two different methods:
Method 1: Page 226 in http://www.st.com/content/ccc/resource/technical/document
Temp(degree) = (V_sense - V_25)/Avg_slope + 25
Method 2: Page 251 in http://www.st.com/content/ccc/resource/technical/document
Temp(degree) = ( ( (110 - 30)*(TS_DATA - TS_CAL1) ) / (TS_CAL_2 - TS_CAL_1) ) + 30
Where:
- TS_CAL2: temperature sensor calibration value at 110 C°
- TS_CAL1: temperature sensor calibration value at 30 C°
- TS_DATA: temperature sensor output from ADC
It confuses me which one is the correct formula for calculating the temperature in C°.
Although Method 1 is from reference manual of STM32F401, the temperature result doesn't look correctly. While Method 2 from reference manual of STM32F0 series, it looks more reasonable.
Still I don't know which formula should I apply when using STM32F401RE Nucleo board?
Method 1 Temp(degree) = (V_sense - V_25)/Avg_slope + 25 is a simplified version where calibration is presumably done by pre-measuring the value at 25° and assigning it to V_25. In this context, Avg_slope is probably taken from datasheet - but it could be also a result of some calibration.
Method 2 Temp(degree) = ( ( (110 - 30)*(TS_DATA - TS_CAL1) ) / (TS_CAL_2 - TS_CAL_1) ) + 30 uses TWO calibration points, at 30° and 110°, and is more correct. Note that also method 1 can use two calibration points (used to calculate average slope). Also, method 2 would let you to take your calibration points anywhere (presumably, in the range where you are more interested in).
Both the methods, however, suffer from non-linearity (if any) of the sensor. I suppose that some non-linearity is present, because method 1 tells about "average slope".
If you want greater precision, you can take several calibration points and interpolate between them.
i am currently using the microcontroller stm32 f030 c8t6
:question:Is TS_DATA=(ADC Value)*(Vdd/Vref) or TS_DATA=(ADC Value) the temperature sensor adc value when the temperature sensor channel is activated ??

Units of a Fourier Transform (FFT) when doing Spectral Analysis of a Signal

My question has to do with the physical meaning of the results of doing a spectral analysis of a signal, or of throwing the signal into an FFT and interpreting what comes out using a suitable numerical package,
Specifically:
take a signal, say a time-varying voltage v(t)
throw it into an FFT (you get back a sequence of complex numbers)
now take the modulus (abs) and square the result, i.e. |fft(v)|^2.
So you now have real numbers on the y axis -- shall I call these spectral coefficients?
using the sampling resolution, you follow a cookbook recipe and associate the spectral coefficients to frequencies.
AT THIS POINT, you have a frequency spectrum g(w) with frequency on the x axis, but WHAT PHYSICAL UNITS on the y axis?
My understanding is that this frequency spectrum shows how much of the various frequencies are present in the voltage signal -- they are spectral coefficients in the sense that they are the coefficients of the sines and cosines of the various frequencies required to reconstitute the original signal.
So the first question is, what are the UNITS of these spectral coefficients?
The reason this matters is that spectral coefficients can be tiny and enormous, so I want to use a dB scale to represent them.
But to do that, I have to make a choice:
Either I use the 20log10 dB conversion, corresponding to a field measurement, like voltage.
Or I use the 10log10 dB conversion, corresponding to an energy measurement, like power.
Which scaling I use depends on what the units are.
Any light shed on this would be greatly appreciated!
take a signal, a time-varying voltage v(t)
units are V, values are real.
throw it into an FFT -- ok, you get back a sequence of complex numbers
units are still V, values are complex ( not V/Hz - the FFT a DC signal becomes a point at the DC level, not an dirac delta function zooming off to infinity )
now take the modulus (abs)
units are still V, values are real - magnitude of signal components
and square the result, i.e. |fft(v)|^2
units are now V2, values are real - square of magnitudes of signal components
shall I call these spectral coefficients?
It's closer to an power density rather than usual use of spectral coefficient. If your sink is a perfect resistor, it will be power, but if your sink is frequency dependent it's "the square of the magnitude of the FFT of the input voltage".
AT THIS POINT, you have a frequency spectrum g(w): frequency on the x axis, and... WHAT PHYSICAL UNITS on the y axis?
Units are V2
The other reason the units matter is that the spectral coefficients can be tiny and enormous, so I want to use a dB scale to represent them. But to do that, I have to make a choice: do I use the 20log10 dB conversion (corresponding to a field measurement, like voltage)? Or do I use the 10log10 dB conversion (corresponding to an energy measurement, like power)?
You've already squared the voltage values, giving equivalent power into a perfect 1 Ohm resistor, so use 10log10.
log(x2) is 2 log(x), so 20log10 |fft(v)| = 10log10 ( |fft(v)|2), so alternatively if you did not square the values you could use 20log10.
The y axis is complex (as opposed to real). The magnitude is the amplitude of the original signal in whatever units your original samples were in. The angle is the phase of that frequency component.
Here's what I've been able to come up with so far:
The y-axis seems likely to be in units of [Energy / Hz] !?
Here's how I'm deriving this (feedback welcomed!):
the signal v(t) is in volts
so after taking the Fourier integral: integral e^iwt v(t) dt , we should have units of [volts*seconds], or [volts/Hz] (e^iwt is unitless)
taking the magnitude squared should then give units of [volts^2 * s^2], or [v^2 * s/Hz]
we know Power is proportional to volts ^2, so this gets us to [power * s / Hz]
but Power is the time-rate of change in energy, i.e. power = energy/s, so we can also write Energy = power * s
this leaves us with the candidate conclusion [Energy/Hz]. (Joules/Hz ?!)
... which suggests the meaning "Energy content per Hz", and suggests as a use integrating frequency bands and seeing the energy content... which would be very nice if it were true...
Continuing... assuming the above is correct, then we are dealing with an Energy measurement, so this would suggest using 10log10 conversion to get into dB scale, instead of 20log10...
...
The power into a resistor is v^2/R watts. The power of a signal x(t) is an abstraction of the power into a 1 Ohm resistor. Therefore, the power of a signal x(t) is x^2 (also called instantaneous power), regardless of the physical units of x(t).
For example, if x(t) is temperature, and the units of x(t) are degrees C, then the units for the power x^2 of x(t) are C^2, certainly not watts.
If you take the Fourier transform of x(t) to get X(jw), then the units of X(jw) are C*sec or C/Hz (according to the Fourier transform integral). If you use (abs(X(jw)))^2, then the units are C^2*sec^2=C^2*sec/Hz. Since power units are C^2, and energy units are C^2*sec, then abs(X(jw)))^2 gives the energy spectral density, say E/Hz. This is consistent with Parseval's theorem, where the energy of x(t) is given by (1/2*pi) times the integral of abs(X(jw)))^2 with respect to w, i.e., (1/2*pi)*int(abs(X(jw)))^2*dw) > (1/2*pi)*(C^2*sec^2)*2*pi*Hz > (1/2*pi)*(C^2*sec/Hz)*2*pi*Hz > E.
Conversion to a dB (log scale) scale does not change the units.
If you take the FFT of samples of x(t), written as x(n), to get X(k), then the result X(k) is an estimate of the Fourier series coefficients of a periodic function, where one period over T0 seconds is the segment of x(t) that was sampled. If the units of x(t) are degrees C, then the units of X(k) are also degrees C. The units of abs(X(k))^2 are C^2, which are the units of power. Thus, a plot of abs(X(k))^2 versus frequency shows the power spectrum (not power spectral density) of x(n), which is an estimate the power of a set of frequency components of x(t) at the frequencies k/T0 Hz.
Well, late answer I know. But I just had cause to do something like this, in a different context. My raw data was latency values for transactions against a storage unit - I resampled it to a 1ms time interval. So original data y was "latency, in microseconds." I had 2^18 = 262144 original data points, on 1ms time steps.
After I did the FFT, I got a 0th component (DC) such that the following held:
FFT[0] = 262144*(average of all input data).
So it looks to me like FFT[0] is N*(average of input data). That sort of makes sense - every single data point possesses that DC average as part of what it is, so you add 'em all up.
If you look at the definition of the FFT that makes sense too. All of the other components would involve sine and cosine terms too, but really the FFT is just a summation. The average is just the only one that happens to be present in all points equally, because you have cos(0) = 1.

Resources