Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: Audio lib ..Oscillator object can it be run above 22k ?

  1. #1
    Member
    Join Date
    Apr 2020
    Location
    Guelph Ontario Canada
    Posts
    66

    Audio lib ..Oscillator object can it be run above 22k ?

    can the oscillator object in the audio lib run past 22 kHz ..?? Or be pushed beyond 22 kHz?

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    390
    That would be meaningless at 44100 sample rate as +23kHz = -21.4kHz, and unless you are handling complex (ie quadrature) signals
    negative and positive frequencies are indistinguishable. So going over 22.05kHz means going below 22.05kHz - above 22.05k is aliased
    to below 22.05k

    If you change the sampling rate of the library that's another matter, but not every I/O option can handle this readily.

    If you look at the code you'll probably find the frequency is constrained to a suitable range for most of the synthesis
    classes.

  3. #3
    Member
    Join Date
    Apr 2020
    Location
    Guelph Ontario Canada
    Posts
    66
    Well ..no.. it's not neaningless as I'm sampling at 192k right now... What I'm doing is creating an SDR receiver..The higher sampling frequency gives me a larger spread bandwidth wise to view on the FFT display ....but I wanted to digitally mix the oscillator with the incoming signal to digitally mix it down to a lower intermediate frequency ..

  4. #4
    Member
    Join Date
    Apr 2020
    Location
    Guelph Ontario Canada
    Posts
    66
    Most sdr receivers are running 6k to 11k for their intermediate frequency ...I'd like to run it higher ..around 20k

  5. #5
    Senior Member
    Join Date
    Jul 2020
    Posts
    390
    The AudioSynthWaveform class limits frequency to Nyquist, so if the audio sample rate is set higher it will allow higher frequencies,
    just checked the code:

    Code:
    	void frequency(float freq) {
    		if (freq < 0.0) {
    			freq = 0.0;
    		} else if (freq > AUDIO_SAMPLE_RATE_EXACT / 2) {
    			freq = AUDIO_SAMPLE_RATE_EXACT / 2;
    		}

  6. #6
    Member
    Join Date
    Apr 2020
    Location
    Guelph Ontario Canada
    Posts
    66
    Thankyou very much for sleuthing that out ..greatly appreciated ..!!!

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,671
    Indeed it should work up to half the sample rate. But the audio library gets relatively little testing at other sample rates. If you do find any bugs where it does something wrong, please mention them here.

  8. #8
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    337
    Hi,

    In the batdetector project ( https://forum.pjrc.com/threads/38988-Bat-detector ) we use the oscillator function at very high samplerates (up to 352k) without any problems. In the heterodyne mode we mix this oscillator with incoming sound to detune. I have had no issues at all with this.

    regards
    Cor

  9. #9
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    676
    In the context of Software Defined Radio dealing with analytical (complex) signals, builders often use an IF at exactly samplerate-divided-by-4, ie. in your case 192ksps / 4 = 48kHz

    Then you are able to use a frequency translation method with nearly zero processor load:

    https://www.embedded.com/digital-sig...ultiplication/

    This is very easy to implement and works nicely (an example code):
    Code:
          // this is for +Fs/4 [moves receive frequency to the left in the spectrum display]
          for (unsigned i = 0; i < BUFFER_SIZE * N_BLOCKS; i += 4)
          { // float_buffer_L contains I = real values
            // float_buffer_R contains Q = imaginary values
            // xnew(0) =  xreal(0) + jximag(0)
            // leave as it is!
            // xnew(1) =  - ximag(1) + jxreal(1)
            hh1 = - float_buffer_R[i + 1];
            hh2 =   float_buffer_L[i + 1];
            float_buffer_L[i + 1] = hh1;
            float_buffer_R[i + 1] = hh2;
            // xnew(2) = -xreal(2) - jximag(2)
            hh1 = - float_buffer_L[i + 2];
            hh2 = - float_buffer_R[i + 2];
            float_buffer_L[i + 2] = hh1;
            float_buffer_R[i + 2] = hh2;
            // xnew(3) = + ximag(3) - jxreal(3)
            hh1 =   float_buffer_R[i + 3];
            hh2 = - float_buffer_L[i + 3];
            float_buffer_L[i + 3] = hh1;
            float_buffer_R[i + 3] = hh2;
          }
    Last edited by DD4WH; 09-19-2020 at 12:12 PM.

  10. #10
    Member
    Join Date
    Apr 2020
    Location
    Guelph Ontario Canada
    Posts
    66
    No problem Paul ..if I notice anything I'll post up ..Corbet, thanks for the info I want to heteodyne down as well ..cheers

  11. #11
    Member
    Join Date
    Apr 2020
    Location
    Guelph Ontario Canada
    Posts
    66
    Yes the goal is fs/4 ..thanks for the code snippit

  12. #12
    Member
    Join Date
    Apr 2020
    Location
    Guelph Ontario Canada
    Posts
    66
    Wow .. nice ..I was going to run at fs/4 ..this will help alot ..thank You very much !

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •