Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to read an electric signal through sound card? (C++)

  1. Feb 1, 2012 #1
    How to read a signal through the sound card? I want to capture an amplified electric signal that emerge in the heart, and then to draw the ECG diagram.

    Can I use the soundcard's jacks for this purpose? if then, what is the best method to use to capture these signals using C++ on windows?

    if using the sound card is not the best solution, what would you suggest?

    Thanks in advance!
     
  2. jcsd
  3. Feb 1, 2012 #2

    chiro

    User Avatar
    Science Advisor

    Hey da_coolest and welcome to the forums.

    For your second question, you may have a few options but if you can still a peripheral card that allows to stream the data straight from your medical device to the computer, then that will be a viable option.

    Using the above device will depend on the nature of the device and who made it. For example you might get a device that comes with a complete software package and device driver that allows you to do everything you want without having to even program the computer. However you might get the hardware with a device driver and some guidelines on how to communicate with it, but you end up having to do most of the programming yourself.

    I don't know anything about the nature of such devices so giving any more advice would be speculative.

    As for the first question, I think windows has a library for this kind of thing. Have you looked at DirectSound? Its part of the DirectX package and is windows specific. Also hardware vendors have to supply their own interface in their device driver so any platform issues outside of windows should be ok.
     
  4. Feb 1, 2012 #3
    Thanks for the reply. The device that I have is a very simple one made by myself. Its picking up electric signals through electrodes and amplifying using an opamp. I thought of using the soundcard's inputs to connect the output of the amp to the pc.

    I found several multimedia libraries that allows to record input signals from the sound card (SFML). But I want to achieve is to extract data enough to draw the ECG diagram (amplitude versus time) . And then to recognize peak points of the input signal to determine heart pulses.
     
  5. Feb 1, 2012 #4

    chiro

    User Avatar
    Science Advisor

    I'm guessing you are getting a PCM form of the data. Is this true?

    If this is the case, you should be able to just to find global and local maximums by just doing a loop through your data and just storing data when you find a local maximum (has been continually increasing until certain point).

    So you would something like:

    Code (Text):

    int lastsample = sample[0];
    for (int i = 1; i < numSamples; i++)
    {
       // Assume that each sample is a signed integer that has the required resolution
       if (sample[numSamples] < lastSample)
      {
           // You have a local peak so do stuff here
      }
      lastSample = sample[numSamples];
    }
     
    Of course this is very simple, but if you just want to find local peaks, then if it is in amplitude form it should do the trick.
     
  6. Feb 1, 2012 #5
    Thanks. But can you suggest a good method to capture signal through the sound card inputs that would allow me to analyze captured signal?

    I have read about some multimedia libraries available for C++, but most are seems to be just allowing to record data and save them to a file, or to play back etc.
     
  7. Feb 1, 2012 #6

    chiro

    User Avatar
    Science Advisor

    DirectSound would be your best bet.

    The DirectX library allows you to interface directly with hardware at the lowest possible level permitted by the OS (unless you have some kind of custom driver or something like that).

    This includes among other things, getting the exact keyboard and mouse states that are not filtered out by windows events as well getting screen buffer information from the graphics card.

    It does the same sort of thing for the soundcard: You should be able to get the raw data directly from your soundcard in an appropriate format.

    You should take a look at this if you haven't already:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ee416968(v=vs.85).aspx
     
  8. Feb 1, 2012 #7
    Thanks a lot for all the information you have provided. I will start reading about directsound. thanks again.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: How to read an electric signal through sound card? (C++)
Loading...