Shop OBEX P1 Docs P2 Docs Learn Events
Audio Spectrum Analyzer. — Parallax Forums

Audio Spectrum Analyzer.

lyassalyassa Posts: 52
edited 2012-06-27 10:06 in Propeller 1
I want to build an audio spectrum analyzer. I couldn't find a FFT object in OBEX, and it doesn't seem easy to roll my own. Any advice how to go about building a simple spectrum analyzer using the Propeller?
Thanks.

Comments

  • lyassalyassa Posts: 52
    edited 2012-06-06 14:01
    Oh ... the links in the "Similar Posts" section took me to this thread http://forums.parallax.com/showthread.php?96099-Propeller-Application-DEMO-Spectrum-Analyzer-(for-Audio). Will give it a try.
  • Heater.Heater. Posts: 21,230
    edited 2012-06-06 14:32
    I cant get the link to the project in that thread to work. Has it moved?
    In the mean time have a search for heater_fft in this forum.
  • hover1hover1 Posts: 1,929
    edited 2012-06-06 14:46
    Which link Heater?


    Google search on "fft heater www.parallax.com"

    produces some results

    Jim
  • Cluso99Cluso99 Posts: 18,069
    edited 2012-06-06 18:20
    There has already been some amazing work done in fft and decoding radio signals so I am sure once you get going there will be some excellent help and enthusiasm provided by others. Phil seems to be a specialist in this arena so expect him to chime in as you get this project underway.
  • lyassalyassa Posts: 52
    edited 2012-06-25 23:48
    I tried the program posted by Beau Schwabe in the following thread
    http://forums.parallax.com/showthread.php?96099-Propeller-Application-DEMO-Spectrum-Analyzer-%28for-Audio%29

    ... and it works really well when I feed it a sine or square wave from a signal generator. However, it doesn't work well when I feed it signal from a guitar, for example. Does anyone know if the routine works only with "pure" fixed frequency signal or should it work also with "mixed" signal like guitar signal?
  • Mark_TMark_T Posts: 1,981
    edited 2012-06-26 02:53
    How many spectral bands do you want to analyze into? The FFT isn't the only way to run a spectrum analyzer, you can also run a set of resonators (complex or cosine) in parallel from the signal and chart their amplitudes. This is more easily parallizable to multiple cogs than an FFT.

    With lots of spectral bands the FFT is going to win easily on performance though.
  • Heater.Heater. Posts: 21,230
    edited 2012-06-26 03:52
    I can't get the link in the first post of Beau's Spectrum analyser thread to work.

    Thread: http:// http://forums.parallax.com/showthread.php?96099-Propeller-Application-DEMO-Spectrum-Analyzer-%28for-Audio%29

    Leads to dead end: http://members.cox.net/brookhaven-north/Parallax/PropellerSpectrumAnalyzerforAudio.html

    Best way to google search the forums is:

    site:forums.parallax.com heater_fft
  • Mark_TMark_T Posts: 1,981
    edited 2012-06-26 05:00
    Early paper on cosine and complex resonators for spectral filtering:
    http://www.alcatel-lucent.com/bstj/vol48-1969/articles/bstj48-3-501.pdf
  • RS_JimRS_Jim Posts: 1,768
    edited 2012-06-26 05:41
    Try this link
    ForumGeneral ForumsPropeller Chip Heater's Fast Fourier Transform.
    Jim
  • lyassalyassa Posts: 52
    edited 2012-06-26 06:42
    Heater. wrote: »
    I can't get the link in the first post of Beau's Spectrum analyser thread to work.

    Thread: http:// http://forums.parallax.com/showthread.php?96099-Propeller-Application-DEMO-Spectrum-Analyzer-(for-Audio)

    Leads to dead end: http://members.cox.net/brookhaven-north/Parallax/PropellerSpectrumAnalyzerforAudio.html

    Best way to google search the forums is:

    site:forums.parallax.com heater_fft

    Yes, the link in the post is not functional, but the attachments in that same post works. I downloaded "TV - Audio Spectrum Analyzer.zip", modified it a little bit to detect certain frequencies, e.g. 1khz, 2khz from the signal generator (this part works well). Then tried to detect the musical notes frequencies, and this is the part that is not working.
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2012-06-26 08:37
    re: I feed it a sine or square wave from a signal generator. However, it doesn't work well when I feed it signal from a guitar,

    Did you put the output of the guitar through a preamp first?
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2012-06-26 08:55
    Yes, the link is dead... my service provider decided to shut down web-hosting ... not happy about that, as they gave me virtually no warning.

    I need to use the "Wayback" machine to retrieve some of the things I was hosting.

    The word document is essentially what was being hosted on the page...
    http://forums.parallax.com/attachment.php?attachmentid=48409&d=1185537374


    Aside from that, the Audio Spectrum Analyzer should work better after amplification, but consider that for every frequency present in the signal you will have a distribution loss to contend with. i.e. a single frequency present will provide the best 100% signal detection ... two frequencies 50% ... three 33.3% ... four 25% ... etc... 20%, 17%, 14% ....
  • lyassalyassa Posts: 52
    edited 2012-06-26 09:16
    re: I feed it a sine or square wave from a signal generator. However, it doesn't work well when I feed it signal from a guitar,

    Did you put the output of the guitar through a preamp first?

    Yes I do. I am using LM324, powering it from the 3.3V and getting output ranging from 0 to 2v. I was hoping to get output of 0V to 3.3V since LM324 is rail to rail. The signal gets distorted wen I increase the gain. I still need to spend some time on the amp circuit.
  • lyassalyassa Posts: 52
    edited 2012-06-26 09:21
    Yes, the link is dead... my service provider decided to shut down web-hosting ... not happy about that, as they gave me virtually no warning.

    I need to use the "Wayback" machine to retrieve some of the things I was hosting.

    The word document is essentially what was being hosted on the page...
    http://forums.parallax.com/attachment.php?attachmentid=48409&d=1185537374


    Aside from that, the Audio Spectrum Analyzer should work better after amplification, but consider that for every frequency present in the signal you will have a distribution loss to contend with. i.e. a single frequency present will provide the best 100% signal detection ... two frequencies 50% ... three 33.3% ... four 25% ... etc... 20%, 17%, 14% ....

    So may be I do not have adequate amplification (output is 0V to 2V). Thanks a lot for the tip " two frequencies 50% ... three 33.3% ...", I didn't know that. I was looking for values > 50% regardless how many notes are played at once. Will take this info in consideration now.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-06-26 09:37
    lyassa,

    The LM324 is not a rail-to-rail amplifier. The input and output common-mode ranges run from 0 to Vdd - 1.5V. You have to be careful not to amplify your signal too much, else you'll get peak clipping, leading to spurious harmonics in your spectral analysis.

    -Phil
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-06-26 17:18
    Good point PhiPi. Running a LM324 from a 5V supply with a virtual earth of 2.5V, like you say you cannot go within 1.5V of either rail. So that is 1.5V to 3.5V.

    But running from 3.3V with a virtual earth of 1.65V I think you will only be able to get a signal from 1.5V to 1.8V.

    A CA3140 can go rail to rail, but I think min supply voltage is 4V. So you could run it from 5V and create a virtual earth of 1.65V. If all of that is a bit confusing maybe post a schematic because there are many ways of creating distorted waveforms if op amps are not used correctly :)
  • lyassalyassa Posts: 52
    edited 2012-06-26 23:36
    Dr_Acula wrote: »
    Good point PhiPi. Running a LM324 from a 5V supply with a virtual earth of 2.5V, like you say you cannot go within 1.5V of either rail. So that is 1.5V to 3.5V.

    But running from 3.3V with a virtual earth of 1.65V I think you will only be able to get a signal from 1.5V to 1.8V.

    A CA3140 can go rail to rail, but I think min supply voltage is 4V. So you could run it from 5V and create a virtual earth of 1.65V. If all of that is a bit confusing maybe post a schematic because there are many ways of creating distorted waveforms if op amps are not used correctly :)

    I am using the circuit below. I replaced R3 and R4 by a potentiometer, that allows me to shift the output so that I do not have a dc component on the output. I also removed C2 and R1 and replaced the mic by the signal generator. I am connecting the output directly to the Propeller. I will try it with 5V supply and will post the result.

    simple-mic-pre-amp-based-LM358.jpg
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-06-27 00:14
    It should be possible to get something working. What is the amplitude of the input signal (?1V P to P, or is it a microphone or something else?). What values of R2 and R5 are you using? Also what values of R3 and R4?

    One concept very useful with op amps and a single rail supply is a 'virtual earth'. For the propeller 1.65V would be the right voltage. So whatever input you have needs to be biased to 1.65V. It might be already if whatever made the signal was supplied by 3.3V (eg another propeller). Actually you might not even need an amplifier if the signal was, say, 1V peak to peak. Just change the bias so it sits in the middle of the propeller range. A 1uF and a couple of 10k resistors could do that. And you might need to attenuate rather than amplify the signal - if so, we can do that with resistors rather than with an op amp.

    I'm hoping with enough information we won't need a CRO. I got away with building audio circuits for 20 years without a CRO and it can be possible - just need to think about what the voltages are and whether you are introducing distortion by amplifying things too much.
  • lyassalyassa Posts: 52
    edited 2012-06-27 07:08
    Dr_Acula wrote: »
    It should be possible to get something working. What is the amplitude of the input signal (?1V P to P, or is it a microphone or something else?). What values of R2 and R5 are you using? Also what values of R3 and R4?

    One concept very useful with op amps and a single rail supply is a 'virtual earth'. For the propeller 1.65V would be the right voltage. So whatever input you have needs to be biased to 1.65V. It might be already if whatever made the signal was supplied by 3.3V (eg another propeller). Actually you might not even need an amplifier if the signal was, say, 1V peak to peak. Just change the bias so it sits in the middle of the propeller range. A 1uF and a couple of 10k resistors could do that. And you might need to attenuate rather than amplify the signal - if so, we can do that with resistors rather than with an op amp.

    I'm hoping with enough information we won't need a CRO. I got away with building audio circuits for 20 years without a CRO and it can be possible - just need to think about what the voltages are and whether you are introducing distortion by amplifying things too much.

    The signal is 50mv peak to peak. Fortunately I have a signal generator and an oscilloscope so I can see if a distortion is introduced. I adjust the variable resistors to stay away from any distortion and to make the output vary between 0V and 2V (2V for now, will be 3.5V when I supply the op amp with 5V). After things looks good with the signal generator, then I use a guitar as an audio signal source of mixed frequencies (about 50mv peak to peak). So in brief, I am mapping (-25mV to +25mV) into (0V to 3.5V). That is a gain of 70.
  • Mark_TMark_T Posts: 1,981
    edited 2012-06-27 10:06
    lyassa wrote: »
    Yes I do. I am using LM324, powering it from the 3.3V and getting output ranging from 0 to 2v. I was hoping to get output of 0V to 3.3V since LM324 is rail to rail. The signal gets distorted wen I increase the gain. I still need to spend some time on the amp circuit.

    The LM324 is not rail-to-rail - the inputs and outputs go to Vcc-1.5 or so only. Power it from 5V and it should deal with inputs from 0 to 3.3V happily though.

    Also most opamp's perform poorly near the limits of voltage (gain reduces, bandwidth reduces, output current drive drops by orders of magnitude - all rail-to-rail opamps are a compromise alas, but Analog Devices seem to make a good range to choose from - I'd always choose 5V over 3V3 for an opamp supply if I could, a lot more choice of devices.
Sign In or Register to comment.