NanoVNA V2 / Forum

Note: this page is a mirror of https://groups.io/g/NanoVNAV2.
Click here to join and see most recent posts.

Signal processing questions


Jose Barros 2021/04/15 12:11

Hi,
I recently bought a nanoVNA and as always couldn't avoid looking under the hood.
Been browsing trough the code and I'm currently trying to understand the sample processing function.

I see that there is something that looks like a convolution between the adc samples and a sinROM complex data table containing a signal of the same frequency as the IF.

I would really appreciate if someone could answer a few questions:
1-Why does the sinROM contain a complex Morlet Wavelet for the 12KHz IF and a "normal" sine/cosine for 6KHz IF.
2-Why is the convolution not done with a sliding window but instead advances 50 samples at a time (the kernel size).
3-How does the  phase measurement maintain coherence between the different measures (Reference, Reflected, Trough) since they are taken at different times using a non coherent LO for the final conversion (the convolution kernel)

I understand if there is nobody willing to answer this questions, but can you at least point me to some information sources?

Thank you in advance,

José

DiSlord 2021/04/16 00:07

On Thu, Apr 15, 2021 at 10:04 PM, Jose Barros wrote:

>
> 3-How does the  phase measurement maintain coherence between the different
> measures (Reference, Reflected, Trough) since they are taken at different
> times using a non coherent LO for the final conversion (the convolution
> kernel)

This compensated by calibration. Phase shift between measures constant (should be)

IF in V2 6k or 12k for different frequency range, so used 2 sin/cos tables for this (last changes added window function to tables, not in all tables, but i not see any features it can give)

If use sliding window "i think" not possible easy comensate variable phase shift between measures

Erich Kaltenbrunner 2021/04/16 10:02

Hello,
a I wish to be able to switch to a logarithmic frequency scale



Erich

Jim Lux 2021/04/16 05:50

On 4/15/21 12:11 PM, Jose Barros wrote:
> Hi,
> I recently bought a nanoVNA and as always couldn't avoid looking under
> the hood.
> Been browsing trough the code and I'm currently trying to understand
> the sample processing function.
>
> I see that there is something that looks like a convolution between
> the adc samples and a sinROM complex data table containing a signal of
> the same frequency as the IF.
>
> I would really appreciate if someone could answer a few questions:
> 1-Why does the sinROM contain a complex Morlet Wavelet for the 12KHz
> IF and a "normal" sine/cosine for 6KHz IF.
> 2-Why is the convolution not done with a sliding window but instead
> advances 50 samples at a time (the kernel size).
> 3-How does the  phase measurement maintain coherence between the
> different measures (Reference, Reflected, Trough) since they are taken
> at different times using a non coherent LO for the final conversion
> (the convolution kernel)

#1 - I've not looked into the 12kHz IF so can't answer that.

#2 - don't know - on the original NanoVNA the raw measurement is a
single block of 48 samples, so it's just mixed down to baseband in one step.

#3 - The 3 measurements are taken at the same time,  so they are
coherent with each other, even though the test signal and the LO are not
coherent with each other. All three measurements are sampled with the
same clock, and all three mixers are fed with the same LO.



Jim Lux 2021/04/16 06:33

On 4/15/21 12:11 PM, Jose Barros wrote:
> Hi,
> I recently bought a nanoVNA and as always couldn't avoid looking under
> the hood.
> Been browsing trough the code and I'm currently trying to understand
> the sample processing function.
>
> I see that there is something that looks like a convolution between
> the adc samples and a sinROM complex data table containing a signal of
> the same frequency as the IF.
>
> I would really appreciate if someone could answer a few questions:
> 1-Why does the sinROM contain a complex Morlet Wavelet for the 12KHz
> IF and a "normal" sine/cosine for 6KHz IF.
> 2-Why is the convolution not done with a sliding window but instead
> advances 50 samples at a time (the kernel size).
> 3-How does the  phase measurement maintain coherence between the
> different measures (Reference, Reflected, Trough) since they are taken
> at different times using a non coherent LO for the final conversion
> (the convolution kernel)

#1 - Seeing response from DisLord - It's windowed.

A comment on #1, #2 - in this application, I'm not sure you care what
the sidelobes of the analysis window are, in the frequency domain - that
is, why not use a rectangular window (a standard sin/cos table)?  If you
were doing spectral analysis, then there's some benefit in a windowed
approach, to reduce the -13dBc side lobes, or to reduce the "scalloping
loss" if the signal isn't in the middle of the "channel".   Also, I
don't know that there's any benefit from a reduced filter order (i.e.
sliding and integrating a smaller filter, rather than just taking all
the samples as a block).

Here, though, you have a single tone you are looking for, and what you
would want to do is optimize the SNR of that single tone measurement. So
what you would want to look at from a windowing/filtering standpoint is
whether using something other than a rectangular window reduces the
noise (i.e. the power from frequencies other than the center of the
band). (the Equivalent Noise Bandwidth, as it were) Looking over the
table in Harris, all the windows have wider ENBW than rectangular, which
means the SNR of a measurement of a tone at the center would have
*lower* SNR using the window than just a straight out rectangular window.

This is an interesting question for implementation - Some of the
theoretical papers one would normally look to (Fred Harris, IEEE
Proceedings Jan 1978, "On the Use of Windows for Harmonic Analyiss with
the Discrete Fourier Transform" - sort of the original window bible) are
cast in the framework of infinite precision.  Here, through, one has a
quantized signal (so the noise is a combination of analog circuit noise
and quantization noise) and the math is fixed precision, so you have an
interesting tradeoff in terms of filter coefficients (the sin/cos table
in the NanoVNA is basically a FIR filter with 48 taps).

And, of course, implementation complexity (time it takes to code and
test it, size of the code, runtime).


For what it's worth, there is quite a literature of "optimal estimators"
for finding the amplitude and phase of a sampled sinusoid with a known
frequency - for instance, you can do a least squares fit.  My
recollection is that none of them are *significantly* better than just
multiplying by sin/cos and integrating - after all, that *is* the
matched filter for the input.  And in something like the NanoVNA "simple
code" is probably an overall win.

OwO 2021/04/17 12:39

Yes, what Jim said. Of course rectangular window gives optimal SNR if
you assume white noise, but gaussian window rejects out of band noise
better at the expense of letting in more close in noise. It is a
tradeoff based on where you think the synthesizer spurs are.

Jose Barros 2021/04/18 04:01

Thank you for all the valuable information, this would be a nice wiki page. Looking at the code without this background information is hard (at least to me) and OSS projects with proper code commenting are more rare than white unicorns (not criticism I'm just as guilty)

To reply to this topic, join https://groups.io/g/NanoVNAV2

View this thread on groups.io