Low frequencies Vector Network Analyzer, arduino based. - Page 1
Forum section: electronics / projects

author: MasterT
author_rank: Frequent Contributor
timestamp: September 20, 2018, 02:11:55 pm
content: https://www.youtube.com/watch?v=83TpYkJQTyU&feature=youtu.beFeedback is welcome on a project, I'm having fun with.Frequency range: 1k - 6.8MDDS synthesizer AD9833Accuracy of the phase measurement better than:0.01 degree for frequencies < 100k.0.3 < 1MTBD > 6.8MModest results at high frequencies due to limited GBW of the MCP6S91.(Needs to be replaced. PGA feature is not active at the moment, both channels in buffer G=1 mode.)Arduino adc sampling rate set 1 MSPS, 12-bits, 2 channels at 500 ksps. Sampling above 250 kHz is done in "undersampling" mode, aliasing number goes up to 28(!) at 6.8M. FFT size is 2048, 244 Hz/bin.22-09-2018///// Updates, after some debates we have on two pages...Project is inspired by AD5933 IC, to create something even better and lower cost.Objective of this project - network analyzer - is to measure magnitude and phase.What next is not completely defined yet, using precise phase data impedance could be calculated, capacitance, inductance, phase and gain of the OPA or any other amplifiers could be traced with one click on a knob.Arduino DUE as a base platform was chosen, because it's cheap and well supported on the software side.Primary goal is accuracy of this two parameters: magnitude and phase.To get 0.01 degree or better, w/o paying to much for gold plated IC, extremely overpriced high speed ADC, etc.What I have is 12-bits adc, that is actually 9.6 (ENOB at 1 MSPS). So, SNR is less than 60 dB, not accounting for buffer amps, interference and all noise from digital circuits around.60dB is Very low to reach the goal. To increase SNR ( and to calculate a magnitude & phase, of course) FFT-2048 was selected.And here is the magic, fft provides 30 dB improvement in SNR, bringing it's up to 90 dB. That is about the same that someone could get out of expensive 16-bits ADC.If I make fft size bigger, sacrificing speed, even better SNR ratio could be reached, and consequently, more accurate measurement results for magnitude & phase.Logic diagram (crystalized on page 2): Phase Error - > SNR - > Bandwidth - > FFTNow more software tricks...I'd underline, highest priority is for phase accuracy.Phase is easily calculated out of the fft results:Code:double get_Phase(int *fr, int n_bin){int real = fr;int imag = fr[FFT_SIZE -n_bin];double Phase = RAD_CONV *atan2((double)imag, (double)real);return Phase;}Because there is a ratio: imag/real (arctang ( sin /cosine)), the most accurate resultsis when ratio is close to 1. I don't think it has to be proofed.There are couple steps implemented in software to keep an error smalestTo minimize phase noise:1. DDS frequencies is always set to exact FFT bin, so it's corrected+- 122 Hz up or down to nearest fft bin.2. DDS synthesizer is preset to phase zero each time new freq. value loaded,hold in reset mode, and start simultaneously with arduino adc sampling.It's helpful at lower frequencies <1 MHz.Since ADC is running at its own clock derived from arduino DUE prescallersettings, that different from on-board DDS module's 25 MHz crystal,phase jitter still exist. AD9833 is also not very stable on this matter:Quote3. I'm thinking to add some quality factor, when phase data close to 0 or close to 90- results should be discarded and measurements repeated at this point.I attached a "working copy" of the software. Be careful, there are many debug messages, and may be some harsh comments, don't take it personally.King of the dsp engine - fft library - was posted here, message #4https://www.eevblog.com/forum/microcontrollers/fft-processing-using-ucpu/Though, any other will make no difference, DSP pack for cortex-3 for example (not tested).

author: metrologist
author_rank: Super Contributor
timestamp: September 20, 2018, 05:47:57 pm
content: Looks like I'm gonna have to get a due.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 20, 2018, 06:33:23 pm
content: Quote from: metrologist on September 20, 2018, 05:47:57 pmNot sure, if there is a question why I'm using arduino? No affiliation. Simply, I know sam3x better than stm32f3/4xx, and digging up 1500+ pages DS is not funny, even I have to do it once in a while.For person, who completes at least one project with uCPU, the choice of architecture /hardware would be greatly biased to "pre-compiled" software pieces he has, availability of libraries and on-line examples. Certainly, it 'd be possible to write your own graphics library, DDS/ TFT drivers etc, but it's would takes a years for amateur /hobby programmers.Most important things for this device is ENOB / ADC performance, and I know sam3x has >9.6bits at 1msps rate. Blue pill, stm32f303 for example, has less than 8-bits, so board may be used with lower phase accuracy output

author: metrologist
author_rank: Super Contributor
timestamp: September 20, 2018, 07:32:22 pm
content: No question, just admiration. I only have the 328p based Arduinos. Did I miss the project details, or are they not ready yet?

author: DaJMasta
author_rank: Super Contributor
timestamp: September 20, 2018, 07:55:42 pm
content: Maybe it's more of a software issue, but I would have thought than an external ADC would be the obvious choice. Sure, the integrated ones can be alright, but you could easily get a couple more bits worth of resolution and enough sample rate to not have to deal with aliasing in this bandwidth... and you're already using an external DAC.Maybe an R2R DAC using arduino output pins and the internal ADC could be used for a lower frequency cap option, but if you're going to go with external chips, I figure an external ADC as well would give you a fair bit better performance for a few extra bucks and a little board real estate. Not actually doing the sampling on the main MCU also would probably give you some responsiveness in the UI.Certainly a neat project, though, can you do SOLT calibration or is this just raw data?

author: MasterT
author_rank: Frequent Contributor
timestamp: September 20, 2018, 10:05:55 pm
content: Quote from: metrologist on September 20, 2018, 07:32:22 pmProject is not finished yet, may be never would, I'm still testing all possibilities. I was thinking of using UNO board, but than reject. Technically it possible to run 512-fft on UNO, and sampling at 64-76 ksps with modest 9-bits achievable, but: not enough pins - TFT display shown on a video eats up 13-pins out of 18 (2 no use - serial link). Plus, scan mode instead of 5-8 seconds on DUE board would takes 50-90 seconds - unacceptable slow for tunning something real-time.Quote from: DaJMasta on September 20, 2018, 07:55:42 pmExternal ADC - is a way on FPGA, but there are no any benefits of using it with uCPU. Maximum you can get about 2.5 MSPS over 42 MHz SPI (16-bits w/o software overhead).SAM3X doesn't have parallel port DMA, mapping pins is out off order and parallel ADC bus I'm sure would be even slower. Plus cost of external ADC, loosy 500 ksps 16-bits more than 30$. Doesn't make any sense.Aliasing is not an issue, I already tested sam3x adc - it has not any issue to undersample up to 30 (!) MHz. For continuous sine wave like in this project internal adc is perfect.I do not have DAC in a project, $3 DDS module from ali, AD9833 has internal DAC, but since it's not accessible, there is no point to talk that we have a DAC. Just DDS.What is required, a good PGA, I'm lazy to build one myself. PGA with gain as little as 16-32 equals to 4-5 additional bits, it easily turns sloppy 8-bitter into luxurious 12-13 bits, arduino's 12-bitter into 16-17 !Or if double stages 32+32 - into unimaginable 22-bits with 1 msps.

author: coppercone2
author_rank: Super Contributor
timestamp: September 20, 2018, 10:09:28 pm
content: you know what would be nice, a DSA

author: MasterT
author_rank: Frequent Contributor
timestamp: September 20, 2018, 10:14:06 pm
content: Quote from: coppercone2 on September 20, 2018, 10:09:28 pmgoogle says: Democratic Socialists of America, is it correct?

author: coppercone2
author_rank: Super Contributor
timestamp: September 20, 2018, 10:39:40 pm
content: no think of it like a dynamic signal analyzer not some kind of commie plot

author: xaxaxa
author_rank: Regular Contributor
timestamp: September 21, 2018, 03:09:29 am
content: I would use an audio ADC, e.g. pcm1802. Cheap and has excellent linearity and dynamic range that no MCU ADC would ever hope to match. For higher frequencies (>1MHz) a mixer is a must.What directional coupler are you using for low frequency?

author: MasterT
author_rank: Frequent Contributor
timestamp: September 21, 2018, 11:20:11 am
content: Quote from: xaxaxa on September 21, 2018, 03:09:29 amNot relevant, there is no any directional coupler. I used non RF approach, similar to analog device AD5933

author: RoGeorge
author_rank: Super Contributor
timestamp: September 21, 2018, 11:50:06 am
content: Nice, well done!Do you have any plans to publish the software, too?

author: MasterT
author_rank: Frequent Contributor
timestamp: September 21, 2018, 12:40:34 pm
content: Quote from: RoGeorge on September 21, 2018, 11:50:06 amDifficult to say, have to clean it up first. It's like a big pizza, assembled out of "customized" libraries.For example, TFT, GFX - Adafruit libraries, tweaked internally to make it compatible with mcufiends ILI9341 shield.For rotary encoder same things, was not able to find "plug-in and use" arduino DUE version, have to re-write interrupt driven UNO version.DDS AD9833 again, tweaked to synchronize with adc start dma conversion.Customized I mean on direct port manipulation level, so pieces of code would not run on any other uCPU except sam3x.

author: ogden
author_rank: Super Contributor
timestamp: September 21, 2018, 01:57:58 pm
content: Quote from: xaxaxa on September 21, 2018, 03:09:29 amYou can't "undersample" with most SD ADC's so w/o mixer you are stuck with around 1/10 of sampling frequency - to get +/- meaningful phase/amplitude measurements. In general it means with such a slow ADC's you shall implement mixers, this also means added complexity. This basically means N2PK VNA or it's simplified variant with two AD9833's.Quote from: MasterT on September 20, 2018, 02:11:55 pmNice project indeed, but I would not name it VNA. It's more like RF impedance meter "with a twist". Also you shall write "theory of operation" or provide pointer to existing one - because many who read this thread possibly do not understand operation of instrument you are building.I would useDCTDFT instead of FFT. Your DDS is generating just single frequency, so there's no point to calculate all the bins of FFT that does not relate to frequency of DDS, you basically need to calculate just one which is what DFT does. With DFT you don't need so much memory and CPU resources as well.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 21, 2018, 02:51:10 pm
content: Quote from: ogden on September 21, 2018, 01:57:58 pmThanks. I should put a reference link to AD5933 in the first message, and since AD used "1 MSPS, 12-Bit Impedance Converter, Network Analyzer" as a title for theirs chip, I would keep network analyzer as a name of my project.I intended to get comments from the audience that already posses a knowledge "theory of operation."Manny people don't understand the absolute supremacy of the FFT on any other method of data processing. The question of "why using FFT instead of DCT?" is the same as "why to sample data by ADC and than process in DSP core, if we can drive a couple of MUXes by quadrature shifted clock?" Because FFT provides processing gain, increasing SNR ratio by >30 dB(!). Using hardware analogy with two MUXes, someone has to put a hardware preselector - 244 Hz wide band pass filter in front of the MUXes. Practically impossible to build such BPF with 40-80 dB roll off, adjustable over 1 kHz - 6.8 MHz. Not now, not ever in the future.

