There are trivial C programming issues, I think. I would generally suggest to trace program execution with a debugger to check for plausible operation.
One point is that in an expression as 2*pi*500*i/1000 the compiler is free to define the order of execution to its needs, thus an integer expressions 500*i and 500*i/1000 may be executed first. One would possibly cause overflow, if integer is 16 (you didn't tell about the enviroement), the other truncation anyway. Writing (500.0f*i) or (float)i would guarantee correct execution.
The oher point is, that local variables in a function are generally uninitialized in C, so your filter storage elements contain arbitrary valuesa t the beginning.
Finally, I don't know how the Scope component works, if it's used correct with the y output vector.
thank,FvM
I'm using VC++ ver6.0 , and that Scope ,I'm sure that It's completely TRUE.Because ,in my project I use one Active X control that can make Scope.
There is obvious buffer overflow :
You use sample[4] but size of array x is four so allowed index is 0,1,2,3 but not 4.
Also I think Scope.Channels[0].Data.SetYData(y,1000) ;//draw signal output
should be after for loop to speed up execution.
FvM, the C expression 2*pi*500*i/1000 is equivalent to (((2*pi)*500)*i)/1000.
If 'pi' is a double, then everything gets promoted to double, so there's no risk of dividing two integers.
Kernighan/Ritchie says, that a compiler is free to reorder * or + operators in an expression. Also, * and / have equal priority. I don't see a rule that would forbid to evaluate i/1000 first. It could be, that VC6 has additional self-defined constraints to provide more clarity to programmers.
K&R2 section A.7.6 says, "The multiplicative operators *, /, and % group left-to-right."
You may be thinking of this statement from K&R2 section 2.12:
"C, like most languages, does not specify the order in which the operands of an operator are evaluated."
That's a different issue.