I'm planning on doing a small project involving ECG signals. I am currently getting ECG signals via a COM port and recording these in a txt file using C programming.
My next step is to be able to plot all those data points in real-time. Can this be done using C programming? If not, I do not mind collecting a sample that is 2 minutes long and then plotting those data points.
After that, I want to be able to take the FFT of the time-domain data and be able to plot the frequency plot.
My end goal is to design a GUI using C, that shows a person the real-time EEG waveform as well as the frequency plot.
I did make another post and was advised to try:
RRDTool (http://oss.oetiker.ch/rrdtool/) : However, this doesn't seem to be a straightforward implementation for C.
OpenGL Utility Toolkit (http://www.opengl.org/resources/libraries/glut/) : This seems to be really powerful for generating 3D plots. However, I couldn't find helpful guides simplifying 2D plot implementations
KST : http://kst-plot.kde.org/ , This was the most interesting software. I've played around with it a bit and like it's simplicity. It also allows me to get FFT data. However, I'm not sure how to connect it with my end goal of having the GUI since it is a seperate program.
If someone could recommend C based implementation and some tutorials/sample code to go along with it that would be great. Additionally, advice on other alternatives to reach my end-goal would also be much appreciated !
I can suggest using SDL. It's more 2d based and easier to learn than OpenGL, written in C and quite powerful.
If you want you can first try out SDL in Python using pygame.
Qt http://qt.nokia.com/products/ has a plot widget that you could use ... and has language bindings for many languages
You might want to look at PLplot. Works with many languages, including C, on all the common desktop operating systems (Mac, Windows, Linux, Unix). There are quite a few examples, and most (if not all) examples are available in a number of different languages.
Related
I want to ask if it is even possible to create a software that produces a wave form from using CORDIC Algorithm to make a Direct Digital Synthesizer?
Also, since I'm new, I'm using C since that's what our professor wants us to use, and also, do you guys have any code on a very simple GUIs without any function, only just the window, file, edit, help taskbars?
I am testing some convolution algorithms i found in some sites but none of them apply the matrix filters as it should.
I am writing a very simple 24 bits bmp library on my own, but now i need a little help with the convolution, i don't need FFT or complex algorithm, running time is not important at this time.
The last code i was testing was this: http://lodev.org/cgtutor/filtering.html But i didn't work fine.
Could some one indicate me a code or algorithm in C?.
Thank you very much.
You can have a look at this algorithm - this is the closest which i can find:
Convolution to blur the image
Know that the basic convolution algorithm is more or less the same, the affect changes only by the kernel values.
There is an open source C# library which provides methods to perform image convolution of simple filters. It would be an easy port to C.
The actual methods to perform convolution can be found here. The BitmapContext class is used to just wrap a pointer to bitmap. I believe in C# this is treated as int*, so this code is operating on 4 bytes at a time.
I created Image Convolution library for simple cases - https://github.com/RoyiAvital/Projects/tree/master/ImageConvolution.
It is pretty fast (OpenMP + SIMD).
Though I'm not an advanced programmer of something, just tried doing it to do first steps in utilizing SIMD.
Still, from what can be seen in VS 2015, the CPU utilization is pretty good.
If you have ideas to make it even faster, I will be happy.
Feel free to use it in any manner you'd like.
I use matlab to write a program with many iterations. It cannot be vectorized since the data processing in each iteration is related to that in the previous iteration.
Then I transform the matlab code to mex using the build-in MATLAB coder and the resulting speed is even lower. I don't know whether I need to write the mex code by myself since it seems the mex code doesn't help.
I'd suggest that if you can, you get in touch with MathWorks to ask them for some advice. If you're not able to do that, then I would suggest really reading through the documentation and trying everything you find before giving up.
I've found that a few small changes to the way one implements the MATLAB code, and a few small changes to the project settings (such as disabling responsiveness to Ctrl-C, extrinsic calls back to MATLAB) can make give a speed difference of an order of magnitude or more in the generated code. There are not many people outside MathWorks who would be able to give good advice on exactly what changes might be worthwhile/sensible for you.
I should say that I've only used MATLAB Coder on one project, and I'm not at all an expert (actually not even a competent) C programmer. Nevertheless I've managed to produce C code that was about 10-15 times as fast as the original MATLAB code when mexed. I achieved that by a) just fiddling with all the different settings to see what happened and b) methodically going through the documentation, and seeing if there were places in my MATLAB code where I could apply any of the constructs I came across (such as coder.nullcopy, coder.unroll etc). Of course, your code may differ substantially.
I have a very nice & tricky question for you.
I need to align two meshes using a very fast algorithm. Given mesh1 and mesh2 I want to find how I need to traslate and rotate mesh1 to be in the same position of mesh2.
Firstly I did this using inertia moments of the two meshes, but the algorithm does not work if the second mesh is similar to the first one but with some missing parts. In other words, take two identical meshes and from one of them cut same parts off.
I'd like to write the code in C because I need to perform that on multiplatform machines (linux/win) and do that in a very fast way: it has to be put into a GA algorithm.
The two meshes are in STL (stereolitography) format (binary or ascii) but maybe can be useful using another kind of file format.
Do you have any idea how to perform this stuff?
question update:
first of all I want to thank you guys very much for all your suggestions. I've downloaded an install PCL on my machine and compiled the ICP (tutorial) algorithm successfully, taken from PCL web site.
But now I have some questions about that, maybe because for me is a brand new thing. what is the meaning of the 4x4 matrix output for the fitness? I should expect a rotational matrix and a traslational vector..
I hope some of you can help me.
If you need any other info please ask.
Point Cloud Library has several resources that you may find useful. As #Throwback1986 says, ICP is one excellent algorithm for aligning geometry. Pcl also features other, often faster alignment algorithms, based on identifying and matching features of interest in two pieces of geometry. The library finds a lot of use in the robotics communities, who, like you, are very performance conscious.
Pcl is written in c++. While not as portable as straight C, They offer installation instructions for windows, a few *nix flavors, and mac os. I've seen it running on ios and android as well. Check out the tutorials.
Iterative Closest Point (ICP) is one way of registering (aligning) 3D point clouds with rigid transformations. (It can also apply to meshes.)
Here is a good introduction: http://www.cs.duke.edu/courses/spring07/cps296.2/scribe_notes/lecture24.pdf
Here is a reasonable summary:
students.asl.ethz.ch/upl_pdf/314-report.pdf
Here is a matlab implementation:
http://www.mathworks.com/matlabcentral/fileexchange/12627-iterative-closest-point-method
Here are some potential optimizations:
http://www.cs.princeton.edu/~smr/papers/fasticp/
Just wondering if it's possible to go through a flac, mp3, wav, etc file and edit portions, or the entire file by removing sections based on a specific frequency range?
So for example, I have a recording of a friend reciting a poem with a few percussion instruments in the background. Could I write a C program that goes through the entire file and cuts out everything except the vocals (human voice frequency ranges from 85-255 Hz, from what I've been reading)?
Thanks in advance for any ideas!
To address the OP's specific example: I think your understanding of human voice frequency is wrong. Perhaps the fundamental frequency of male spoken voice stays in that range (for tenor singing, or female speech or singing, or shouting, even the fundamental will go much higher, maybe 500-1000 Hz). But that doesn't even matter, because even if the fundamental is low, the overtones which create the different vowel sounds will go up to 2000-4000 Hz or higher. And the frequencies which define "noise" consonants like "t" and "s" go all the way to the top of the audio range, say 5000-10000 Hz. Percussion fills this same audio range, so I doubt that you can separate voice and percussion by filtering certain frequencies in or out.
It is certainly possible, otherwise digital studio mixing software wouldn't exist.
What your'e effectively asking for is to attenuate frequency ranges across an entire file. In analog land, you would apply a low-pass and a high-pass filter (or some other combination of filters) to attenuate the frequencies.
In software, you'd solve this problem by writing a digital filter of sorts that would reduce the output of various frequencies. Frequencies would be identified via an FFT computation.
The fastest thing to do would be to use an audio editing app and apply the changes there.
There is an audio library called PortAudio that may provide some support for editing an audio stream at the numerical level. It is written in C, and has a C API.
If you want to test out audio processing algorithms I strongly suggest Supercollider. It's free and has many kinds of audio filter built in. But eliminating voice could require considerable tweaking. Supercollider will allow you to write code driven by various parameters and then hook those parameters up to a GUI which you'll be able to tweak while supplying it with live (or recorded) data.
Even if you want to write C code, you'll learn a lot from using Supercollider first. Many of the filters are surprisingly easy to implement in C but you'll need to write a certain amount of framework code before you can get started.
Additionally, I learnt quite a bit about writing digital audio filters from this book. Among other things, it discusses some of the characteristics of human speech, as well as how to build filters to selectively enhance or knock out particular frequencies. It also provides working C code.
SciPy can do all sorts of signal processing.
You can also use MAX/MSP (but that's paid) or PureData (that's free) for working with music algorithms , they are the basis from which supercollider was created. And are excellent softwares if you want to do that on real-time envirollments.