author: nihtila
author_rank: Regular Contributor
timestamp: September 21, 2018, 05:59:03 pm
content: I am not a mathematician and do not understand DCT or those formulas really, but I think the point was that why do you calculate FFT when you are only after one frequency which you know (or are you, you do sweep right?). FFT calculates correlation for all frequencies between zero and Nyquist frequency, and although it is efficient computation, it is probably better just calculate correlation for that one frequency you are interested in. It does not change your processing gain if you do not change the length of your signal.Of course if you have the computation power it probably does not matter. Or this comment may not even be relevant as I do not know exactly how you compute the impedance.But your project looks cool! Really looking forward to more information.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 21, 2018, 07:45:35 pm
content: Quote from: nihtila on September 21, 2018, 05:59:03 pmThe question I see, why someone would calculate all those 1023 bins if results trashed except only one bin that is goes into arctangent formula for phase extraction? Seems like a nonsense.Lets me be more specific for this project, so it would be easy for me to explain. I have 250 kHz (putting aside aliasing for now) band splitted into 1024 stripes 244 Hz wide each. My signal is falling into 125 kHz, bin = 512.The problem is that ADC data (and any data) hold not only pure signal, but a noise as well. And all these noise present in each stripes, more or less equally (gaussian somekind off). Noise level is expressed in Volt / sqrt(Hz), so wide bandwidth - higher noise level. For person who works with RF it's not a news, wider bandwidth - is always band things, and must be avoided.I already gave a hardware example with MUX (or mixers). So, if I use a hardware phase discriminator, all 250 kHz wide band with all noise present in it goes into output. The only way to stop it, it's a preselector - or filter.Now, if I do run a FFT, its sorting out everything - useful signal , noise - whatever. FFT is a separator, refinery machine, it would filter out /extract noise for example 128 kHz out of bin of interest 512, 125 kHz. Same apply to all 1023 bins, they are all cross-referenced with each other. Noise that presents in each stripe is extracted from 125k, doing so FFT is "cleaning up" "refines" "polishing" my the only one bin of interest. So at the end, even most results are trashed, but it's doesn't matter since each result is already Accounted and extracted from bin 512. Numerical data in bin 512 becomes sqrt(1023) time LESS noisy. Because an FFT magically pumped out any dust that otherways will go directly into output, into arctangent formula and generate a phase error.

author: nihtila
author_rank: Regular Contributor
timestamp: September 21, 2018, 07:59:14 pm
content: I'm not sure what you mean by "cross-referencing" between bins. Isn't FFT effectively just a bank of narrow bandpass filters?Try to generate 125kHz digital reference signal (sine) of the same length as your FFT, and use the same windowing. Correlate that with your wideband signal. You will get one number. If I am not completely wrong, that is the same number as your FFT gives for that bin.

author: ogden
author_rank: Super Contributor
timestamp: September 21, 2018, 08:20:43 pm
content: Quote from: MasterT on September 21, 2018, 02:51:10 pmWell, I have to admit two things: 1) I was wrong suggesting DCT (discrete cosine transfer) when actually I had DFT (discrete fourier transfer) in mind 2) you are mistaken about "FFT supremacy on any other method of data processing".Why? - Check datasheet of AD5933, chip you are referring to. It does not do FFT but DFT instead.

author: oPossum
author_rank: Super Contributor
timestamp: September 21, 2018, 08:37:16 pm
content: Quote from: ogden on September 21, 2018, 08:20:43 pmFFT is just a fast way to do a DFT.

author: ogden
author_rank: Super Contributor
timestamp: September 21, 2018, 08:38:28 pm
content: Quote from: oPossum on September 21, 2018, 08:37:16 pmFor single frequency bin?Good resource to read:https://literature.cdn.keysight.com/litweb/pdf/5950-3000.pdf

author: oPossum
author_rank: Super Contributor
timestamp: September 21, 2018, 08:49:35 pm
content: The results are the same for any number of bins.

author: ogden
author_rank: Super Contributor
timestamp: September 21, 2018, 08:52:06 pm
content: Quote from: oPossum on September 21, 2018, 08:49:35 pmNot if you care about memory and CPU resources used.

author: oPossum
author_rank: Super Contributor
timestamp: September 21, 2018, 08:58:10 pm
content: You really aren't making much sense.

author: ogden
author_rank: Super Contributor
timestamp: September 21, 2018, 09:13:53 pm
content: Quote from: oPossum on September 21, 2018, 08:58:10 pmIf you do not understand what is FFT compared to discrete sine and cosine transform (DFT) then obviously it does not make much sense to you.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 21, 2018, 10:05:14 pm
content: Quote from: nihtila on September 21, 2018, 07:59:14 pmEffectively yes, it's bank of BPF's. Internally fft engine does cross-correlation against sine & cosine And against each others components, there is summ-diff embedded. Exactly this sum-diff feature makes it's so efficient, compare to bank of FIR filters. Running 1024 FIR's (with 1024 kernel length) in parallel would not be possible on any CPU I know.Sure you can do cross-correlation with single 125k sine wave, that is another way to get delay or phase shift info. They do same things in all audio and video codec for compression of data, but using optimised version. Simple point-to-point cross-correlation is the highly unefficient operation

author: MasterT
author_rank: Frequent Contributor
timestamp: September 21, 2018, 10:35:16 pm
content: Quote from: ogden on September 21, 2018, 09:13:53 pmAll this delusion about DFT /DCT /Wavelets arises from misunderstanding basic fact, that FFT is the most efficient, accurate and fastest algorithm.I have another topic on FFT somewhere on this forum, and I already read and know mr. Ogden opinion. Like DCT - do your project with DCT and we will compare results. I don't like this discussion over and over again about difference between DFT DCT wavelet and anything else. There are things that not everyone would ever understand, despite "correct" vocabulary they use.Regarding terminology Analog Device used in their data sheet on AD5933, right , I didn't read it attentively, and don't care what they call DCT or DFT. What I was expecting from someone who read DS, is a question how I get 0.01 degree phase error compare to 0.5% stated in DS.

author: ogden
author_rank: Super Contributor
timestamp: September 21, 2018, 10:50:00 pm
content: Quote from: MasterT on September 21, 2018, 10:35:16 pmI am not sure who is delusional here. You state that FFT is the most efficient, accurate and fastest algorithm to calculate what exactly? Indeed it is most efficient if you are interested in every bin of it's output, but you are not. You are using just one bin. Look, I am not your mother nor your university. If you still did not get it - so be it. Hopefully other readers of our conversation will do the homework and actually check what I am talking about.QuoteRight.You use correct vocabulary: FFT?

author: xaxaxa
author_rank: Regular Contributor
timestamp: September 22, 2018, 01:47:56 am
content: If you multiply your input signal by sine and cosine, then do integrate and dump, the result you get is mathematically equivalent to one frequency bin of your FFT. You can see this just from the formula of the DFT. FFT takes O(n log n) to compute whereas the single frequency DFT takes O(n) even without taking into account memory locality effects, so the integrate and dump is a better choice for this application. Look at my VNA implementation on github (xaxaxa-dev/vna) which does this on an FPGA.

author: ogden
author_rank: Super Contributor
timestamp: September 22, 2018, 03:11:44 pm
content: Quote from: MasterT on September 21, 2018, 02:51:10 pmI am afraid that you are only person who knows "theory of operation" of that circuit which most likely is truly your "design".

author: MasterT
author_rank: Frequent Contributor
timestamp: September 22, 2018, 03:19:39 pm
content: Quote from: xaxaxa on September 22, 2018, 01:47:56 amI was able to locate your project on github, and download a tar-ball. Can't find dsp processing, where do you calculate phase/magnitude? Is this in fpga? Could I run your dsp core in Qt for evaluation purposes?I couldn't see any metrological parameters for phase error, have any data?

author: MasterT
author_rank: Frequent Contributor
timestamp: September 22, 2018, 03:47:00 pm
content: Quote from: ogden on September 22, 2018, 03:11:44 pmCan't read you, blacklisted by very nice "Ignore" feature on this forum.

author: ogden
author_rank: Super Contributor
timestamp: September 22, 2018, 03:51:58 pm
content: Quote from: MasterT on September 22, 2018, 03:47:00 pmOk. You do not deserve my input anymore anyway. Warning to others: his circuit has many flaws, better do not copy it.

author: Kleinstein
author_rank: Super Contributor
timestamp: September 22, 2018, 04:53:16 pm
content: For just using 1 or 2 bins (as one also needs the phase) from the FFT it is usually faster to just calculate those 2 bins by DFT. The FFT is very efficient if many bins are needed, like in a spectrum analyzer function, but not for a simple lock in / VNA type measurement.The advantage of DFT is that is can be done in real time, without even saving all the samples. Its just a few running sums and than from time to time the final result.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 22, 2018, 05:06:10 pm
content: Quote from: Kleinstein on September 22, 2018, 04:53:16 pmProbably, you didn't read what I already explain using hardware analogy with MUX-ers, that running FFT would reduce noise floor in single bin bucket? In other words, provides >30 dB (fft-2048) improvements in SNR ratio ?

author: Kleinstein
author_rank: Super Contributor
timestamp: September 22, 2018, 05:16:00 pm
content: The FFT is just an numerical efficient algrorithm calculating the DFT for all the bins. The result is essentially the same for the fourier-transformation for single bins by the basic formula. If at all there might be a minor difference due to rounding effects - here the FFT might be slightly worse. However with a 12 Bit ADC and thus likely 16 bit math, this should not be significant.I think the hardware analog to the DFT is rather confusing, and might be wrong. Fact is that it does not help all those extra bins by FFT if you don't need them. No SNR gain from calculating all all bins and ignoring it later.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 22, 2018, 05:43:07 pm
content: Link to doc:http://www.analog.com/media/en/training-seminars/design-handbooks/Data-Conversion-Handbook/Chapter5.pdfpage 57.

