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

AI Thread Summary
Capturing an amplified electric signal from a heart device to create an ECG diagram can be achieved using a sound card, although it may not be the most optimal solution. Users can connect the output of their custom-built amplifier to the sound card's input jacks. For signal processing, libraries like DirectSound, part of the DirectX package, can be utilized to access raw data from the sound card. This allows for real-time analysis of the signal, including extracting amplitude versus time data and identifying peak points to determine heart pulses. While some multimedia libraries focus on recording and playback, DirectSound offers a more direct interface for signal analysis. Users are encouraged to explore documentation on DirectSound for detailed implementation guidance.
da_coolest
Messages
15
Reaction score
0
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!
 
Technology news on Phys.org
da_coolest said:
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!

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.
 
chiro said:
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.

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.
 
da_coolest said:
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.

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:
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.
 
chiro said:
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:
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.

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.
 
da_coolest said:
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.

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
 
chiro said:
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

Thanks a lot for all the information you have provided. I will start reading about directsound. thanks again.
 
Back
Top