monitor a guitar signal strength, then output a DC level?


Closed Thread
Results 1 to 25 of 25
  1. #1
    Join Date
    Mar 2009
    Posts
    653

    Default monitor a guitar signal strength, then output a DC level?

    I'm at an early exploratory stage, where I'm looking for some circuit or other (not sure if it'll be PIC based or not yet!), to do the following....

    Feed a guitar signal as an input to a a PIC input pin.

    Have this incoming signal level monitored...then output a DC level on an output pin that's inversely proportional to the incoming signal. Therefore if the overall incoming signal is too high, drop the DC level on the output pin. If the incoming signal is too low, raise the DC level on the output pin

    This DC level output will be fed to an audio power amp chip that has a DC pin dedicated to volume control.

    So in essence, it's an AGC circuit...but utilising a PIC to do this (yes, I know there are probably specialised ICs that already do this, but I have a unique need & need to control the charactersistic of the circuit)

    Is this do-able?

    If so...a lot of code? (I'm new...having just done a small amount of programming...though I did get my first PIC project working!)

    Anyone got a link to something I could rejig?

    Any comments to get me started most welcome!
    Last edited by HankMcSpank; - 2nd April 2009 at 12:07.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    Hmm, any audio processing of this kind needs logarithmic amplifiers to cover the dynamics.

    You will not have satisfactory results with just the A/D converter of the PIC.

    Have a look at the http://www.picbasic.co.uk/forum/show...?t=2359&page=2 from post 51 and after.

    Also PIC are not very fast for the processing you may need.

    Ioannis

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    I'm not sure if this would help you. I remember a gentleman called Robert A Penfold in the late 80's-early 90's who used to write lots of audio related articles in Practical Electronics Mag or Everyday Electronics Mag. If you can search for his articles, I'm pretty sure, he has covered this too. What you're trying to do is called an envelope grabber, I think.

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    I probably didn't explain myself very well (for the sake of simplicity) - I can see that you've probvably not sussed what I'm trying to achieve!

    So, a little more meat on the bones...

    I'm intending 'tapping' off a guitar signal (six signals actually...one from each string)...I need the 'level of the output of these six strings monitored. I originally implied having the PIC carry out this monitoring on the alternating guitar signal, but it makes more sense to do the following...


    Since these six signals will be buffered (and will likely be amplified a little), I could actually turn them into a DC level with a full wave rectifier & smoothing cap...so I don't need any massive A/D processing...a simple sample of the string's DC level about 5 times per second should suffice.

    I need the PIC here to act as a DC voltage comparator....let's say the rectified/extracted DC level of a particular incoming guitar signal is 2V, but it needs to be 3V...therefore we get the PIC to increase a DC level on an output pin (this feeds a DC 'volume control' pin on a power amp IC, this elevated DC will make the power amp 'drive' a guitar string sustainer coil more, which in turn makes the string vibrate more...the 'increased' guitar output signal is fed back into my circuit.

    Thererefore, what we have is a feedback loop....if the incoming guitar signal is too low, the corresponding guitar string will be 'driven more' until its amplitude is increased & it hit's the target reference voltage.

    I know all of this can be done in analog, but I'd like the circuitboard to go inside the guitar, so small size is paramount & a PIC with say IO 20 pins is an awful lot smaller than the several opamps per sting needed to do this.

    So what I really need is a PIC to monitor 6 x DC levels against a reference voltage & subsequently change a DC output level on six of its output pins to suit. (ie I don't need any fancy logarithmic algorithms, etc)
    Last edited by HankMcSpank; - 2nd April 2009 at 18:24.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    IMHO, every audio needs at least 60-70db dynamic range. With the full wave rectifier I am not sure that you will reach over 25-35db. Your ear, no matter what post processing you are going to do, needs this logarithmic treatment.

    Anyway, about the PIC now, if 5 times/sec is enough for you, then almost any PIC may do the job. What you need at the output is a PWM signal with a low pass filter to get the analog control voltage for the VCA.

    Forum has covered the last many times.

    I really would love to hear some samples of the effect if you make it working.

    Ioannis

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    IMHO, every audio needs at least 60-70db dynamic range. With the full wave rectifier I am not sure that you will reach over 25-35db. Your ear, no matter what post processing you are going to do, needs this logarithmic treatment.

    Anyway, about the PIC now, if 5 times/sec is enough for you, then almost any PIC may do the job. What you need at the output is a PWM signal with a low pass filter to get the analog control voltage for the VCA.

    Forum has covered the last many times.

    I really would love to hear some samples of the effect if you make it working.

    Ioannis

    Many thanks...in the time since posting I've been on intense googling & realised that the PIC doesn't have the opposite of ADCin (which is a shame as DACout would have been fab!).....sussed the PWM approach but hadn't realised about the low pass filter on the PWM output - tks.

    Re the end result itself...I'm not trailblazing....it's been done - I'm just trying to do it with six channels (the commerical units send one 'summed' signal to their driver), as having six channels means more control & cool possibilities, but the component count will be 6 times more, hence trying to condense using a PIC...

    (about 12 seconds in)
    Last edited by HankMcSpank; - 3rd April 2009 at 01:03.

  7. #7
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Hi peeps,

    Since starting this threa, I went away & knocked up a little program to monitor a DC level at a PIC input pin & then output a PWM stream accordingly ...it increases the PWM duty cycle if the incoming DC level is too low & vice versa...it works well.

    But now I'm thinking it would be really cool if I didn't have to rectify the incoming analogue guitar signal first (ie to derive DC level for the PIC input pin)...as this means I could do away with 6 x rectification circuits (& space is tight) ....there must be a slicker way of doing this in software?

    The frequency 'band' of each string is quite small ...therefore what my 'concept is', is to work out the highest frequency per string (I'm monitoring each string individually) & sample the signal level at a fast enough rate to make sure the highest frequency 'peak' is detected.

    A highest fretted top E string is about 1kHhz (give or take!), which means the shortest time between 'peaks' will be 1ms. I guess that I'd need to take a reasonable amount of samples to make sure I catch 'peak' ...I'm thinking 64 samples within that 1ms. (guitar signals aren't exactly sine waves, but they're not square waves either so I'm thinking 64 samples ought to get me very close to 'peak')

    Therefore 1ms divided by 64 samples = 15us between samples.

    Is a PIC up to this level of AtoD rate? (there'd be six different individual strings to sample).

    Now, I'm no programmer & I find myself having to learn this PIC programming melarkey out of need, so at a high concept level, how does this sound...

    Start looping (to be done every 15us for 1ms)
    'sample1' - store result in a Variable1
    'sample2' - compare result to Variable1, if it's less do nothing, if it's more update Variable1
    'sample3 - compare result if less do nothing, if more update Variable1
    & so on...

    after 1ms stop stampling - the data stored in 'Variable1' is the peak.

    Now go and 'act upon' the data.

    Start next loop sampling cycle


    Does this sound about right?

    Have I missed anything?


    Does anyone have a link to some suitable sample code to get me started?

  8. #8
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Most PICs only have ONE ADC which is multiplexed to a whole heap of pins. This means you have to select your Input, perform an ADC operation, select the next input etc etc...

    So, with 6 inputs, your 15uS slot becomes 3uS (15uS/6). With all the other processing, variable comparison, PWM updates etc, it's just not going to happen (at least not with a 12F, 16F or 18F device with PBP - even at 40MHz).

    A splattering of small surface mount Diodes, Capacitors and Resistors suddenly become very attractive.

  9. #9
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Melanie,

    Thank you for such a fast response & enlightening post! (I had no idea that PICS simply multiplexed their one AtoD (I feel cheated ).

    So if summed the six strings & therefore just went with the one 'commonised' string input ...& perhaps trimmed the sample rate down a little (say 32 samples, therefore 1ms/32 = 1 ADC sample every 30us) ......do you think be viable on the 'standard issue' PICKit2 PIC - a 16F690?

    I should have said I don't need this intense sampling to run continuously.... probably every 150ms would suffice (there 32 samples at 30us per sample for 1ms, pause for 149ms & repeat)

    I'm not geared up for SMT & ultimately, this little widget will have to go in a guitar - and space it stight, so the lower the component count the better!

  10. #10
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Don't fall into the trap that a PIC is a panacea for all your problems... half the forum thinks that way and then they discover after a lot of wasted time and effort these little things sometimes need external help to accomplish some tasks - and multi-channel complex signal processing is one of them.

    0603 size Resistors and Diodes are still very much hand solderable with a pair of tweezers and a steady hand. You quickly tack one end with a soldering iron so it anchors, solder the other end properly, then go back and solder the first end properly. If you're building a one-off it won't matter. Trust me, you WILL need to rectify and filter those inputs. You are going to waste a shed-load of time and effort and end up with mediocre results going down the route you plan.

    The final output from the Guitar to the Amp is a sum of the individual strings anyway. You can always build an external 'in-line' box which has the added advantage that it can be fitted to any Guitar without voiding manufacturers warranties etc. If you do it using Thermionic Valves (a single ECC83 or any twin-triode equivallent will make an eminent AGC and pre-amp) you will have a queue of people breaking your door down to get one (since valves and stage gear are very much in vogue).

  11. #11
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    I'm going to give it a go anyway (on one pin - combined strings), so to my questions.....

    Working on the basis that the highest note on a Guitar (fundamental frequency), is about 1.4kHz, Therefore, this highest (guitar string) note 'cycle' will take about 700us to complete

    The lowest note is 82Hz - therefore this lowest (guitar string note) 'cycle' will take 12ms to complete.

    I'll work on 32 'samples periods'for the highest frequency as a starter, so to cater for the highest note, I need to carry out an AtoD command every 21us (700us/32)...& to cater for the lowest note, I must continue doing this for 12ms. (the time it takes for the lowest note to complete one cycle of sound)

    How can I be sure that such fairly rigid sample times are met?

    At a PIC internal clock rate of 4Mhz, would I be right in saying that each clock cycle is 0.25us?

    Therefore I need to carry out AtoD every 84 clock cycles?

    Can someone help out here to get me started ...please?!!!

  12. #12
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    Don't fall into the trap that a PIC is a panacea for all your problems... half the forum thinks that way and then they discover after a lot of wasted time and effort these little things sometimes need external help to accomplish some tasks - and multi-channel complex signal processing is one of them.

    0603 size Resistors and Diodes are still very much hand solderable with a pair of tweezers and a steady hand. You quickly tack one end with a soldering iron so it anchors, solder the other end properly, then go back and solder the first end properly. If you're building a one-off it won't matter. Trust me, you WILL need to rectify and filter those inputs. You are going to waste a shed-load of time and effort and end up with mediocre results going down the route you plan.

    The final output from the Guitar to the Amp is a sum of the individual strings anyway. You can always build an external 'in-line' box which has the added advantage that it can be fitted to any Guitar without voiding manufacturers warranties etc. If you do it using Thermionic Valves (a single ECC83 or any twin-triode equivallent will make an eminent AGC and pre-amp) you will have a queue of people breaking your door down to get one (since valves and stage gear are very much in vogue).
    Just seen your reply (before I made my posting immediately above).

    This PIC circuit is not for a guitar output...but for a guitar sustainer (ie feed the guitar signal back into a circuit which drives a coild to keep the string virating ...there's no combining any output here...the normal (mono) guitar signal still goes to the amp as normal. The only combining would possibly of a hex pickup into my circui to feed a sustainer driver coil.

    The reason I initially want handle 'six' strings, is becuase there are quite a few guitar variants out there that have hex pickups (one pickup per string), but like I say, I can sume these & then treat them as one. The sustainer needs an AGC, a threshold, a limit & an attack/release 'user definable' input parameters...this makes a PIC ideal.

    I don't think a PIC is a panacea...but in this instance it could be very useful - what I don't have any knowledge about - is how hard they can be pushed. For example is carrying out AtoD every 20us for 13ms, then repeating again in 130ms afterwards that onerous for a PIC?

    I'm assuming not, as I'm only talking about 32 samples at 1.4khz for 13ms on one input pin ...then repeating every 130ms (& I can't imagine Microchip would have been able to call its converters 'AtoD converters' if they struggle at this relatively low sample rate & base frequency!)

  13. #13
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Read the DATASHEET for your PIC... especially the ADC section.

    Instruction Cycle is FOsc/4 so a 4MHz chip has 1uS Instruction Cycles.

    It will probably take you 60uS to do ONE ADC (aquisition plus external housekeeping, retrieval, storage etc). Your worst case scenario is 1.4kHz... that means one complete sine-wave in 714uS... you'll be lucky to do six acquisitions per half wave... if you're lucky you'll hit peak, if you're unlucky your best shot will have missed peak by 15 Degrees. So doing my Nostradamus bit and predicting the future, you'll have a resultant randomly waving about like a pr**k in distress by upto 15 degrees of Sinus.

    Oh... and you know you're talking about not having any (or minimal) external components... unless your input has a DC bias (more components needed), half your input will be negative going... so for 357uS out of the 714uS the PIC isn't going to see anything, but worse, it's internal protection circuitry on it's pins may well load and distort your input signal during the negative half-cycle, so unless the signal is buffered (more components), you'll distort the output of your Guitar by the simple act of connecting up.

    But don't let me put a damper on things... it's your life...

  14. #14
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    I'm sure this is best done in discrete analog. Doing what you want with a PIC and the way you want is going to be a tough one. But as Melanie said, you have to make that call.

  15. #15
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson View Post
    I'm sure this is best done in discrete analog. Doing what you want with a PIC and the way you want is going to be a tough one. But as Melanie said, you have to make that call.

    Ok, after sleeping on this...you're right (& there's little point asking for advice, if you're not going to heed it from those that know!).

    Many thanks for taking time to respond.

    rgds,
    Hank.

  16. #16
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    Most PICs only have ONE ADC which is multiplexed to a whole heap of pins. This means you have to select your Input, perform an ADC operation, select the next input etc etc...
    This is an old thread of mine, but I've just revisited it on account I wanted to be sure what I'd asked previously!

    Ok, I have my PIC program successful carrying out AtoD on one incoming (full wave rectified) guitar signal.

    Presently I'm hard coding the 'target DC' level for the PIC AGC circuit to strive for eg (let's say I've set a raw AtoD value of 550 as the optimum incoming DC level ...but the full wave rectified guitar signal is only measuring 400 - then the PIC just sends some pulses to a volume control to increase the signal)

    Now to try & save POTs/switches having to be mounted on the guitar, I'd like to design my own little board with a resident pot on it - I'd like use the DC level from this pot to set the AGC's target incoming DC level for the circuit to strive for - the thing is my PIC 16F690 is already using one channel of AtoD to sample the incoming rectified guitar signal. From Melanies post above it seems that I'll need to switch the AtoD converter to another input pin

    How do I switch the AtoD pin - is that done with the ADCON0 setting? (& presumably I have to switch back & forwards between the two pins involed - each time changing the pin that the AtoD converter is connected to)

    Let's say my guitar signal is AtoD'ed on AN1 ...if I then want to use AN2 in my circuitry, does this mean that everytime I want to establish the DC level on the pot, I need to invoke a ADCON0 command to change the CHS2,CHS1 and CHS0 bits (bits 3,4 & 5 of the ADCON register?) Forgive the naive line of questiong - I'm far away from even being considered an entry level programmer - this stuff doesn't come easy to me!)

    Someone asked a bit further up this thread, to post a demo of the thing I'm pottering on with , well here's a link to a short video I made (albeit this video was when I was using analogue for the AGC aspect - which was not flexible enough in the end, hence returning to the scary world that is digital!)



  17. #17
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Ok - I manged to kludge my way through it & get two AtoD channels working - but man, what a struggle ...you'd think they'd gone purposely out of their way to getting something as simple as AtoD setup (it's akin to having to read the service manual on the hubble space telescope!)

  18. #18
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    Have you considered using the NE/SA 572 chip? I think to propr do such a job with controller you need a fast one like dsPIC or better a DSP processor.

    PIC'c do not have many resources for analog processing.

    Ioannis

  19. #19
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    Have you considered using the NE/SA 572 chip? I think to propr do such a job with controller you need a fast one like dsPIC or better a DSP processor.

    PIC'c do not have many resources for analog processing.

    Ioannis
    That's a nice little chip, but alas the minimum VCC is 6V. (I'm tied to 5V)

    As it goes, in my config, I'm not placing that much in the way of demands on the PIC - it's simply sampling a rectifed/smooth guitar signal to get a handle on the signal strength. The PIC then either pulses up/down a digital pot accordingly - as simple as simple can be.

  20. #20
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    If you use the proposed chip, then why still use 5V as power? Do you have need for a controller?

    Anyway, is it working now or you have other problem with the PIC?

    Ioannis

  21. #21
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    I'm tied to using 5V as I will be placing this board inside a guiutar that already has 5V inside it - I want to tap into that supply for my circuit.

    The circuit itself works, but I need to refine the Automatic Gain Control 'decisions' made by the PIC - & I'm still very much finding my feet wrt PIC Programming!

    For example I need to modify the the code to make a decision something along these lines...

    "If the present incoming AtoD sample if 40% bigger than the last AtoD sample then do nothing - just keep looping until the sample falls in level to equal a user determined level"

    (In the situation above, it means a new note on the guitar has just been plucked - however, at the minute, my circuit's Automatic gain control sees the incoming larger signal of the plucked string & cranks the gain down - but it then struggles to get the gain up in time after the initial high pluck signal strength has dropped out!)
    Last edited by HankMcSpank; - 30th October 2009 at 10:01.

  22. #22
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    How about :

    Code:
    if signal>(0.6*prev_signal) then gosub attenuation
    Ioannis

  23. #23
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    How about :

    Code:
    if signal>(0.6*prev_signal) then gosub attenuation
    Ioannis
    thanks Ioannis

    I'll not get a chance to try that until tomorrow evening now (Saturday evening) - but to my very untrained eye, it looks like that setup is saying ...

    if the present incoming signal (ie sample) is greater than 60% of the previous signal (sample), then blah blah


    ??

    If so, then what I actually need is this type of condition ....

    "if the present signal (ie sample) is 40% greater than the previous signal (sample), then blah blah?


    By the way - what's the best way to do percentages in PICBASIC? (if it helps, I can dispense with the floating point - which I'm presuming the PIC just does away with ...eg 40.4% becomes 40%)

  24. #24
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    PBP does not do floating of course. you have to multiply the variable by 10 or 100 or even 1000 to get the "floating" digits in the integer part of the number.

    Ioannis

  25. #25


    Did you find this post helpful? Yes | No

    Default Frequency to voltage

    I skimmed over this thread... maybe you need a simple frequency to voltage converter... this was used in some of the first guitar synth's... there are discrete as well as monolithic devices (still) available...

    Mike Tripoli

Similar Threads

  1. small dc signal amplifier schematic need
    By phoenix_1 in forum Schematics
    Replies: 9
    Last Post: - 8th May 2009, 03:32
  2. Output current to a DC motor
    By bigbanner in forum General
    Replies: 1
    Last Post: - 6th April 2009, 07:29
  3. Unwanted output signal jitter
    By LinkMTech in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 18th January 2008, 02:31
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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