author: Kleinstein
author_rank: Super Contributor
timestamp: September 22, 2018, 05:49:15 pm
content: The same SNR gain as with the FFT also applies to calculating the Fourier components in an other way. So there is the gain from the reduced bandwidth, but this is not exclusive to an FFT.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 22, 2018, 05:59:56 pm
content: Quote from: Kleinstein on September 22, 2018, 05:49:15 pmNo, it's not. Reducing bandwidth is usually done by RF preselectors. To do it in software, there is no alternative to FFT in efficiency. Difference is enormous, compare for example with BP FIR, I 'd estimate for fft-2048 fft is x10^6 times more efficient.

author: Bud
author_rank: Super Contributor
timestamp: September 22, 2018, 06:38:13 pm
content: This device is limited to series passive DUTs, correct? It can only work with 2 wire circuits that can be inserted between the source and receiver terminals, so no ground referenced and/or active circuits can be measured - is my understanding correct?

author: ogden
author_rank: Super Contributor
timestamp: September 22, 2018, 06:54:35 pm
content: Thermal noiseformula:If you type in bandwidth (delta F) 1KHz, you get −144 dBm. If you type in 1000 times smaller bandwidth 1Hz you get −174 dBm which isexactly 30dB lower value. Yes, FFT so to say splits spectrum into smaller bands and in result noise power for individual band decreases. As already said - it happens disregarding what type of "filtering" used. Unless someone quote me, OP will not see what I am telling here about noise. Just saying

author: Kleinstein
author_rank: Super Contributor
timestamp: September 22, 2018, 07:01:34 pm
content: Quote from: MasterT on September 22, 2018, 05:59:56 pmThe FFT is more efficient, if all bins are needed - but not that much. It depends on how the sin/cos values are provided. With FFT2048 the gain is more around 200 times (around 2028 / log 2048) if sin / cos values are from a table. However, if only 2 bins are needed (and the others are ignored) it is no more efficient - its more like the direct way is more efficient by maybe a factor of 10. In addition the direct way can use much less memory and thus possibly longer time windows if needed. The FFT would normally be limited by the memory.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 22, 2018, 10:04:40 pm
content: Quote from: Kleinstein on September 22, 2018, 07:01:34 pmI will try to explain one more time. I also gonna to put it into first initial message, to help others with the same doubts why is fft?Lets put 4 dots.Phase error - > SNR - > Bandwidth - > FFT.Is it so hard to connect those 4 dots? It's clear, that in order to get minimum phase error, bandwidth must be shrinked as much as possible. FFT here is the most efficient BPF, that allows to cut 244 Hz out of 250 kHz . Now, I 'd repeat last time, there is NO alternative to fft, stop crying about bins that goes to garbage can, fft is doing one specific function: it's sharply cut 244 Hz out of 250 kHz. Anything else, single bin DFT, Goertzel, FIR etc - don't do this simple task. Easy they are not able to shrink bandwidth, or they are extremely inefficient on a clock cycle scale.Quote from: Bud on September 22, 2018, 06:38:13 pmGood question. Initially, I was thinking to do just capacitor tester, C-V, C-F, ESR, quality etc. That's why 400V capacitor in drawings. To apply high voltage and trace capacitance lost. Than I changed my mind, and decided to complete AD5933 alternative, simple network-impedance analyzer.I came to conclusion, that better to leave capacitors in place, to keep DC blocking, doing so any active components could be tested. For example, gain/ phase chart for OPA. And there is also diodes/ series resistors - for safety, to prevent circuitry from careless operator, since test pad is exposed and anything could goes wrong, external DC , static discharge, high inductance creates huge EMF sparks etc.To test active component (amplifier) just connect reference channel - 220 OHm resistor to input, and output goes to 22k resistor. Variable cap shown on a drawings is an example of DUT cap.22k would creates slight load for amplifier output but it's negligible to any amp I know. And common ground should be connected of course. External DC power for amp (OPA) not limited to -+15 , can be higher up to +400V.There are two test connectors, x100 scale. DUT is plugged ether between 22k & ground or between 220 & ground. Ground referenced in both cases. Someone ask me a "theory of operation" , it's simplest voltage divider. One leg is a resistor, another leg - DUT. Things that voltage divider is under AC, does not change anything, it's still divider. I would not call it "half bridge" - do not want to generate more confusion.

author: ogden
author_rank: Super Contributor
timestamp: September 22, 2018, 11:04:18 pm
content: Quote from: MasterT on September 22, 2018, 10:04:40 pmOMGFFT is not a filter. FFT does not sharply cut it's bins. "Sharp cut" happens only when signal precisely "hits" bin frequency. If incoming signal frequency stand between two bins then both receive power, thus both have nonzero real/imag values after transform. Funny that "FFT vs DFT" topic is written in the chapter "FFT Basics" of the document OP is referring to:Quote from: MasterT on September 22, 2018, 05:43:07 pm

author: Dave
author_rank: Super Contributor
timestamp: September 23, 2018, 10:31:56 am
content: FFT is just a more efficient way to calculate DFT. It exploits the complex conjugate symmetry and periodicity of exp(-j*2*pi*k*n/N) and produces the same result with far fewer computational steps. You get the same benefits from DFT that you get from FFT, because FFTISDFT.It makes no sense whatsoever to use FFT when you're only interested in the results of just 1 or 2 bins. It's faster and less wasteful (in terms of RAM) to use DFT in this case.Quote from: MasterT on September 22, 2018, 10:04:40 pmYou seem to lack the very basic understanding of what FFT is and how it works. Perhapsthis videocan clear up some of your misconceptions.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 23, 2018, 01:17:08 pm
content: Quote from: Dave on September 23, 2018, 10:31:56 amI'm not commenting on FFT, there is another thread.https://www.eevblog.com/forum/microcontrollers/fft-processing-using-ucpu/Know it better than me, good, be happy. Stop talking, show your code. My FFT library is only 10% of on timing compare to Keil's, what is yours?

author: Dave
author_rank: Super Contributor
timestamp: September 23, 2018, 02:54:59 pm
content: Quote from: MasterT on September 22, 2018, 10:04:40 pmQuote from: MasterT on September 23, 2018, 01:17:08 pmHmm... what could possibly make me think otherwise?Quote from: MasterT on September 23, 2018, 01:17:08 pmBoy, it sure is difficult to acknowledge you were wrong, isn't it?It doesn't matter how efficient your FFT implementation is, it's never going to be more efficient than a single bin DFT. You can convince yourself that you're right as much as you want, but you're arguing against the laws of mathematics here.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 23, 2018, 03:32:18 pm
content: Quote from: Dave on September 23, 2018, 02:54:59 pmNothing of the kind. Is it engineering forum? I don't like to be involved in any philosophical / political / or abstract mathematics debates. And I 'm not worry if there is a life on a Venus. The point is, engineers should talk in different terms, leaving abstract "better", "less memory" " faster". Tell me in dB, uVolts, microseconds, or in this particular case, tell me the Bandwidth in Hz for single bin DFT. There is no issue with pure math, consider ratio: "Bandwidth / Clock_cycles_uCPU".I'm not argue, that single bin (6-8 math operation code) is faster than 2048 bins, it's all about bandwidth (second page in a row).For single bin Bandwidth is 250 kHz.

author: radioactive
author_rank: Regular Contributor
timestamp: September 23, 2018, 03:42:20 pm
content: The Goertzel algorithm is even more efficient than a single-bin DFT.https://www.dsprelated.com/showarticle/495.php

author: ogden
author_rank: Super Contributor
timestamp: September 23, 2018, 03:52:46 pm
content: Quote from: MasterT on September 23, 2018, 03:32:18 pmLOL it is already said here in this thread. He not only ignores my posts but most likely ignore posts of everybody but him:Quote from: xaxaxa on September 22, 2018, 01:47:56 am Please somebody poke him with xaxaxa post

author: Kleinstein
author_rank: Super Contributor
timestamp: September 23, 2018, 08:08:49 pm
content: It dependents on the way the sin / cos values are calculated. With an efficient method (e.g. table or cordic like (Görtzel algorithm or similar)) the DFT for 2 bins is usually more computational efficient than the full FFT and ignoring most of the data. The result is essentially the same, except for possible rounding errors, that should not be significant for 12 Bit raw data. It is just a different way of calculation. So the effective BW is exactly the same.The expected advantage in computation time is about about a factor of 10 (details depend on the µC). The DFT code can definitely do real time operation, that is doing the calculation as fast as the data come in at 1 MSPS. Depending on the µC and compiler used one might get something like 8-30 µC cycles per ADC sample. There is a slight chance the FFT code could also operate real time with 1 MSPS data, though it would be hard and need a faster µC.The memory use is much lower for the DFT - something like 2 or 4 numbers of about 32 Bit, maybe even 16 bit. For the same window length the result is essentially the same, so no difference in SNR ratio. The DFT solution is flexible to allow longer windows if needed, as there is essentially no memory limitation. In this case a slightly better SNR would be possible. However even with FFT data there is also a chance to use coherent averaging over longer time and thus the same SNR.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 23, 2018, 08:34:00 pm
content: Quote from: Kleinstein on September 23, 2018, 08:08:49 pmThis is where you do a big mistake. BW is Not the same. SNR is not the same. Stop fooling yourself, there is no free cheese in the mouse trap.Reducing fft code down, in any manner, gaining in memory or clock cycles is become NON relevant, since you are getting the product with lower quality. Lower freq. resolution per bin , lower SNR, missing imaginary part (DCT) etc.It's same as small print on your insurance policy, bunch of crooks advertise you different variety of the fft, but any variation isa crap, if you look more carefully into the output.Getting back to the numbers, Görtzel algorithm is unable to select channel 244 Hz wide at 249 756 Hz. Never ever.

author: Kleinstein
author_rank: Super Contributor
timestamp: September 23, 2018, 09:00:53 pm
content: The DFT result is the same (except minor rounding differences) as FFT. One needs the second bin to get the imaginary part. So using the 2 bins DFT instead of the FFT is just a different computational method, but essentially the same result.The FFT algorithm is the most efficient known way if all bins are needed. However it isnotthe most efficient way anymore if one only needs 2 bins.The exact speed does not matter - the question is only if the FFT code could be fast enough to do the calculations in real time, I have some doubt it can with the STM32F3... Even if fast enough, there is the limitation with memory usage.The possible frequency resolution with the Görtzel Algorithm only depends on the time used and the numerical accuracy. So with enough resolution (e.g. 32 Bit data) the resolution can be way better than 1 Hz in 1 MHz if needed. It just needs time (e.g. a few seconds).

