Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi , i want to create a user interface in which the user will enter the sampling rate and the frequency, the interface will plot the sine wave when pressed on a button accordingly using chart series.
simply what im trying to do is this code when written on matlab, 

1 fs= 96000;  
2 f= 1000;  
3 nCyl=1;  
4 t=0:1/fs:nCyl*1/f;  
5 x=sin(2*pi*f*t);  
6 plot(t,x)   

if you try to write this code on matlab a sine graph will appear,the thing i couldnt write as an equation in line 4, i want my user interface to give me the same sine graph after the user enters the sampling rate and frequency values.


thank you  


What I have tried:

i have tried the following code when pressing the button, there is no errors just the graph is wrong, it doesnt work correctly i think the equation is wrong:
double phasecent = 0;
                    double samplerate = 96000;
                    double freq = 1000;
                    for (int i = 0; i < samplerate; i++)
                    {
                        double t = Math.Sin(freq * (2 * Math.PI) * (phasecent) / samplerate);
                        phasecent++;
                        double x = Math.Sin(2 *Math.PI*freq*t);
                        chart1.Series["b2"].Points.AddXY(x, t);
                    }
Posted
Updated 11-Aug-22 3:12am
v5
Comments
OriginalGriff 11-Aug-22 7:21am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
turkmani_11 11-Aug-22 9:10am    
i have updated my question sir , i hope u can understand better now
Richard MacCutchan 11-Aug-22 9:16am    
Yes, bit you have still not explained what is wrong. Saying, "it doesnt work correctly" tells us nothing.
turkmani_11 12-Aug-22 1:53am    
sorry, what im getting is a straight line, what i should get is a sine wave.
OriginalGriff 11-Aug-22 9:58am    
"It doesn't work" is probably the most useless problem report we get - and we get it a lot. It tells us nothing about what is happening, or when it happens.
So tell us what it is doing that you didn't expect, or not doing that you did.
Tell us what you did to get it to happen.
Tell us any error messages.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900