Shop OBEX P1 Docs P2 Docs Learn Events
Silence is golden — Parallax Forums

Silence is golden

jhoyozajhoyoza Posts: 72
edited 2007-02-12 01:43 in BASIC Stamp
Hello,

Every time I start to think I’m getting smarter, “Whamo,” hit right off the forehead with another dose of reality!

I’m trying to create frequency sequences that allow me to extend the time of a specified frequency beyond the command’s limit of 65535 (about a minute). There is no real problem in doing that simply by repeating the command, and I don’t even mind if there is a silent gap between reinitializing the command. However, instead of a brief moment of silence I get a rather loud popping noise. Brief but annoying especially at higher volumes and frequencies. I tried to EQ it out, with minimal success, as it appears to be more bass orientated.

Is there something I can do to the code or is it more of an analog component issue? I’m using the line-input on my computer’s soundcard as an amplifier with a home-made cable salvaged from a broken set of headphone wires. Below, I attached the two circuits diagrams that I’ve tried. The one with the 10K resistor appears to be the quieter of the two. However, I would very much like to be able to not have any “popping” sound at all if possible? Any suggestions?

Thanks!

-J

' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse]I/O Definition ]
Speaker PIN 9
'
[noparse][[/noparse] Constants ]
Amount CON 100
Time CON 65535
'
[noparse][[/noparse] Variables ]
frequency VAR Word
repeat VAR Byte
'
[noparse][[/noparse] Program Code]
frequency = 2000
DO
ON repeat GOSUB Increase_Freq
repeat = repeat + 1 // 3
IF (frequency > 3000) THEN END
DEBUG "tone sending ",DEC frequency, CR
FREQOUT Speaker ,Time, frequency
LOOP
'
[noparse][[/noparse] Subroutines]
Increase_Freq:
frequency = frequency + Amount
RETURN

