I would like to code something that could take some sort of input and identify it as a square wave, triangle wave, or some sort of waveform. I also need some way of generating said waves.
I do have experience with C/C++, however, I’m not sure how I would approach simulating all of this. Eventually, I would like to translate it to a microcontroller program for reading its analog input to determine the waveform.
EDIT: Sorry; I should have mentioned it would be at a known frequency and the amplitude should be unknown.
Generating the waves is significantly easier than identifying them. I have a small project that does some wave generation. Here’s an example from my project:
thetahere is updated at every frame along the wave form and is dependent on the frequency of the wave you’re creating.As for identifying waves, if you know you’re just going to be getting simple, unmixed square, triangle or sine waves, you can probably just do some simple tests. Look at the change in amplitude at any two points along the wave. If they’re the same, square wave. If they’re changing linearly (that is, if the change in amplitude is constant) you’ve got a triangle wave (or a sawtooth, if you’re making that distinction). Otherwise, it’s a sine wave. Keep in mind this check only works if you’re expecting just those types of wave, and they’re not being mixed or anything. There’s some other edge cases in there I can think of but I’ll let you worry about that.
If you’re doing anything fancier, you’re going to need to probably look up a book that specializes in this sort of thing, like the one suggested in the comments section.