I think that all of these answers are still pretty bad (including my previous ones ...) after I thought about the problem a bit more, I would suggest the following:
1) take a 1 second sample of the input signal (it doesn't have to be that big, but it simplifies a few things)
2) throughout the second, zero intersections are counted. at the moment you have cps (cycles per second) and know the frequency of the generator. (in case you want to know)
3) now take a smaller segment of the sample for work: take exactly 7 zero intersections. (therefore, your working buffer now, if rendered, will look like one of the graphical representations that you sent with the original question.) use this small working buffer to perform the following tests. (normalization of the working buffer at this moment can make life easier)
4) square wave test: zero crossings for a square wave are always very big differences, look for a large delta of the triangle, followed by a slight movement until the next zero transition.
5) saw wave test: similar to a square wave, but a delta of a linear constant value will follow a large signal delta.
6) test for triangles of a triangular wave: linear constant (small). find the peaks, divide by the distance between them and calculate what the triangular wave should look like (ideally), now check the actual signal for deviation. set the deviation tolerance threshold and you can determine if you are looking at a triangle or sine (or something parabolic).
kent
source share