author: ogden
author_rank: Super Contributor
timestamp: September 23, 2018, 09:16:27 pm
content: Quote from: Kleinstein on September 23, 2018, 09:00:53 pmThis sentence is said like five times here in this thread? Your patience is unrealQuote from: MasterT on September 23, 2018, 08:34:00 pmRight. BW of FFT and DFT. If such actually exists

author: MasterT
author_rank: Frequent Contributor
timestamp: September 23, 2018, 10:03:59 pm
content: Quote from: Kleinstein on September 23, 2018, 09:00:53 pmTime frame is already defined, I have 2048 samples accumulated in data pull, please give me a favor - run Goertzel and see what frequency resolution you would get.If you are saying, that 1 000 000 samples has to be processed, to get EQUAL to fft-2048 frequency resolution (244 Hz) , than calculate clock cycles you spend and compare to fft-2048 , I'm sure that would surprise you. Goertzel gonna to loose quite a lot to get same numbers.Ratio : " BW / Clock_Cycles", if you are pulling one (BW) or another "Clock_Cycles" out of equation, you are trying to cheat. It's not a poker.Both parameters has to be evaluated in the same time frame, numbers of samples, same test condition. Otherwise you are manipulating data.

author: radioactive
author_rank: Regular Contributor
timestamp: September 23, 2018, 10:15:45 pm
content: This might help with evaluating.I started with a C implementation of the Goertzel algorithm from here:https://www.embedded.com/design/configurable-systems/4024443/The-Goertzel-AlgorithmI hacked it up to add the FFT to compare against. It depends on libfftwhttp://www.fftw.org/compile itgcc goertzel_test.c -o goertzel_test -lm -lc -lfftw3The magnitudes are almost identical over a narrow sweep around the "frequency bin of interest" just to make it visually interesting.This is a very good reference from Richard Lyons bookhttps://www.embedded.com/design/real-world-applications/4401754/Single-tone-detection-with-the-Goertzel-algorithm

author: Dave
author_rank: Super Contributor
timestamp: September 23, 2018, 10:18:43 pm
content: Quote from: MasterT on September 23, 2018, 03:32:18 pmSure, let's pretend that "better", "less memory" and "faster" are open to any kind of interpretation.Attached to this message is a MATLAB script that I've written to compare DFT and FFT. Save the file and change the file extension to .m (the forum does not allow .m files). Run it and carefully read through the code.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 23, 2018, 10:54:10 pm
content: Quote from: Dave on September 23, 2018, 10:18:43 pmI'm "self-educated" in C and Java, have EE degree from Russia. But we didn't study matlab in 90-s, sorry for disappointing, no I'm not a digital robot.Quote from: radioactive on September 23, 2018, 10:15:45 pmThanks for sharing, I will test your code in Qt, though I already know the answer.

author: Dave
author_rank: Super Contributor
timestamp: September 23, 2018, 11:26:51 pm
content: This is the output of my script.Top graph is magnitude, bottom is phase. Red line with points is DFT, green dashed line is FFT.

author: radioactive
author_rank: Regular Contributor
timestamp: September 24, 2018, 12:28:27 am
content: Quote from: radioactive on September 23, 2018, 10:15:45 pmQuoteDon't bother. I just realized you need the complex input/output for your application. Goertzel algorithm will work almost exactly as FFT/DFT for calculating magnitude from real data, but you need complex input/output for your application. I will add that I do agree with the others here suggesting that a single-bin DFT would be more optimal for N=2048 and completely identical in output compared to FFT (including your bandwidth concerns). They are the same thing. Others have already said it, but FFT is better only if you need to calculate *all* of the bins.Sorry for not taking a look at your project video before my earlier posts. It looks really great!

author: Bud
author_rank: Super Contributor
timestamp: September 24, 2018, 01:12:49 am
content: What i think is fft or not is the least of the worries so to speak. I think some the device architecture needs a few clarifications. What calibrations do you perform to remove systematic errors?

author: Mechatrommer
author_rank: Super Contributor
timestamp: September 24, 2018, 02:12:50 am
content: Quote from: MasterT on September 23, 2018, 03:32:18 pmeveryday i learn new thing.. today isGoertzel Algorithmif you just dont care to read here is the snip from Goertzel...Quotewhen Goertzel said computation efficient for single or few bins, it means the same bin as we speak when we calculate DFT or FFT, the resolution for each bin will be = sample rate / number of points / 2. whether DFT, FFT, or Goertzel algorithm they are the same. Goertzel was not fooling around when formulating the single bin algorithm. nobody want to argue with Goertzel that his bin's resolution will be = (sample rate / 2) aka BW. i think the confusion happened (vocabulary) is between DFT and Goertzel. the competition of FFT is not between DFT (FFT is derivative or DFT we know that), but the competition should be between FFT and Goertzel (single bin DFT) and again, the resolution of the single bin of Goertzel will be just the same as bins for DFT or FFT. fwiw...

author: radioactive
author_rank: Regular Contributor
timestamp: September 24, 2018, 02:26:39 am
content: Quote from: Mechatrommer on September 24, 2018, 02:12:50 amTrue, I showed that in an example a couple of posts ago, but the issue in this instance is that the Goertzel algorithm is good for real data input. I think the OP needs complex input for his application (feel free to correct me if I'm wrong here). The single-bin DFT, as others have pointed out many times, should be more efficient and identical to FFT in this case. Goertzel is good for applications where you want to optimally detect a single frequency in magnitude (e.g. DTMF detection). The computational savings would be very good for N=2048...

author: Mechatrommer
author_rank: Super Contributor
timestamp: September 24, 2018, 02:32:32 am
content: Quote from: radioactive on September 24, 2018, 02:26:39 amthere is no mentioning that Goertzel is limited to real part only, (istr there is even faster algortihm than FFT when calculating real part only) so Goertzel should be capable of calculating both the magnitude and phase, as others linked the Impedance Measurement Techique by Keysight (i think Goertzel algorithm is used in there but not sure didnt read) its just a matter of the OP reading carefully and understanding how Goertzel formulation works, and start coding it in complex number, he got ee degree aye? i dont. he should be able to implement it in C/C++

author: radioactive
author_rank: Regular Contributor
timestamp: September 24, 2018, 02:39:36 am
content: Quote from: Mechatrommer on September 24, 2018, 02:32:32 amI think at the point that you implement that, it probably won't have any gains over the single-bin DFT (again correct me if I'm wrong). I used Goertzel in an FPGA application where I didn't have enough cells for FFT in the past, but I was only interested in magnitude. It worked quite well. fixed quote block

author: Mechatrommer
author_rank: Super Contributor
timestamp: September 24, 2018, 03:18:16 am
content: Quote from: radioactive on September 24, 2018, 02:39:36 amnot sure if Goertzel is optimized single bin DFT for real part, cant differ, but i think even when calculating imaginary part in single-bin DFT (or maybe Goertzel?), the complexity should still near O(n) or O(2n)? still better than O(n.log(n)) if n > 100 or something.as from the hardware side, there are interesting topology or some sort of impedance divider going on, but its not clear since there are few broken traces so i dont know where the DUT will be connected to. i agree i have to vote this device is more toward "Impendace Analyzer" or "Bode Plotter" as video in the OP, there is no direct S21 measurement let alone S11. so VNA is probably just a marketing hype from Analog Devices or the OP. i look uphttp://www.analog.com/media/en/technical-documentation/data-sheets/AD5933.pdfthe OP circuit front end doesnt resemble anything like the diagrams in the datasheet nor this..fromhttp://www.analog.com/en/applications/markets/instrumentation-and-measurement-pavilion-home/electronic-test-and-measurement/rf-signal-analyzers-and-vector-network-analyzers.html

author: ogden
author_rank: Super Contributor
timestamp: September 24, 2018, 07:12:35 am
content: Quote from: Mechatrommer on September 24, 2018, 02:32:32 amThey use DFT. Also it shall be noted that VNA's/LCR's usually does not do direct sampling but have heterodyne architecture with fixed, low IF frequency so it can be sampled using high resolution ADC's.Agilent E5063A Network Analyzer Help:The digital filter performs a discrete Fourier transformation (DFT) and picksup IF signals. Each IF signal is then converted into a complex number thathas a real part and an imaginary part. The IF bandwidth of the analyzer isequivalent to the bandwidth of the DFT filter.Google for "e5063a_operation.pdf"

author: MasterT
author_rank: Frequent Contributor
timestamp: September 25, 2018, 04:41:54 pm
content: Quote from: radioactive on September 24, 2018, 12:28:27 amNo, pure real data in this project, I'm not doing reverse IFFT, and adc is always realThanks again for posting a code, it has more value for me than a million words. I really appreciate, when conversation is going more specific, down to earth - digits in this particular case.Running this piece of code up and down, I finally created the test procedure, that Magnifying the small prints in your insurance policy, I was talking about.Excuse for delay to everyone, who is reading this, was busy doing testing with a code. Here is what I came up to.Test condition://https://www.embedded.com/design/configurable-systems/4024443/The-Goertzel-AlgorithmGoertzel algorithm is initialized to detect Target Frequency = 500.//FFT is my own, feel free to replace it with whatever you like, FFTW, CMSIS-DSP pack etc.FFT algorithm doesn't need to be initialized, magnitude is extracted at:Resolution = sampling freq. /256 = 31.25 HzBin = target /resolution = 500 / 31.25 = 16.No windowing function is applied in this test, not to obscure the purpose of the testing.Input:Single tone sine wave, no phase data, no noise added in this test.Test tone is swapped from 0 to Nyquist = sampling /2.Swapped tone is stepping at 31.25 Hz, since there was no windowing function, stepping goes at exact "bin's frequencies" inorder to prevent any side lobes that would be generated otherwise and ruin the objective of this test.When test tone "hits" a target frequency, detection happened and magnitude is recorded.Any other frequencies, except target, becomes in this case "interference", "noise" or "adjacent channel power ratio".Obviously, dsp core (Goertzel or FFT) Must eliminate any interference getting into the target frequency (detection band).The magnitude of the interference is preset to -40 dB, 20.47 riding over 2047 DC level - 12-bits ADC approximation.To precisely evaluate this "interference withstanding" or "noise reduction" capability of the dsp-core SINAD is calculated :sinad = (20.0 * log10(temp /tot_magnt));where tot_magnt is RMS of all interference getting into detection band,and variable "temp" is assigned to magnitude at Target frequency.Results:bin 2620.176270 tot_m 1.124978 sinad_grt 67.343732bin 2620.160156 tot_m 0.020573 sinad_fft 102.100667You see, there is 35 dB (!) difference in the SNR.Goertzel is miserable failed on the objective.NB1:Not sure what is correct name for this test would be. I already used hardware analogy with pre-selector, so "selectivity" comes to mind.NB2:I agree, that using "bandwidth" was wrong on my side, indeed BW (defined in terms of sqrt(2)) is practically identical betweensingle bin (Goertzel) and FFT.Can't explain any better.Code:Code:#include <stdio.h>#include <math.h>#include <stdlib.h>#define SAMPLING_RATE 8000.0// 8kHz#define TARGET_FREQUENCY 500 //1875//941.0//941 Hz#define N 256 //205//Block size//bin 2559.962402 tot_m 1.118038 sinad_grt 67.195540//bin 2559.995117 tot_m 0.020119 sinad_fft 102.092452float coeff;float Q1;float Q2;float sine;float cosine;double testData;/*//bin 2559.989502 tot_m 0.182476 sinad_grt 82.940644//bin 2559.995117 tot_m 0.020119 sinad_fft 102.092452double coeff;double Q1;double Q2;double sine;double cosine;double testData;*/#define FFT_SIZE N#define MIRROR (FFT_SIZE / 2)void ResetGoertzel(void){Q2 = 0;Q1 = 0;}void InitGoertzel(void){intk;floatfloatN;floatomega;floatN = (float) N;k = (int) (0.5 + ((floatN * TARGET_FREQUENCY) / SAMPLING_RATE));omega = (2.0 * M_PI * k) / floatN;sine = sin(omega);cosine = cos(omega);coeff = 2.0 * cosine;printf("For SAMPLING_RATE = %f", SAMPLING_RATE);printf(" N = %d", N);printf(" and FREQUENCY = %d,\n", TARGET_FREQUENCY);printf("k = %d and coeff = %f, sine = %f, cosine = %f\n\n", k, coeff, sine, cosine);ResetGoertzel();}void Processfloat(float sample){float Q0;Q0 = coeff * Q1 - Q2 + (float) sample;Q2 = Q1;Q1 = Q0;}void GetRealImag(float *realPart, float *imagPart){*realPart = (Q1 - Q2 * cosine);*imagPart = (Q2 * sine);}float GetMagnitudeSquared(void){float result;result = Q1 * Q1 + Q2 * Q2 - Q1 * Q2 * coeff;return result;}void Generate(float frequency){intindex;floatstep;step = frequency * ((2.0 * M_PI) / SAMPLING_RATE);for( index = 0; index < N; index++) {testData = 20.470 * sin(index * step) +2047.0;}}void GenerateAndTest_GRT(float frequency, float *result){intindex;floatmagnitudeSquared;floatmagnitude;floatreal;floatimag;printf("F1=%7.2f, ", frequency);Generate(frequency);/*// 2.Windowingdouble base_angle = 2.0 *M_PI / (FFT_SIZE -1);for( int16_t i = 0; i < FFT_SIZE; i++ ) {double angle = i *base_angle;float temp = 0.35875 -(0.48829*cos(angle)) +(0.14128*cos(2*angle)) -(0.01168*cos(3*angle));// testData *= temp;testData *= (0.5 - (0.5 * cos( 2 *M_PI *i /(FFT_SIZE -1))));}*/for( index = 0; index < N; index++) {//Processfloat(testData);float Q0;Q0 = coeff * Q1 - Q2 + (float)testData;Q2 = Q1;Q1 = Q0;}GetRealImag(&real, &imag);// printf("r= %15.5f i= %15.5f", real, imag);magnitudeSquared = real*real + imag*imag;// printf("rel mag^2=%16.5f ", magnitudeSquared);magnitude = sqrt(magnitudeSquared);// printf("mag=%15.5f\n", magnitude);printf("mag=%15.5f", magnitude);ResetGoertzel();*result = magnitude;}// FFTvoid rev_bin( float *fr, int16_t fft_n){int m, mr, nn, l;float tr;mr = 0;nn = fft_n - 1;for (m=1; m<=nn; ++m) {l = fft_n;do {l >>= 1;} while (mr+l > nn);mr = (mr & (l-1)) + l;if (mr <= m)continue;tr = fr;fr = fr;fr = tr;}}void get_MagnitF(float *fr){for(int i = 1; i < MIRROR; i++) {float real = fr;float imag = fr[FFT_SIZE -i];float Magnit = (float) (sqrt((real * real) + (imag * imag)));fr = Magnit;}}void rfft33(float X[], int Nd){/***************************************************************************** rfft(float X[],int N) ** A real-valued, in-place, split-radix FFT program ** Decimation-in-time, cos/sin in second loop ** Length is N=2**M (i.e. N must be power of 2--no error checking) ** ** Original Fortran code by Sorensen; published in H.V. Sorensen, D.L. Jones,** M.T. Heideman, C.S. Burrus (1987) Real-valued fast fourier transform ** algorithms. IEEE Trans on Acoustics, Speech, & Signal Processing, 35, ** 849-863. Adapted to C by Bill Simpson, 1995 wsimpson@uwinnipeg.ca ** --------------------------------------------------------------------------** C/C++ language bugs fixing & correction: ** 1. C-style array start adress ; ** 2. SIN() and COS tweed factors change place; ** 3. Rev Bin - replaced by new fastest version. ** made by Anatoly Kuzmenko, 2017, anatolyk69@gmail.com *****************************************************************************/int I, I0, I1, I2, I3, I4, I5, I6, I7, I8, IS, ID;int J, K, M, N2, N4, N8;float A, A3, CC1, SS1, CC3, SS3, E, R1;float T1, T2, T3, T4, T5, T6;M = (int)(log(N) / log(2.0)); /* N=2^M *//* ----Length two butterflies--------------------------------------------- */IS = 0;ID = 4;do {for (I0 = IS; I0 < Nd; I0 += ID) {I1 = I0 + 1;R1 = X;X = R1 + X;X = R1 - X;}IS = 2 * ID - 2;ID = 4 * ID;} while (IS < Nd);/* ----L shaped butterflies----------------------------------------------- */N2 = 2;for (K = 1; K < M; K++) {N2 = N2 * 2;N4 = N2 / 4;N8 = N2 / 8;E = (float) 6.2831853071719586f / N2;IS = 0;ID = N2 * 2;do {for ( I = IS; I < Nd; I += ID) {I1 = I; // + 1;I2 = I1 + N4;I3 = I2 + N4;I4 = I3 + N4;T1 = X + X;X = X - X;X = X - T1;X = X + T1;if (N4 != 1) {I1 += N8;I2 += N8;I3 += N8;I4 += N8;T1 = (X + X) * .7071067811865475244f;T2 = (X - X) * .7071067811865475244f;X = X - T1;X = -X - T1;X = X - T2;X = X + T2;}}IS = 2 * ID - N2;ID = 4 * ID;} while ( IS < Nd );A = E;for ( J = 1; J < N8; J++) {A = (float)J * E;A3 = 3.0 * A;CC1 = cos( A);SS1 = sin( A);CC3 = cos(A3);SS3 = sin(A3);IS = 0;ID = 2 * N2;do {for ( I = IS; I < Nd; I += ID) {I1 = I + J;I2 = I1 + N4;I3 = I2 + N4;I4 = I3 + N4;I5 = I + N4 - J;// + 2;I6 = I5 + N4;I7 = I6 + N4;I8 = I7 + N4;T1 = X * CC1 + X * SS1;T2 = X * CC1 - X * SS1;T3 = X * CC3 + X * SS3;T4 = X * CC3 - X * SS3;T5 = T1 + T3;T6 = T2 + T4;T3 = T1 - T3;T4 = T2 - T4;T2 = X + T6;X = T6 - X;X = T2;T2 = X - T3;X = -X - T3;X = T2;T1 = X + T5;X = X - T5;X = T1;T1 = X + T4;X = X - T4;X = T1;}IS = 2 * ID - N2;ID = 4 * ID;} while ( IS < Nd );}}}void GenerateAndTest_FFT(float frequency, float *result){floatmagnitude;Generate(frequency);float fr;for( int16_t i = 0; i < FFT_SIZE; i++ ) {fr = (float)testData;}/*printf(" X Input Data \n");for ( int i = 0; i < FFT_SIZE; i++){ printf("%8.1f", fr);if ((i+1)%16 == 0) printf("\n");}printf("\n.........................................\n");*//*// 2.Windowingdouble base_angle = 2.0 *M_PI / (FFT_SIZE -1);for( int16_t i = 0; i < FFT_SIZE; i++ ) {double angle = i *base_angle;float temp = 0.35875 -(0.48829*cos(angle)) +(0.14128*cos(2*angle)) -(0.01168*cos(3*angle));// fr *= temp;fr *= (0.5 - (0.5 * cos( 2 *M_PI *i /(FFT_SIZE -1))));}*//*printf(" X Input Data \n");for ( int i = 0; i < FFT_SIZE; i++){ printf("%8d", fr);if ((i+1)%16 == 0) printf("\n");}printf("\n.........................................\n");*/rev_bin( fr, (int16_t) FFT_SIZE);/*printf(" X Input Data \n");for ( int i = 0; i < FFT_SIZE; i++){ printf("%8.0f", fr);if ((i+1)%16 == 0) printf("\n");}printf("\n.........................................\n");*/rfft33( fr, FFT_SIZE);/*printf(" X Output Data \n");for ( int i = 0; i < FFT_SIZE; i++){ printf("%8.0f", fr);if ((i+1)%16 == 0) printf("\n");}printf("\n.........................................\n");*/get_MagnitF(fr);/*printf(" X Output Data \n");for ( int i = 0; i < MIRROR; i++){ printf("%8.0f", fr);if ((i+1)%16 == 0) printf("\n");}printf("\n.........................................\n");*/magnitude = fr;printf(" mag=%15.5f\n", magnitude);*result = magnitude;}int main(void){float freq;InitGoertzel();float test;float snr_grt = { 0.0};float snr_fft = { 0.0};int index = 0;float step = SAMPLING_RATE / FFT_SIZE;// for (freq = TARGET_FREQUENCY - 300; freq <= TARGET_FREQUENCY + 300; freq += 15)// for( freq = 0.0; freq < SAMPLING_RATE /2.0; freq += 31.25) {for( freq = 0.0; freq < SAMPLING_RATE /2.0; freq += step) {GenerateAndTest_GRT(freq, &test);snr_grt = test;GenerateAndTest_FFT(freq, &test);snr_fft = test;if(index >= MIRROR) break;index++;}/*printf(" snr_grt \n");for( int i = 0; i < MIRROR; i++) {printf("%15.6f", snr_grt);if ((i+1)%8 == 0) printf("\n");}printf("\n.........................................\n");printf(" snr_fft \n");for( int i = 0; i < MIRROR; i++) {printf("%15.6f", snr_fft);if ((i+1)%8 == 0) printf("\n");}printf("\n.........................................\n");*/int bin_numbr = 16;double tot_magnt = 0;double temp = 0.0;double sinad = 0.0;for( int i = 0; i < MIRROR; i++) {if(i == bin_numbr) continue;temp = snr_grt;tot_magnt += (temp * temp);}tot_magnt = sqrt(tot_magnt);if (tot_magnt == 0) tot_magnt = 0.000001;temp = snr_grt;sinad = (20.0 * log10(temp /tot_magnt));printf("\n bin %12.6f", temp);printf(" tot_m %12.6f", tot_magnt);printf(" sinad_grt %12.6f", sinad);tot_magnt = 0;temp = 0.0;sinad = 0.0;for( int i = 0; i < MIRROR; i++) {if(i == bin_numbr) continue;temp = snr_fft;tot_magnt += (temp * temp);}tot_magnt = sqrt(tot_magnt);if (tot_magnt == 0) tot_magnt = 0.000001;temp = snr_fft;sinad = (20.0 * log10(temp /tot_magnt));printf("\n bin %12.6f", temp);printf(" tot_m %12.6f", tot_magnt);printf(" sinad_fft %12.6f", sinad);return 0;}Raw data:Code:For SAMPLING_RATE = 8000.000000 N = 256 and FREQUENCY = 500,k = 16 and coeff = 1.847759, sine = 0.382683, cosine = 0.923880F1= 0.00, mag= 0.10611 mag= 0.00000F1= 31.25, mag= 0.09423 mag= 0.00000F1= 62.50, mag= 0.10754 mag= 0.00000F1= 93.75, mag= 0.08793 mag= 0.00000F1= 125.00, mag= 0.11068 mag= 0.00000F1= 156.25, mag= 0.07982 mag= 0.00000F1= 187.50, mag= 0.11203 mag= 0.00000F1= 218.75, mag= 0.07678 mag= 0.00000F1= 250.00, mag= 0.09029 mag= 0.00000F1= 281.25, mag= 0.10285 mag= 0.00000F1= 312.50, mag= 0.08015 mag= 0.00000F1= 343.75, mag= 0.10285 mag= 0.00000F1= 375.00, mag= 0.09063 mag= 0.00000F1= 406.25, mag= 0.09256 mag= 0.00000F1= 437.50, mag= 0.08764 mag= 0.00000F1= 468.75, mag= 0.09484 mag= 0.00000F1= 500.00, mag= 2620.17627 mag= 2620.16016F1= 531.25, mag= 0.10418 mag= 0.00000F1= 562.50, mag= 0.10534 mag= 0.00000F1= 593.75, mag= 0.10568 mag= 0.00000F1= 625.00, mag= 0.09694 mag= 0.00000F1= 656.25, mag= 0.08705 mag= 0.00000F1= 687.50, mag= 0.09377 mag= 0.00000F1= 718.75, mag= 0.09259 mag= 0.00000F1= 750.00, mag= 0.10259 mag= 0.00195F1= 781.25, mag= 0.08477 mag= 0.00000F1= 812.50, mag= 0.10585 mag= 0.00000F1= 843.75, mag= 0.10384 mag= 0.00000F1= 875.00, mag= 0.10069 mag= 0.00000F1= 906.25, mag= 0.10469 mag= 0.00000F1= 937.50, mag= 0.11233 mag= 0.00000F1= 968.75, mag= 0.09861 mag= 0.00000F1=1000.00, mag= 0.11733 mag= 0.00391F1=1031.25, mag= 0.10588 mag= 0.00000F1=1062.50, mag= 0.09900 mag= 0.00000F1=1093.75, mag= 0.09996 mag= 0.00000F1=1125.00, mag= 0.09220 mag= 0.00000F1=1156.25, mag= 0.11435 mag= 0.00000F1=1187.50, mag= 0.09662 mag= 0.00000F1=1218.75, mag= 0.10372 mag= 0.00000F1=1250.00, mag= 0.09398 mag= 0.00276F1=1281.25, mag= 0.09437 mag= 0.00000F1=1312.50, mag= 0.09865 mag= 0.00000F1=1343.75, mag= 0.11403 mag= 0.00000F1=1375.00, mag= 0.10098 mag= 0.00000F1=1406.25, mag= 0.08598 mag= 0.00000F1=1437.50, mag= 0.10105 mag= 0.00000F1=1468.75, mag= 0.09867 mag= 0.00000F1=1500.00, mag= 0.10565 mag= 0.00485F1=1531.25, mag= 0.09424 mag= 0.00000F1=1562.50, mag= 0.09212 mag= 0.00000F1=1593.75, mag= 0.10664 mag= 0.00000F1=1625.00, mag= 0.11636 mag= 0.00195F1=1656.25, mag= 0.08445 mag= 0.00000F1=1687.50, mag= 0.10084 mag= 0.00000F1=1718.75, mag= 0.09308 mag= 0.00000F1=1750.00, mag= 0.10372 mag= 0.00249F1=1781.25, mag= 0.09571 mag= 0.00000F1=1812.50, mag= 0.09840 mag= 0.00000F1=1843.75, mag= 0.10246 mag= 0.00000F1=1875.00, mag= 0.11236 mag= 0.00195F1=1906.25, mag= 0.11003 mag= 0.00000F1=1937.50, mag= 0.10503 mag= 0.00000F1=1968.75, mag= 0.11180 mag= 0.00000F1=2000.00, mag= 0.09783 mag= 0.00254F1=2031.25, mag= 0.09688 mag= 0.00000F1=2062.50, mag= 0.09493 mag= 0.00000F1=2093.75, mag= 0.09357 mag= 0.00000F1=2125.00, mag= 0.09151 mag= 0.00000F1=2156.25, mag= 0.10432 mag= 0.00000F1=2187.50, mag= 0.09754 mag= 0.00000F1=2218.75, mag= 0.10882 mag= 0.00195F1=2250.00, mag= 0.10045 mag= 0.00202F1=2281.25, mag= 0.11314 mag= 0.00000F1=2312.50, mag= 0.09258 mag= 0.00000F1=2343.75, mag= 0.09818 mag= 0.00000F1=2375.00, mag= 0.11400 mag= 0.00195F1=2406.25, mag= 0.09444 mag= 0.00000F1=2437.50, mag= 0.10033 mag= 0.00000F1=2468.75, mag= 0.07606 mag= 0.00000F1=2500.00, mag= 0.10632 mag= 0.00465F1=2531.25, mag= 0.11568 mag= 0.00000F1=2562.50, mag= 0.11631 mag= 0.00000F1=2593.75, mag= 0.10031 mag= 0.00000F1=2625.00, mag= 0.10132 mag= 0.00000F1=2656.25, mag= 0.10407 mag= 0.00000F1=2687.50, mag= 0.10097 mag= 0.00000F1=2718.75, mag= 0.07938 mag= 0.00195F1=2750.00, mag= 0.09015 mag= 0.00383F1=2781.25, mag= 0.11763 mag= 0.00195F1=2812.50, mag= 0.09597 mag= 0.00000F1=2843.75, mag= 0.10604 mag= 0.00000F1=2875.00, mag= 0.11056 mag= 0.00195F1=2906.25, mag= 0.09866 mag= 0.00000F1=2937.50, mag= 0.09622 mag= 0.00000F1=2968.75, mag= 0.09654 mag= 0.00361F1=3000.00, mag= 0.08598 mag= 0.00149F1=3031.25, mag= 0.09443 mag= 0.00289F1=3062.50, mag= 0.10529 mag= 0.00383F1=3093.75, mag= 0.10426 mag= 0.00195F1=3125.00, mag= 0.07579 mag= 0.00361F1=3156.25, mag= 0.08571 mag= 0.00000F1=3187.50, mag= 0.11280 mag= 0.00000F1=3218.75, mag= 0.07765 mag= 0.00000F1=3250.00, mag= 0.09780 mag= 0.00195F1=3281.25, mag= 0.08297 mag= 0.00000F1=3312.50, mag= 0.09670 mag= 0.00195F1=3343.75, mag= 0.11009 mag= 0.00000F1=3375.00, mag= 0.11433 mag= 0.00345F1=3406.25, mag= 0.10358 mag= 0.00000F1=3437.50, mag= 0.09293 mag= 0.00195F1=3468.75, mag= 0.11226 mag= 0.00868F1=3500.00, mag= 0.12093 mag= 0.00379F1=3531.25, mag= 0.10341 mag= 0.00000F1=3562.50, mag= 0.10189 mag= 0.00076F1=3593.75, mag= 0.11852 mag= 0.00195F1=3625.00, mag= 0.08856 mag= 0.00217F1=3656.25, mag= 0.11255 mag= 0.00000F1=3687.50, mag= 0.10105 mag= 0.00195F1=3718.75, mag= 0.11565 mag= 0.00518F1=3750.00, mag= 0.08955 mag= 0.00293F1=3781.25, mag= 0.09275 mag= 0.00195F1=3812.50, mag= 0.10781 mag= 0.00000F1=3843.75, mag= 0.10727 mag= 0.00000F1=3875.00, mag= 0.09191 mag= 0.00546F1=3906.25, mag= 0.09398 mag= 0.00656F1=3937.50, mag= 0.09004 mag= 0.00000F1=3968.75, mag= 0.10833 mag= 0.00000bin 2620.176270 tot_m 1.124978 sinad_grt 67.343732bin 2620.160156 tot_m 0.020573 sinad_fft 102.100667

