1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Has anyone here ever made a frequency detector?

Discussion in 'REAKTOR' started by Michael O'Hagan, Feb 13, 2018.

  1. Michael O'Hagan

    Michael O'Hagan NI Product Owner

    Messages:
    1,163
    I am now working on a frequency detector with phase recognition to create a vinyl timecode system for a reaktor ensemble, I've never made a frequency detector before and I'm kinda lost at where to start.

    do you just build a peak detector and a counter of some sort?
     
    • Like Like x 1
  2. Jonathan Tremblay

    Jonathan Tremblay NI Product Owner

    Messages:
    402
    maybe some sort of cycle counter, based on zero-crossings.

    I've tried to modify the Scope block's zero crosser to trigger a counter until it crosses zero again, then multiplying the number by two since you captured half a cycle, as that will equal samples, then doing the samples to frequency conversion.

    However, I failed..haha
     
    Last edited: Feb 13, 2018
  3. Jonathan Tremblay

    Jonathan Tremblay NI Product Owner

    Messages:
    402
    Actually makes me want to re-attempt that..
     
  4. mosaic_

    mosaic_ Guest

    What's the purpose of this frequency tracker? What kind of input will it accept? Is it realtime or offline processing?
     
  5. Jonathan Tremblay

    Jonathan Tremblay NI Product Owner

    Messages:
    402
    Working on a version atm, almost done, just implementing the reset button.
     
    • Funny Funny x 1
  6. Jonathan Tremblay

    Jonathan Tremblay NI Product Owner

    Messages:
    402
    Definitely has some issues with higher frequencies, but I think it's a neat starting point. I did exactly what I described above funny enough..haha
     

    Attached Files:

  7. colB

    colB NI Product Owner

    Messages:
    3,969
    Just in case you didn't already, it's important to introduce some hysteresis to avoid false positives on noisy signals. Also probably useful to filter the result in some way... maybe a peak detector. I guess this would add latency to the tracking, but improve accuracy...
     
    • Informative Informative x 1
  8. ANDREW221231

    ANDREW221231 NI Product Owner

    Messages:
    875
    here are many options to frequency detect, but if phase is a requirement you're gonna want a phase locked loop.

    they way they work is super interesting, you have a free running pulse oscillator and your input which is ran through a flip flop or basically a square wave, and the frequency is controlled by comparing the input with its own output

    this one posted to the UL will get you where you need to go, i learned about about them just from messing with it
    https://www.native-instruments.com/en/reaktor-community/reaktor-user-library/entry/show/4845/

    there's a lot that can be improved with this, it actually doesn't function great. i think there should be step filters after the merge on the flip flops, and about a million other possible things to improve. As colB mentioned hysteresis and a better filter will go a long way towards that.

    i've had it just about as stable as you could ever hope tracking the melody of a commercially mixed song with drums and all. i'd post one, but that they always end up condemned structures from over tinkering

    actually what probably worked the best was taking advantage of the detector output being an event signal before you filter it, use the separator to limit the range. a bit more like lying by omission, so that you don't need to be as pushy afterward with the filter

    after that, if you still have to go further, you gotta make the costas loop which is two loops in quadrature, or basically a phase locked loop as a complex signal, but if you get to that point you might start wondering if you're developing a bit of a problem ---->:eek::oops::confused:
     
    • Like Like x 2
    • Informative Informative x 1
  9. Michael O'Hagan

    Michael O'Hagan NI Product Owner

    Messages:
    1,163
    This works OK as a starting point, but it does not update as the frequency changes.

    I'll study this technique and see what I can come up with, thank you.
     
  10. Michael O'Hagan

    Michael O'Hagan NI Product Owner

    Messages:
    1,163
    I'm going to have to google search and learn what some of these things are.
     
  11. ANDREW221231

    ANDREW221231 NI Product Owner

    Messages:
    875
    what do you need it for? frequency detection is a sort of specialty. i once tried to help a french girl on here looking for a simple frequency tracker by hooking her up with something so overpowered that it wouldn't even work for the single sine wave solution she needed it for

    does it just need to work better? i have that, it just needs cleaned up and made serviceable first
     
  12. Michael O'Hagan

    Michael O'Hagan NI Product Owner

    Messages:
    1,163
    I got approved for the NI SDK for the reaktor player release system and I'm working on a sampler that allows for scratching vie complex envelope generators and midi DJ Controller platters, its essentially a DJ scratch sampler, right now it does everything I want it to do except for vinyl timecode control, which is what I'm tackling now.
     
    • Like Like x 1
  13. Michael O'Hagan

    Michael O'Hagan NI Product Owner

    Messages:
    1,163
    right now frequency to pitch control is working pretty well, but creating a phase detection and comparison for L vs R to determine forward Vs backwards in being a bit of a challenge.
     
  14. Michael O'Hagan

    Michael O'Hagan NI Product Owner

    Messages:
    1,163
    I can't figure out how to do a time based comparison, I need like a compare = type module but for linear time comparison, left gets a 1, then right gets a 1, we're moving forward, right gets a 1 first and left gets a 1 second and were moving backwards.

    I think I'm just over complicating this but I can't come up with a solution right now.

    are there any primary or core modules that do this sort of time relative comparison?
     
  15. ANDREW221231

    ANDREW221231 NI Product Owner

    Messages:
    875
    oh ok i see. i had no idea about time code and figured from the name it was something lame. actually it is interesting, but i know almost nothing about it. i think i'm getting the picture.

    how sharply it tracks any changes has a lot to do with the filter, but it also will depend on the phase detection method. there's two main types, and they both behave differently. i believe for what you are doing you would want the second one.

    if you google phase locked loop the first pdf that shows up explains the difference prettty well. if i remember right, no 1 wants to shoot up to nyquist if you leave it alone for one second, number two wants to find an equilibrium at any frequency and chill there till you make it move
     
  16. Michael O'Hagan

    Michael O'Hagan NI Product Owner

    Messages:
    1,163
    looked that up, we'll now see if I can understand it:cool:, thank you.
     
    • Like Like x 1
  17. ANDREW221231

    ANDREW221231 NI Product Owner

    Messages:
    875
    ;i am reading all about this right now. i misunderstood the context in which meant phase shift. try plugging the stereo signal into the x and y of a scope. you should able to see their position in phase as a circle on the graph
     
  18. Michael O'Hagan

    Michael O'Hagan NI Product Owner

    Messages:
    1,163
    I can plot their phase difference on a pair of oscilloscopes, no problem, but I'm trying to build something in core where the left phase rising first is considered +1 for forward, so that if the record starts to play backwards, scratching, then it will invert to right peak first and become a -1 for reverse.

    record pitch to sample pitch is already working, it's just directional control is becoming tricky.
     
  19. ANDREW221231

    ANDREW221231 NI Product Owner

    Messages:
    875
    oh, ok now i see the rub. that is a subtle thing.

    i often have to build these thing to visualize them properly, but it seems if you delayed one channel by 90 and they were flipped one way, they'd be in phase, and if they were backwards and you delayed that same channel; they'd be 180 degrees out of phase?
     
  20. salamanderanagram

    salamanderanagram NI Product Owner

    Messages:
    3,454
    if you know the phase difference between two sine waves, you should know the expected difference between them at a certain point in time. for example, if L should be greater than R when a zero crossing from negative to positive occurs, but instead it's less than R, you know that the signal is moving backwards.
     
    • Like Like x 1