Shop OBEX P1 Docs P2 Docs Learn Events
Sampling rate of BS2P — Parallax Forums

Sampling rate of BS2P

allan_melvinallan_melvin Posts: 16
edited 2009-07-15 14:25 in BASIC Stamp
Hi,

How to determine the sampling rate of BS2P?

Comments

  • Mike2545Mike2545 Posts: 433
    edited 2009-07-13 01:53
    Sampling rate?Huh__by_Emotikonz.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike2545

    This message sent to you on 100% recycled electrons.
  • allan_melvinallan_melvin Posts: 16
    edited 2009-07-13 02:58
    Yup..I wish to use an ADC to BS2P to process voice signal for my project..how much will be the sampling rate to convert the analog to digital signal?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-13 03:34
    The sampling rate depends more on the ADC than the Stamp although the communication speed (usually SHIFTOUT statements - 42KBaud) will also limit the sample rate. A BS2p is probably not fast enough to do any realistic voice sampling and all of the Stamps have limited memory for processing. The BS2p does have the scratchpad ram which could hold about 120 samples

    Post Edited (Mike Green) : 7/13/2009 3:39:42 AM GMT
  • allan_melvinallan_melvin Posts: 16
    edited 2009-07-13 03:43
    Hi..thank you for your reply..if i wish to include a datalogger to add the memory, is it possible? I might need to process more samples for my project
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-13 04:12
    The datalogger is relatively slow.

    What kind of sample rate do you want? How long a sample do you need to record?

    I suspect you will need something like the Propeller. The Propeller Demo Board already comes with a microphone (and can do its own ADC) and a headphone jack (and can do its own DAC). There already exists sample code for digitizing audio and you can probably fit 16K or more samples in memory. It's easy to add additional memory for data. You could log the data to an SD card if you want and that can be read on a PC for analysis. The main problem is that SD cards are unpredictably slow at times. You can speed up things by preallocating the files. The large buffers can help a great deal.
  • allan_melvinallan_melvin Posts: 16
    edited 2009-07-13 06:46
    Hi Mr. Mike,

    Thank you for your comments. I will seriously consider it. My project is actually to analyze vibration and noise inputs from accelerometer and microphone respectively using microcontroller. I wish to use BS2P but if follow your comments, it might be not suitable. You have any other idea on the project?

    Thank you
  • dev/nulldev/null Posts: 381
    edited 2009-07-13 09:52
    According to the Nyquist theorem you need a sampling frequency of at least 2X the incoming analog signal.
    For audible sound, which peeks at about 22KHz, this will mean you need a sample rate of 44KHz to get a decent recording.
    Sound sampled at 22KHz is still audible, but contains lots of static.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-13 12:52
    You still haven't mentioned important things like frequency range or sample rate needed and sample duration or number of samples. We're really just guessing until you provide that sort of information.

    As I mentioned, the Propeller is perfectly capable of digitizing audio with a 44KHz sample rate with one processor while doing other things with the other 7 processors. The main issue is where to put the data and, for that, you'll need to estimate how much data you'll need to keep. You should be able to record your raw data (if that's what you want) on an SD card by using large buffers to smooth out the variations in writing speed of the SD card (and preallocating file space).
  • allan_melvinallan_melvin Posts: 16
    edited 2009-07-14 02:43
    Hi,

    For your information, I am using 3 accelerometers connected at different area to detect vibration and having a microphone to detect the noise level. The signals supposed to be analyzed using MatLAB's neural network one by one. Each sample is taken for around 5 seconds and analyzed. Once the four signals have been analyzed, the numeric value of the analyzed signals will be compared to the trained value in the Basic Stamp microcontroller. The microcontroller will send signal to the LCD to display the Comfort Level Index (CLI). The process will be continuous, so that the LCD will display the CLI of current state. This is basically what my project all about. The problem now is that I am not sure how big will be trained values database. I need to think about the storage of the actual data also once it is analyzed. Do you have any idea on how the storage problem can be solved? I am think also an option of doing all the processing in the laptop and send the final CLI value to the microcontroller to be displayed. But I am not sure how much will be the success rate. Please advice.

    P/S: I am using Parallax's 3 axis accelerometer with the sample duration of 5 seconds each. Once sample from 1st accelerometer is analyzed, the next sample will be taken from the next accelerometer. So, the sampling rate should be faster

    -Allan-
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-14 03:27
    You still have to quantify the number of samples and the sample rate. It's fine to talk about a sample duration of 5 seconds per axis, but how many samples do you need during that interval? For the microphone, how many samples are you talking about and over what period of time?
  • allan_melvinallan_melvin Posts: 16
    edited 2009-07-14 04:01
    Hi,

    For the accelerometer, i might need 10-20 samples for every 5 seconds and 10-20 samples for every 10 seconds for the microphone.

    -Allan-
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-14 04:13
    So that's 4 samples from the accelerometer and 2 samples from the microphone every second. Assuming they're 8 bit samples, that's 6 bytes per second. A BS2pe has 16K of EEPROM for data only and 16K of EEPROM for either program or data. That would store over 5000 seconds of samples, well over an hour. You weren't clear whether the accelerometer samples were per axis or total. Even if you had to get 14 samples total per second, you'd still be able to store over 40 minutes' worth. A 4 channel ADC like the ADC0834 could sample that quickly.

    The EEPROM can only write 1 byte at a time and takes 5-10ms to do so. There's still plenty of time at 14 samples per second.
  • allan_melvinallan_melvin Posts: 16
    edited 2009-07-14 04:51
    Hi,

    What is your comment about BS2P? Is it suitable for my project?

    -Allan-
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-14 05:09
    Is it suitable for your project? Maybe. If I understand what you've said and you need no more than 16 bytes of information per second, then a BS2p has enough memory (14K) for roughly 20 minutes of samples. If you use a BS2pe instead, you'd have enough memory for roughly 40 minutes of samples. Either a BS2p or a BS2pe could get those samples from a multichannel ADC like the ADC0834 and have time to write them to EEPROM.

    You haven't talked much about the Stamp to PC interface. Remember that any transmission time for the data to a PC will take away from the time available for reading the ADC and writing to EEPROM. You need to be pretty exact about the number of samples per second and the number of bits per sample and the number of bytes needed to transmit to a PC, etc. Do you plan to accumulate the samples for an extended period, the send them all to a PC for analysis or do you need to send them as they're received?

    The better and more complete your information is, the better an answer I can give you
  • allan_melvinallan_melvin Posts: 16
    edited 2009-07-14 07:00
    Hi,

    Ok. I will go for BS2pe instead of BS2p since it may need more time to process the data with the additional of stamp to PC interface.

    I plan to accumulate the data from all sensors for an extended period and send them to the PC for analysis. The Parallax 3 axis accelerometer has build-in ADC. I believe I can save some time in converting the vibration signal. I am just concern about the microphone signal since it requires external ADC.
  • dev/nulldev/null Posts: 381
    edited 2009-07-14 09:55
    You could also consider the Javelin, which has a built-in ADC with 8-bit resolution. It has a fixed sample rate of 476Hz, which is one sample each 2.1 ms, well within your requirements. You don't have to sample at that rate, but thats the sampling rate the ADC will do in the background. The ADC on the Javelin is extremely easy to use. It requires two pins. You have to keep the incoming analog signal between 0 and 5 V.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • allan_melvinallan_melvin Posts: 16
    edited 2009-07-14 09:59
    Hi,

    Thank you for the information. I will check the specification

    -Allan-
  • dev/nulldev/null Posts: 381
    edited 2009-07-14 10:20
    Just to add: Both H48C and the Memsic accelerators from Parallax are easy to use with Javelin as well. The classes for them are allready there.
    Just to give you an example:
    import stamp.peripheral.sensor.accelerometer.*;
    import stamp.core.*;
    
    public class H48C_test2 {
    
      static final int dioPin = CPU.pin6;
      static final int clkPin = CPU.pin5;
      static final int csPin = CPU.pin10;
    
      static H48C myH48C = new H48C(dioPin,clkPin,csPin);
    
      static void main() {
        int axis,gforce;
        System.out.println("H48C test");
        while (true) {
          gforce = myH48C.gForce(myH48C.xAxis);
          System.out.print(" x = ");
          System.out.print(gforce);
          gforce = myH48C.gForce(myH48C.yAxis);
          System.out.print(" y = ");
          System.out.print(gforce);
          gforce = myH48C.gForce(myH48C.zAxis);
          System.out.print(" z = ");
          System.out.print(gforce);
          System.out.print("\n");
          CPU.delay(10500); //wait 1 sec
        }
      }
    
    }
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • allan_melvinallan_melvin Posts: 16
    edited 2009-07-15 04:01
    Hi,

    Thank you for the coding. Is Javelin having any software to analyze the signal from the accelerator?

    -Allan-
  • dev/nulldev/null Posts: 381
    edited 2009-07-15 10:50
    Yes you can analyze the signal from the accelerator by writing Java code.
    It's fairly easy, depending on your programming skills.
    The code in the previous post wil output the X,Y, and Z values or a tri-axis accelerometer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • allan_melvinallan_melvin Posts: 16
    edited 2009-07-15 14:25
    Hi,

    Ok. It is quite suitable for my application then. I think I am having new problem in choosing my microcontroller. Haha. Thank you anyway

    -Allan-
Sign In or Register to comment.