Undescribed Horrific Abuse, One Victim & Survivor of Many gmkarl at gmail.com
Sun Nov 13 07:05:47 PST 2022

So for trying implementing feedback to find the frequency of a signal
precisely, I could try out using fourier.py . I could even use my
existing test data, but leave it blind.

I'd find the highest paired peaks, and then adjust the frequencies of
interest and find again, until the error in the least squares solution
dropped. Seems like it could be a small loop.

ok, so first i would take an fft of the whole data (assuming I had no
signal guess), and find its peak.
i guess i can start by writing a quick peak-finder

0949 i wrote def peak_pair_idcs which takes the abs, sums adjacent
frequencies, and returns the indices of the max pair using argmax. i
put it in fourier.py

i guess it needs some tweaks: it should ignore DC, for example, and
i'm thinking it should rotate the frequencies in some way. usually it
starts at DC, then goes low frequencies up to the nyquist ... but then
what does it do?

>>> np.fft.fftfreq(6)
array([ 0.        ,  0.16666667,  0.33333333, -0.5       , -0.33333333,

it goes back down to low negative frequencies.

so it does make sense, maybe it's okay.

if DC is high, this likely indicates information near or beyond the
nyquist frequency. maybe i could move DC to the nyquist frequency? or
add it to it?

basically if the frequencies are too high it's not quite working!

I think I'll remove DC. nobody wants to zoom in on noise when they're
trying to think about signals.


Okay, so then say I have a peak in the dft. How do I zoom in on it?

I don't actually need to reconstruct the other data. I'm mostly
interested just in the data at that peak. The current code models the
output as fully describing the input, which leaves that out. We could
stick with it for now, though.

If the data _only_ contains that signal, then it is reconstructible
from a dft tightly surrounding just that peak, and I think the code I
wrote provides for that situation. But it's written in terms of sample
rates, rather than frequencies.

Those sound pretty similar though.

When I have it give a normal dft, I give it the sample frequency and
time sample rates.
If I wanted it to do a dft of half stuff, I would give it twice the
frequency sample rate. 2.0 .
Or, I could halve the time sample rate. 0.5 .
In a DFT, the frequency of something that is half, is specified
related to the sample count, like 1 / N or 2 / N, and then at the
nyquist frequency it's (N/2) / N or 0.5 .

So this 1 / N or 2 / N, is what I would pass as 0.5 or 2 .

The frequency is the ratio advancement per sample. so 1 / N reaches a
full cycle in N samples.
2 / N reaches 2 full cycles in N samples.
To zoom in on 2 / N, the frequency sample rate would be twice the time
sample rate. .. I think.

I'll try assuming that freq * N is what goes for the frequency sample rate.
So you'd pass the lower of the two frequencies, to find the real peak.
And you'd only need the portions of the FT that are up through the
higher of the two frequencies: in fact, limiting how high frequency it
goes is part of how it can get really detailed really fast.

So, the current code goes up to the nyquist frequency. I'd want a
different set of frequencies. A different minimum frequency.

At the moment I'm reusing the output of np.fft.fftfreq() which outputs
DC, then positive frequencies that are increasing fractions, then
negative frequencies that are decreasing fractions (I think), with a
change only in sign around the nyquist frequency.

I'd want instead to not go all the way up to the nyquist frequency,
but go only a little bit.
I guess that could be a linear transform of the frequencies. To change
their min and max.

The current code is stated in terms of sample rates, but it might be
more useful to state things in terms of minimum and maximum

That's a little confusing, changing between sample rates and
frequencies, because I am changing the sample index parameter passed
to the sinusoid, rather than the actual frequency.

But the arithmetic reminds that scaling one of those is equivalent to
scaling the other.


I'm thinking of change create_freq2time and create_time2freq so that
they specify the minimum and maximum frequencies of interest. Not

There's some further confusion around what a frequency is, since the
time and space domains have different sampling rates here.

Maybe a simplifying concept can be that the time domain has a real,
measured sampling rate, whereas the frequency domain is just talking
about frequencies, and has not actually been "sampled".

More information about the cypherpunks mailing list