author: ogden
author_rank: Super Contributor
timestamp: September 25, 2018, 08:30:02 pm
content: Quote from: MasterT on September 25, 2018, 04:41:54 pmAuthor (who does not read my posts anymore) "conveniently forgot" that only FFT have granularity and bins. When you use DFT in VNA/LCR_meter - you "tune" it precisely to the test frequency and such thing as "interference withstanding" or "noise reduction" is irrelevant. Of course Goertzel with float coefficients can't win float FFT implementation that does not even use tables but plain sin() cos(). Why would someone need to write such a test to prove that?QuoteThis comes into mind:

author: radioactive
author_rank: Regular Contributor
timestamp: September 25, 2018, 11:01:39 pm
content: Quote from: MasterT on September 25, 2018, 04:41:54 pmI don't understand the need to calculate SNR over the entire channel if you are only interested in the results of a single bin. I think the difference in results are because of floating point precision. Just to test that idea, I changed every float type in your test code to double and then implemented a test to run on a Cortex M7 MCU (results are the same on PC). I also added a test to compare the execution time of Goertzel vs your implementation of FFT. With doubles it appears that Goertzel has SNR improvement of 94 dB over FFT (using your calculations of SNR). It executes about 3x faster with your current configuration of N=256. I didn't try to optimize the initGoertzel() function either, so might gain a little there too.Code:static int grt_count;static int fft_count;static uint32_t grt_st_time;static uint32_t fft_st_time;static uint32_t grt_end_time;static uint32_t fft_end_time;//in main while loop//while(1) {current_time = HAL_GetTick(); //millisecondsif(grt_count<1000) {if(grt_count==0) grt_st_time=current_time;test_grt(0);grt_count++;if(grt_count==1000) {grt_end_time=current_time;printf("\r\ngrt total time for 1k runs %d", grt_end_time-grt_st_time);test_grt(1); //print the SNR results}}else if(fft_count<1000) {if(grt_count==0) fft_st_time=current_time;test_fft(0);fft_count++;if(fft_count==1000) {fft_end_time=current_time;printf("\r\nfft total time for 1k runs %d", fft_end_time-fft_st_time);test_fft(1); //print the SNR results}}}Results:grt total time for 1k runs 21173bin 2620.160000 tot_m 0.000000 sinad_grt 251.172854fft total time for 1k runs 63307bin 2620.159989 tot_m 0.000040 sinad_fft 156.307001Even so, I guess that savings in time might not be worth messing with in your case. If the FFT is working great and there is no need to improve the timing, you have already validated the FFT. I don't see a need to change it. It gets the job done.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 26, 2018, 01:32:45 pm
content: Quote from: radioactive on September 25, 2018, 11:01:39 pmRight, floating point type is generating rounding noise.1. The problem with a Goertzel (as any IIR) it demands 64-bits math, same time fft runs smooth and easy on 32-bits. SAM3X8E is 32-bits, w/o FPU, so difference in the time execution has to be verified on my DUE. Difference in 64-bits Goertzel vs 32-bits FFT.2. Next, in the initial code you omitted windowing function, and this comparison 3x in timing is not correct, iffft-time / grt-time = 3, than(fft-time + windowing) / (grt-time + windowing) != 3.3. Phase data I calculated out of Goertzel is not correct, error seems consistent 22.5 degree "off" - that may be corrected or not, anyway needs more testing to be verified in all circumstances.//All this hussle was started by people persistently pointing me that fft for single bin doesn't make any sense.