Comments

  • steve_bsteve_b Posts: 1,563
    edited 2007-02-10 12:44
    I can't remember which state the pins end up in...but it sounds like you might be getting a high level on your output pin in.
    I think ifyou look in to the OUTPUT commands, you might find out how to designate the pin as an output.
    Also, you might want to make the state of your pin low before you go in to the rest of the program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • jhoyozajhoyoza Posts: 72
    edited 2007-02-10 23:37
    Thanks Steve,

    Unfortunately, I tried your suggestion, and that didn’t seem to help.

    The manual talks about the fact that if the, “10K was tied to +5V then it would put a high (1) on the pin and the output command can override this state by writing a low (0) to bit 9 of outs and changing the pin to an output.”

    Anyway, I fooled around with it and didn’t have any success. Out of curiosity, I did hook it directly to an 8 ohm speaker without and amplifier and the “pop” is still there? So I think I can rule out the soundcard as being the culprit. I wonder if I can lower the amplitude a millisecond or two right before changing the frequency?

    I would bet a cookie that the noise may be able to be filtered out by the correct placement of a filter capacitor of the proper value. However, It is beyond my knowledge and perhaps someone out there may know more about it.

    Do you want Chocolate-Chip or Sugar?

    P.S. I did figure out how to sustain a frequency indefinitely using a BS2, thus eliminating the "popping" noise while sustaining a single frequency, however I can’t quite figure out how to break out of it to change the frequency? Perhaps a programming guru might be able to advice me there?

    Thanks!

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    [noparse][[/noparse] I/O Definitions ]
    Speaker CON 0
    '
    [noparse][[/noparse] Constants ]
    Modulus CON $100
    NoteTime CON 3
    '
    [noparse][[/noparse] Variables ]
    tone VAR Word
    '
    [noparse][[/noparse] Program Code ]
    tone = 2000
    Main:
    DO
    FREQOUT Speaker, NoteTime */ Modulus, tone 'frequency plays indefinitely
    LOOP
    .
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-02-11 00:40
    No chance you can try a low-pass filter?· Yes, it's a spike/pulse that we're talking about, a·short-duration event, and therefore a high-frequency "component" which could be shunted to ground through a·capacitor with negligible, if any, attenuation of the FREQOUT signal.· Try changing values for the 0.01uF (in re. your two ckts.) --·"Experiment for value."
  • Desy2820Desy2820 Posts: 138
    edited 2007-02-11 01:55
    Not an expert, but could this be some kind of DC offset or DC shift?· Try changing the order of the components.· I can't do any cool art, but stamp output--->resistor--->cap to ground--->resistor---> cap inline with output.· The capacitor inline should block any DC level from getting thru to the amp.·

    Hope this helped!

    ·
  • jhoyozajhoyoza Posts: 72
    edited 2007-02-11 03:26
    By George I think you’ve done it!

    It worked! I should have known that DC will not pass through a capacitor…..I believe it is on page 2 of electronics 101.….duh. And as far as not recognizing it as such, well the proof is in the pudding as far as my experience goes…

    Desy you deserve a whole box of cookies and P.J. it looks like cigars for you!

    Thanks to people like yourselves, Steve and countless others in this forum it truly makes this a most enjoyable learning experience for me.

    Thanks to all!

    Plus, I look smart to my friends. (Drawing another bull’s eye on forehead.)
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2007-02-11 06:44
    If a program varies the duration of a constant frequency sound, you will hear the clicks become louder and softer depending on the duration. That happens because the sound ends at a different phases of the waveform and the click seems lowest when the sound ends at a low point of its waveform, which matches the low level that follows the FREQOUT. This is not an easy effect to use in practice, and it is more pronounced for some frequencies than others. But it is an interesting effect:
    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    dur VAR WORD
    frq VAR WORD
    frq = 2007
    FOR dur=90 TO 1099
    FREQOUT 4,dur,frq
    NEXT
    



    The coupling capacitor worked?! The sound is created using PWM at a relatively high frequency. The coupling capacitor acts as a high pass filter that allows the PWM frequencies through but not the very low frequency DC (vout=0) that is present between each FREQOUT. Ideally you would have a highpass filter in order to center the waveform, and then a lowpass filter to turn the PWM into a nice sine waves with limited bandwidth. Your sound card probably acts as a lowpass filter, although if it does not have antialiasing filters at its inputs, you might hear some funny squeeks and howls if the high frequency PWM mixes with the sampling frequency of the sound card.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2007-02-11 08:10
    Tracy,

    What you describe is correct, and the effect can even be more emphasized if you have two frequencies that create a beat frequency to one another.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • jhoyozajhoyoza Posts: 72
    edited 2007-02-11 11:01
    Thank you Dr. Allen,

    Ok, admittedly improved would have been a better term than worked. There is certainly a noticeable difference and is relatively acceptable for my purposes. Obviously your capable of understanding what it sounded like without it. Now to totally get rid of it, that would be wonderful.

    Your demonstration code and explanation is outstanding. However, I thought I would respond ASAP to let you know it is going to take me a little bit of time to think this one out. No doubt, the click is more pronounced when the frequency is cut off at higher amplitudes. Notice I used the term “click” not “pop” and I’m still giving out those cookies.

    Now lets see who gets the box of chocolates!

    My first thought is how can I adjust the timing to land perfectly with the end of the sign wave. There should be no audible difference as it should be something less than one cycle. That is if my thinking is in line with what your describing. Actually doing it is another story.

    Second, as I mentioned earlier, I may be able to fade out the amplitude just before changing frequencies or repeating the command, thus creating a situation where there is nothing to hear momentarily. I did mention I can live with a bit of silence.

    Third is building a low-band pass filter as you suggested. I do have a few examples that use a 741 op-amp however I have a feeling that digital processing may be a different animal all together. It is obvious I have minimal knowledge of either and perhaps I may want to darken up the bulls-eye, on my forehead, a bit before I say anymore.

    When researching the term anti-aliasing I find the math involved is certainly going to require cleaning out a few of the old spider-webs and most likely beyond my capabilities. I do find it ironic that distortion, if properly applied, actually adds clarity. I’m intrigued at the prospect of reading more about it and how it may be apply to digital signal processing. Who knows maybe I will get lucky?

    Like I said, I have a lot to think about and do not know if any of it is even possible taking into consideration my limited knowledge. In the mean time, I’m going to go find a permanent marker and I welcome input from anyone and everyone in regards to this discussion!

    If nothing else, I certainly enjoy learning more about all of these things. turn.gif

    Respectfully yours,

    -J
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2007-02-12 01:43
    We had a similar situation where a researcher needed click-free sounds for a project in animal behavior. We were able to implement that on an SX chip where we had more control over the envelope, to start and finish each pulse with a gradual buildup and tail for each pulse

    You know you can get some quite nice "bell" sounds from the Stamp FREQOUT command, by using two frequncies and a time interval that brackets even multiples of 1/2 cycle of the beat note frequency that Beau mentioned.

    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    dur VAR WORD
    frq VAR WORD
    
    DO
    FOR dur=200 TO 1200 STEP 10
    FREQOUT 4,dur,2000,2001  ' 1 hz difference, 500ms 1/2 cycle
    DEBUG ?dur
    PAUSE 100
    NEXT
    LOOP
    



    In old phonographs or amateur radio we used to use a "pop filter" or "blanking filter". This would detect a pulse above threshold at an early stage in the amplifier chain, and for the duration of that pop in effect turn off the amplifier or hold the output at a pre-pop level. That sort of filtering is easy to accomplish with a digital filter, but more difficult with analog, because of the predictiveness of knowing when the pop has already occured, and then going back in time to filter it out. Time delays, digital or analog. I'm not sure exactly how to go about it with the PWM signal.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.