**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.