author: Bud
author_rank: Super Contributor
timestamp: September 26, 2018, 01:38:03 pm
content: This exersize in comparing sampling algorithm is pointless without a calibration procedure. You can fft until cows come home and get meaningless results because of the systematic errors not being removed.

author: ogden
author_rank: Super Contributor
timestamp: September 26, 2018, 01:52:07 pm
content: Quote from: MasterT on September 26, 2018, 01:32:45 pmHell, no! It was started by you suggesting that nobody but you knowsThe answerto the ultimate question of life, the universe and DSP:Quote from: MasterT on September 21, 2018, 02:51:10 pmQuote from: MasterT on September 21, 2018, 10:35:16 pmQuote from: MasterT on September 21, 2018, 10:35:16 pm

author: radioactive
author_rank: Regular Contributor
timestamp: September 26, 2018, 03:37:52 pm
content: Quote from: MasterT on September 26, 2018, 01:32:45 pmI didn't omit the windowing function, you did.Quote from: MasterT on September 25, 2018, 04:41:54 pmI agree that 3x timing difference is not correct. This was just the timing difference for calling full-sweep with your SNR functions for grt vs fft 1000 times.. The Goertzel function would be thousands of times faster for your original specs: N=2048, single-bin.I think the real point of all this was showing that the FFT, DFT, Goertzel are all going to give you the same results for a single bin. In my opinion, the real take-away should be this:For optimal efficiency (sometimes this doesn't matter),1) use FFT if you need results across the entire channel.2) use a single-bin DFT if you need a single bin with complex input,3) use Goertzel if you need a single bin with real input only.Btw, thank you for the FFT code. It is nice looking code.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 26, 2018, 06:12:20 pm
content: Quote from: radioactive on September 26, 2018, 03:37:52 pmI'm referring to your first post, where you comparing fftw vs goertzel:https://www.eevblog.com/forum/projects/low-frequencies-vector-network-analyzer-arduino-based/msg1844921/#msg1844921Why you didn't apply windowing, as you should? Than, would be a huge difference in the two charts, would not it?And you are ignoring the fact, that Goertzel is meaningless w/o 64-bits architecture.

author: Kleinstein
author_rank: Super Contributor
timestamp: September 26, 2018, 07:16:04 pm
content: If windowing is used, it would not make a big difference, if at all. This is a step on the raw data, essentially before starting with FFT or Görtzel or DFT.I don't think one will need 64 bit math to use the Görtzel algorithm or DFT. 32 Bit math should be plenty for 2048 points, though the FFT might get away with 16 bit math (and may have to use it because of memory limitations).Besides speed the FFT has the disadvantage that it is essentially limited to certain window lengths (usually 1024, 2048, maybe 4096, maybe 768, 1536 in theory), and needs space so have all the data (may need even 2 sets) and the results in memory.Speed wise the critical limit is if real time calculation is possible - that is do the calculation at the speed the data come in. So how fast is the FFT solution ?Even if not optimum speed, the idea of using a µC and little extra HW for a low end slow VNA is nice.

author: ogden
author_rank: Super Contributor
timestamp: September 26, 2018, 07:37:18 pm
content: Quote from: Kleinstein on September 26, 2018, 07:16:04 pmObviously 32bit precision is enough to measure. SNR estimation test wasdistractionBS move anyway. Even OP test shows insignificant difference of magnitude (not SNR) between 32bit (float) precision Görtzel vs FFT: 2620.176270 vs 2620.160156QuoteIn half of that memory I better hold precalculated sine lookup table for DFT

author: radioactive
author_rank: Regular Contributor
timestamp: September 26, 2018, 08:17:35 pm
content: Quote from: MasterT on September 26, 2018, 06:12:20 pmI've re-run my original test (little larger sweep to make it visually symmetrical) with N=2048 and now we are back to using the libfftw library version of fft.compile with gcc goertzel_test.c -o goertzel_test -lm -lc -lfftw3This is also 32-bit floats. I've added a blackman-harris window to compare against the rectangular window (no window). The trade-off for the various windows is usually between finer frequency resolution (rectangular) with less suppression of the side lobes or something like blackman-harris which does a pretty good job of suppressing the side lobes, but gives you less frequency resolution. There is also one called flat-top window that maintains better amplitude accuracy (less scalloping loss). So really depends on what you are measuring.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 27, 2018, 12:54:55 pm
content: Quote from: Kleinstein on September 26, 2018, 07:16:04 pmIt would not, I already tested this, both Goertzel & FFT react in similar manner for introducing windowing. The main question, is do I need a windowing?Thinking about it for awhile, I came to concept of "perspective", a view angle. If I put a phase error, as it is written in the first few lines of the original message, 0.01 degree as a starting point, than all other parameters lined up.1. SNR: 0.01 degree imply -> ~80 dB2. BW: Next, is the bandwidth. Since, this is a "measuring" device I'm trying to build, not a dummy dtmf detector, BW has to be defined differently compare to common definition Peak/ sqrt(2). BW in this perspective is the main peak width At -80 dB.3. And this 80 dB SNR, consequently, says that windowing is a Must, and suppression of the side lobes > 80 .4. "Measuring device" means that it has some dynamic range, so my phase error (0.01) stays below this line even magnitude at the ADC input drops significantly. I do not have PGA at this point, and probably don't want to have, as it would be another "stepped line" cause of errors. So defining dynamic range at least 40 dB, or better 60 , I have 80 + (40-60) = 120 - 140 dB.5. Based on this value, now I'm sure Goertzel is must be 64-bits. In my SNR example, where sng_grt shows 67 dB, plus 40 -test was done at 40 dBc, Goertzel noise floor is 107 dB (if 32-bits math used ) and it's way too low for 120-140.6. I'd test Goertzel-64 on arduino DUE see if it faster than fft-32, could be. Could be I'm underestimating it's performance.

author: ogden
author_rank: Super Contributor
timestamp: September 27, 2018, 01:24:22 pm
content: Quote from: MasterT on September 27, 2018, 12:54:55 pmRight. Let's beat 200k$ worth N5247B which have miserable 0.02 degrees RMS specified.

author: Mechatrommer
author_rank: Super Contributor
timestamp: September 27, 2018, 02:01:27 pm
content: Quote from: MasterT on September 27, 2018, 12:54:55 pmthe purpose of windowing is to reduce leakage in fft result adjacent to/when there is significant frequency component not residing in fft bin. and its a separate (pre) process to dft (fft or goertzel or whatever derivatives) with complexity O(n) and can be easily incorporated real time, once the original data is windowed, its gone, processing/calculation will be made based on the windowed signal. you can get by without windowing if your big mama frequency is residing in one of your fft bin, but if you want to see significant effect of it, try evaluating odd frequency like eg if your bin is ... 244, 488, ... etc, try giving the fft function a pure 366Hz sine signal (in the middle between 2 bins) with 0 or minimal or clean phase noise and look at the fft result, with or without windowing function. but you should know this already i may just rephasing this for anyone who will come across this thread in the future. fwiw...https://www.edn.com/electronics-news/4383713/Windowing-Functions-Improve-FFT-Results-Part-Ihttps://en.wikipedia.org/wiki/Window_functionhttps://community.plm.automation.siemens.com/t5/Testing-Knowledge-Base/Windows-and-Spectral-Leakage/ta-p/432760https://en.wikipedia.org/wiki/Spectral_leakage

