wow & flutter spectrum analysis

What you think causes the massive ripple seen in the spectra ? Seems to be more of an artefact ?
Strange thing too, that the level of FM modulation does not seem to vary significantly

did an analysis with the nice sortware tool wfgui friends came across in the meantime, and this one outputs this spectra that seems pretty reasonable to me
(so we do have some reference now at least):
wfgui_FM_spectra.png

Below the file output of this wfgui tool in the time domain. Pretty much what I was after, as it seems :
The sampling rate is double the carrier - here its 6300Hz - as expected (twice 3150Hz).
Could you help in creating a code for something similar ?
wfgui_time_domain.png

I can’t really comment on this or your later questions as I have no idea what the audio is that you are analyzing.

Sorry Steve, my bad
I try to upload a 10sec sample of a deck I recorded.
This is the sample the above analysis is performed with cut down from 30 sec to 10sec to hopefully get it uploaded

The first thing that I notice is that the frequency is not 3000 Hz, more like 3180 Hz, so if that is a 3 kHz test tone then your turntable is running a bit fast.

I don’t know what the wiggle is in your final waveform. Was that produced with Robert’s code?

There are two standard test tones, the older is 3000 Hz and the newer one, 3150 Hz.
I don’t think that my code is suited for the demodulation, only for the carrier tracking because the integration time is probably too long.
I think the polar discriminator code is more appropriate.
However, I don’t know what should be done with the demodulated signal (ranging from 0 to 200 Hz). W&F meters seem to have some peak weighting applied before returning the two percentages below and above 4 Hz. It might be enough to just look up the peaks in the plot spectrum if you don’t want to follow the ANSI or DIN specifications (which I don’t have).

The file I uploaded was form a cassette deck where a 3150Hz Tone was recorded.

My general aim is not[/] to mimic any wow and flutter measurement standards (there are quite a lot of them, depending on country and the philosophy those guys there were following) but to have a analysis method at hand that allows for deep spectral insight at first hand.
Might be, it will be of some interest to mimic different W&F test setups later on, but frankly thats not high on my list right now.

So, the FM decoded signal shown above was from a software tool that - I guess - works like I would like to “translate” zero crossings into amplitude values.

Two steps would be needed for this
1.) calculate the difference of any zero-zero time with respect to a given carrier (say 3000 / 3150 Hz)
2) assign this differnce as an amplitude value in the output file

If there is a deviation in speed this would / should show up as a DC part in the output file and is actually welcome, as it allows to go down in spectral analysis very very low.

These are my test results.
The first value will be a bit off because it starts with a partial cycle.
Testing know frequency signals at around 3129 Hz I’m getting results that are within +/- 0.15 Hz average over periods of around 0.24 seconds (750 cycles).

The results can be imported into Audacity as a label track. (File > Import > Labels)
The range of values is between 3128.25 and 3130.62 Hz but mostly between 3128.84 to 3130.32 Hz.

If you want to use the figures directly, the first column is start times, the 2nd column is end times and the third column is the calculated frequency.

Interpreting the results will be fun.

The code that I used is basically the same as the “zero crossing counter” that I posted previously.
LabelTrack.txt (1.02 KB)

Well I see what you mean
:open_mouth:

from the code snipplet provided, I get an output like this in debug mode:

#<Sound: #32d0aa0>: srate 20, t0 0, extent 3, dur 3, 60 samples: #(440 440.5 441.5 442.5 444.5 447 450 453.5 458 462.5 467.5 473.5 480 486.5 494 502 510.5 519.5 529.5 539.5 550 561 572 583 594 605 616 627 638 649 660 671 682 693 704 715 726 737 747.5 759 770 736.5 702.5 668.5 633.5 598 562 525.5 488 450.5 412.5 373.5 334 294.5 254 213 171.5 129.5 87 43.5

What actually do that values represent ?
And what part of the code snipplet actually does calculate those values ?

Could you please elaborate about t in some detail, I just didn’t get it ?

This code snipplet was basically yours, Robert ?
May I ask you to explain it ?

Sure, I can explain the code.
As it is, the code uses only a test sound, namely a frequency sweep from 440 to 880 Hz.
(the code was:)

;; Zero crossing rate
;; Size = amount of samples that are averaged
;; hop = samples to advance,
;; determines the sample rate of the result
;; amp is used to disable the averaging 
(defun zcr (snd size hop amp)
  (let* ((zero (snd-from-array 0 (snd-srate snd) (vector amp))))
         (snd-avg (s-max 
            (trigger (mult -1 snd) zero) 
            (trigger snd zero)) size hop op-average)))
;; Modulated signal (sweep)
(setf mod-signal (abs-env (hzosc (pwl 0 440 1 440 3 880 3) )))
;; Output to debug screen
;; We gather all 44100 samples at a sample rate of 20 Hertz
(snd-display (zcr mod-signal 44100 2205 22050))

The main function in use is “trigger”.
It takes a modulated signal and creates a new signal by placing the value of “amp” on each transition from minus to plus. In order to have also the crossings in the other direction, we turn the sound upside down (multiply by -1) and take the maximum.
If the input sound would be

0 0.7 1 0.7 0 -0.7 -1 -0.7

the trigger functions would return

1 0 0 0 1 0 0 0

when “amp” is 1.
Those half-cycles are averaged over “size” samples and we do then advance by “hop” samples.
If the parameters are wisely chosen, the instant frequency will be returned.
Since we need a big amount of samples to average the frequency, the precision won’t be very high. Furthermore, this gives only the deviations from the carrier frequency, but we actually search for the highest wow or flutter peak (0 to 200 Hz).
I have to try myself, what settings are best suited. “Trigger” allows also to return the exact time of the zero crossing, that’s what you’re searched for above.

First the disclaimer. My code was intended only for proof of concept. It extremely inefficient, but it is simple and it does seem to be pretty accurate. If the proof of concept works then it should be developed in a more efficient way. If the concept falls down then we don’t need to spend time developing efficient code.

Those numbers should be the frequencies for each successive 400 cycle period. (were you analyzing the default “Chirp” effect?)
However, your debug output does not match what I get:

481.533
505.357
528.112
549.91
570.892
591.093
610.655
629.618
648.005
665.887

This is the code that I posted:

(defun count-samples (sig crossings)
  (do* ((count 0)    ; number of samples between crossing points     
        (total 0)    ; total counter
        ; get the next sample value
        (val (snd-fetch sig) (snd-fetch sig))
        (zcount 0)   ; zero crossing counter
        (flag val))    ; sign of last value.
       ; stop when crossed zero twice and return 'count'
       ((> zcount crossings) total)
    (when (< (* val flag) 0)  ; crossed zero
      (setq zcount (1+ zcount))
      (setq total (+ total count))
      (setq count 0))
    (setq flag val)
    (if (> zcount 0) (setq count (1+ count)))))

(setq cycles 400) ; about 1 second for a 400 Hz signal

; High pass and extract.
(setf s (extract-abs 1 11 (highpass2 s 20)))

(dotimes (i 10)
  (setq sample-count (count-samples s (* 2 cycles)))
  (print (/ (* cycles *sound-srate*) sample-count)))

Each line that starts with a semi-colon “;” is a comment. Comments are ignored by Nyquist. They are there for the benefit of human readers.

This is a function that counts the number of samples for 400 waveform cycles (the waveform crosses zero 2 x 400 = 800 times):

(defun count-samples (sig crossings)
  (do* ((count 0)    ; number of samples between crossing points     
        (total 0)    ; total counter
        ; get the next sample value
        (val (snd-fetch sig) (snd-fetch sig))
        (zcount 0)   ; zero crossing counter
        (flag val))    ; sign of last value.
       ; stop when crossed zero twice and return 'count'
       ((> zcount crossings) total)
    (when (< (* val flag) 0)  ; crossed zero
      (setq zcount (1+ zcount))
      (setq total (+ total count))
      (setq count 0))
    (setq flag val)
    (if (> zcount 0) (setq count (1+ count)))))

The function is called by the command:

(count-samples s (* 2 cycles)

where:
COUNT-SAMPLES is the function name.
S is the (mono) sound.
(* 2 CYCLES) is the number of zero crossings to count.


The average frequency of those 400 samples can then be calculated:
= /

We know that the number of cycles is “CYCLES” [ = 400 in this example].
We know the number of samples for 400 cycles is “SAMPLE-COUNT”.

To convert from samples to time in seconds:
/

So:
= / ( / )
which we can rearrange as:
= ( x ) /
which is written in the code as:

(/ (* cycles *sound-srate*) sample-count)

A major problem with achieving accuracy is that the results are badly affected by noise. This is why it is necessary to take an average over a lot of cycles.
The results can be improved significantly by pre-filtering the signal to isolate the sine tone as much as possible. For example:

;; Pre-filte the signal
(setf s
  (mult 4     ; make up filter losses
    (highpass8
    (highpass8
    (lowpass8
    (lowpass8 s 3000)
    3000)
    3000)
    3000)))

but note that with such a severe filter, the first part of the signal will be garbage so must be deleted or otherwise ignored.

You are going to need some test signals to get an idea of the accuracy of your analysis.
Here’s a bit of code for generating noisy sine waves at a specified frequency:

;;; Generate test tone:

(setq freq 440)             ; average frequency
(setq max-offset 20.0)      ; Low frequency bias
(setq gain-variation 10.0)  ; Variation in amplitude
(setq noise 0.2)            ; added noise

(let ((gv gain-variation))
  (sum (mult noise (noise))
    (mult
      (sum (hzosc freq)
        (mult max-offset (lowpass4 (noise) 0.5)))
      (sum (/ (- 100 (+ 1.0 gv)) 200.0)
           (mult gv (lowpass4 (noise) 1))))))

This gives pretty good accuracy even with noisy sine waves, though it is still very inefficient and slow.
For a pure sine tone it gives a pretty good result (without the pre-filtering) with just a single cycle.

Disclaimer: This was written quite quickly - there may be errors. In particular I’m not sure that the “fractional part” is being handled correctly for multiple cycles.

;; Find average frequency of N cycles:
(setq cycles 400)  ; frequency is averaged over this many cycles

;; Pre-filte the signal
(setq freq 3000) ; filter frequency
(setf s
  (mult 4       ; make up filter losses
    (highpass8
    (highpass8
    (lowpass8
    (lowpass8 s freq)
    freq)
    freq)
    freq)))

(dotimes (i 44100)(snd-fetch s)) ; ignore first 1 second

(defun get-results ()
  (do ((val (snd-fetch s)(snd-fetch s))
       (index 0 (1+ index))
       (flag 0)
       (zcount 0))
      ((or (>= zcount (1+ (* 2 cycles)))(not val)))
    (if (not (boundp 'oldval))
        (setq oldval val)
        (progn
          (when (< (* val oldval) 0) ; crossed zero
            (setq fractional (/ (- oldval)(- val oldval)))
            (push (+ index fractional) results)
            (setq zcount (1+ zcount)))
          (setq oldval val)))))

(dotimes (i 10)
  (setf results ())
  (get-results)
  (setq freq (/ (* cycles *sound-srate*)
               (- (first results)
                  (nth (* 2 cycles) results))))
  (print freq))

Thanks for takiing your time, Robert

Oh no, actually to calculate a W&F number is not in my interest.
I am soley interested in getting spectral analysis of W&F done.


Ok.
I guess I now have understood what you are doing with “trigger” (though not really understood how and not really understood the “hop” thing, yet - but anyway)


Ok.
So how could this be modified to :

  1. return exact time of the zero crossing of my recorded file above, not the frequency sweep you used (the code seems to be highly nested so its very hard for me to break it up into its functional parts, sorry)
  2. calculate the time difference with respect to the carrier of 3150hz
  3. give back sound file with the calculated results at a sample rate of 6300hz (twice the carrier)

No need for any “disclaimer”, Seve
I’m more than happy that you find interest in the problem I raised.

Strange.
No, I did not use the “Chirp” effect. I soley did analyte the recorded track - at least I thought so.


Ok,
I did understand that you are after the frequency and therefor did a lot of averiging ?
To calculate the “mean” frequency of the recorded file tells us the speed deviation of the recording with respect to the recorded carrier - so far so good to know.

This is more or less that part of the code you already provided in the other thread to find the current carrier frequency in the recorded file for perfect AM demodulation, I guess ?

Thanks.
good to have such a possibility, especially for calibrating values as soon as we get fair spectral results - but for now it seems to be sufficient to test the results against the stored output file of the wfgui software tool which seems to do a good job in FM demodulation.

Here is its output of the recorded file

Ok.
Signal preparation seems to be a good idea.
The bandwidth untouched - for spectral analysis - should be at least 2kHz thus hopefully allowing to get fairly accurate values from roughly 0hz to 1kHz after FM demodulation

Thus - for the carrier in the range of 3kHz - bandwidth may possibly best be limited to 1kHz to 5kHz