author: Bud
author_rank: Super Contributor
timestamp: September 27, 2018, 02:24:58 pm
content: OP no offence but you've been delusional about your device performance. Not sure why you not answering questions about calibration, so i have to assume you do not know what it is. If that is the case you have a lot to learn and a long way to go before this contraption can be called a VNA.

author: Kleinstein
author_rank: Super Contributor
timestamp: September 27, 2018, 03:45:58 pm
content: Much of an VNA is in the software to do the calibration and to compensate for parasitic couplings that ideally should not be there. So this is a really important point. As shown the HW looks more like a limited range, low frequency impedance analyzer. Even there is usually takes corrections / adjustments with something like an open circuit and short.For the SNR / phase noise estimates, it looks like these are at maximum amplitude. However a real signal is rarely at the maximum amplitude and there are other sources of trouble than white ADC noise. One such problem is that the rather slow amplifiers might reach the slew rate / power bandwidth limit. There are also such nasty effects like self heating and temperature dependent phase shifts. The corrections needed also tend to increase the noise by something like a factor of 2 as it involves a 2nd or 3 rd measurement.Comparing to much higher frequency instruments is kind of misleading - they have different problems and a different setup. So in some aspects even a simple low frequency setup can be better than an expensive microwave instrument - these usually don't even offer measurements below a certain limit (e.g. 10 KHz).

author: MasterT
author_rank: Frequent Contributor
timestamp: September 27, 2018, 04:21:58 pm
content: Quote from: Bud on September 27, 2018, 02:24:58 pmI do know about calibration, but really don't care. It's still "work in progress", calibration is only applicable to completed device. Above I set a line at >120 dB, and thinking again I may never get there w/o PGA, as 12-bits adc may not be enough. ADC is only 72 dB and needs about 50 to get a score. Initially I was counting to get 30 via dsp-core (processing gain), and it seems I needs 20 dB more.Quote from: Kleinstein on September 27, 2018, 03:45:58 pmCorrect, I observed that mcp6s91 start to lag at 1 MHZ, even DS says GBW=18 MHz. What is more problematic, that phase offset depends on the magnitude, showing non-linearity, that I can't remedy nether in software not via calibration.

author: Kleinstein
author_rank: Super Contributor
timestamp: September 27, 2018, 08:17:43 pm
content: For the MCP6S91 the power BW is relatively small. At 1 MHz the amplitude limit is at around 1 V_pp at G=1. So this PGA is a rather bad choice if only gain 1 or 2 is used. (see Figure 2-24 in the DS).

author: MasterT
author_rank: Frequent Contributor
timestamp: September 28, 2018, 11:55:30 am
content: Quote from: Mechatrommer on September 27, 2018, 02:01:27 pmNot so easy. If there is only one "mama frequency" - I already done that, run DDS in the multiples of the ADC clock - windowing is not required. The problem is that there could be more than one signal at the input, DDS and interference. I can adjust my ADC clock as well, to suppress lets say 50/60 Hz, same as they do for 18-24 bits SD ADC - using 4.9152 MHz crystals, but it would works for this specific 50/60 Hz frequency. TFT display interference and digital noise from arduino itself very likely can't be rejected simultaneously, it's asking for windowing function. I see, that a lot depends on SNR ratio, DDS / Interference, and dynamic range I want to reach.Quote from: Kleinstein on September 26, 2018, 07:16:04 pmI read a few times, that fft needs to store samples, and goertzel like may work on "the fly". So memory requirements for goertzel may be much smaller.Not is this project. Sampling at 1 MSPS, (and using DMA to get this high sampling rate) is making operation (to store data before processing) not optional.

author: Mechatrommer
author_rank: Super Contributor
timestamp: September 28, 2018, 02:30:38 pm
content: Quote from: MasterT on September 28, 2018, 11:55:30 am"we" (someone else already posted and asked this) are not sure why noises, interferences, dynamic range, SNR are your main concern. when your main interest should be on the fundamental frequency, thats why all posters suggested single-bin application to you. SNR or dynamic range concern should be in spectrum analysis, signal purity/distortion out of a DUT such as signal/function generator design application, which is not what you are doing here (impedance analyzer). further, since you have internal signal generator, you should be able to specify that as calibration data and subtract from your output, ymmv.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 28, 2018, 09:45:21 pm
content: Quote from: Mechatrommer on September 28, 2018, 02:30:38 pmWhat I see, that nobody understand the difference between dumb DTMF detection, and 0.01 degree accuracy phase measurements. When you find out what is it about, than post your comments, please.

author: Kleinstein
author_rank: Super Contributor
timestamp: September 28, 2018, 10:10:11 pm
content: The noise is usually not the main problem, as one can reduce noise by spending a little more time on taking data. Here it helps if the calculations can be done real time, so that little time is lost.The more difficult parts are usually to get parasitic phase shifts and unwanted signal paths small or at least stable enough that they can be corrected. So here this is the amplifiers but also choice of signal paths (e.g. relays). A special problem can be switchable gain, as the dynamic range of the 12 bit ADC is not that large. Nonlinear effects can also cause funny effects at the small scale. Quite often accuracy is not limited by noise, but by other non-ideal effects. So the SNR is not such an important factor - it is more important to the speed of a measurement, not the accuracy.I think many of us understand the DFT quite well: There is no magic gain in SNR from the FFT compared to other DFT methods. It is just a different algorithm to give essentially the same result. Depending on the situation it can be faster or slower - that is the main difference.It is a little unfortunate that the DDS and ADC seem to use independent clocks. This is a possible source of hard to control errors due to variations in initial phase.

author: ogden
author_rank: Super Contributor
timestamp: September 28, 2018, 11:48:51 pm
content: Quote from: Kleinstein on September 28, 2018, 10:10:11 pmLOL. It's least problem of particular circuit.I am puzzled about another question: how this so called VNA can measure any other property (like dissipation) of capacitor besides plain capacitance. Could you please explain this to me?

author: Dave
author_rank: Super Contributor
timestamp: September 29, 2018, 04:20:57 pm
content: Quote from: MasterT on September 28, 2018, 09:45:21 pmWhat I see, is a person that intentionally ignored the evidence that I provided, demonstrating that conventional DFT and FFT produce the exact same results. You ramble that you want evidence and when I put in the time to produce said evidence for you, you blatantly ignore it.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 29, 2018, 07:59:04 pm
content: Quote from: Dave on September 29, 2018, 04:20:57 pmI did replay, have you misread?Quote from: MasterT on September 23, 2018, 10:54:10 pmIt says, I'm proud to be completely illiterate in matlab. No comprendo, sinor.In theory, there is no difference if algorithm is written for "float" "double" or "int64_t". But in practice there is, big pile of shit at the output.

author: Dave
author_rank: Super Contributor
timestamp: September 29, 2018, 09:11:43 pm
content: Knowing any of the programming languages gives you enough background to at least try to understand matlab code. It's merely a manipulation of matrices and to top it all off, I added plenty of comments in there to make things clear.Single-precision floating-point variables are more than good enough to produce accurate results. Heck, you could even do it with int32 variables if you did your homework and kept the variable lengths in check.The claim that plenty of us already voiced still stands: Doing a full FFT for a single bin is a waste of resources and clock cycles.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 29, 2018, 11:36:16 pm
content: Quote from: Dave on September 29, 2018, 09:11:43 pmVery accurate description, "manipulation", unfortunately, matlab does manipulation not only with the matrices.I already verified Goertzel C code on 32-bits math, and it's failed on rounding noise. Anyone could run original software with low frequencies to confirm this.If under "resources" you mean memory, than when DMA involved algorithm is out of business, anyway samples directed to memory.Last, but not least. Clock cycles.I acknowledge, that I misunderstood performance of the single bin (Goertzel) algorithm, provided by "radioactive". My latest test shows that it runs >2 times faster on arduino Due (SAM3X8E) in similar with fft conditions. I spend some time to re-write code into int64_t math, otherwise it would be much slower on uCPU w/o FPU. So, again a lot depends on implementation. It was mot obvious in the beginning that int64 version would be so fast, trickery that compiler does can't be predicted by no-one.

author: Dave
author_rank: Super Contributor
timestamp: September 30, 2018, 01:00:19 am
content: Quote from: MasterT on September 29, 2018, 11:36:16 pmNot quite sure I catch your drift. How is it unfortunate that matlab can do more than calculations on matrices?

author: MasterT
author_rank: Frequent Contributor
timestamp: September 30, 2018, 10:12:23 am
content: Quote from: Dave on September 30, 2018, 01:00:19 amWhat I'm trying to say, matlab is a tool to manipulate the consciousness. It can show any results, that someone want to show.Consequence of the "digital economic". In other words, it last things on a planet that I would trust. I'm better to believe in the "fft magic"Sametime, I do respect the right to "freedom of religion" others.

author: Dave
author_rank: Super Contributor
timestamp: September 30, 2018, 02:33:18 pm
content: Matlab (or Scilab, Octave, R and Python's NumPy) are the de facto tools that engineers and data analysts use for numeric computation. The syntax is similar or the same in all of them - know one and you pretty much know all of them.I posted my script, I'm not hiding anything. Anyone is free to dismantle my code and show me exactly where I'm wrong.The fact that you're ignorant and refuse to adapt to new standards is not an excuse to accuse me of being shifty and presenting data to support a hidden agenda.Congrats, you just earned yourself a spot on the ignore list.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 30, 2018, 02:57:20 pm
content: Quote from: Dave on September 30, 2018, 02:33:18 pmThanks, will do same thing. I'm not gonna to study matlab, ( or cantonese, if someone provided his tests results). Project is in plain C (and arduino) languages, so you are talking on same wave or moving on.

author: Bud
author_rank: Super Contributor
timestamp: October 18, 2018, 11:13:10 pm
content: Quote from: MasterT on September 28, 2018, 09:45:21 pmYes here is my comment. Indications are you are confusing accuracy with resolution. No wonder, since this is a common mistake. Accuracy is a measure of how close the measurement is to the correct value. In absence of calibration you accuracy can be off 2 orders of magnitude, i.e. non-existstant. Beside the phase (you claim 0.01 degree) will be invalid because the device errors not being accounted for, it will depend on the length of the cables connecting the DUT to the device. The claimed 0.01 degree are meaningless. It is just how granular your invalid measurements are going to be. And once you will get to implementing calibration you will find out (if dilligent enough) that achieving just 1/10 of that claim (0.1 degree phase accuracy) is very hard. Let alone no calibration model exists for such device architecture so you will have much fun developing one and proving it is valid. This is why i said you have a long way to go.