Saturday, June 25, 2011

MATLAB Programs 05: Generating sine/cosine waveform

Below given is a program to generate sine waveform. Parameters for the sin() and cos() functions share same typical meaning.


%program to generate sine wave


f= input('enter the frequency in hertz of the sine wave'); 
t=0:.0001:5;
y=sin(2*pi*f*t);
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
TITLE ('Sine wave');



%program to generate cosine wave


f= input('enter the frequency in hertz of the sine wave'); 
t=0:.0001:5;
y=cos(2*pi*f*t);
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
TITLE ('cosine wave');





16 comments:

Anonymous said...

Thanks a lot



Rahul m.

Anonymous said...

how to sample it?

Anonymous said...

how to take its fft?

Anonymous said...

how can i make a sinusoidal generator with a variable frequency?

Anonymous said...

how to retain curve between time 2.5 to 3.5 and rest to be zero

Anonymous said...

run nai ho raha bhadveee

Anonymous said...

tu khud gand maraaa
ghar jaake
randve
hijde

Anonymous said...

uday prakash pethakamsetty said...

for the question: how to get fft,
ans is use fft command.

for the question : how to sample it?

ans: the output itself is a discrete signal. But, as the plot command is used,
you are getting a continuous representation.
But, you can change the sampling rate.

in second line,
t=0:.0001:5;
Here .0001 is the sampling period. change that value to change the sampling period, which in turn effects its inverse i.e., sampling frequency

Jibin Mathew said...

how can i generate sinc wave using matlab

Ahmad said...

i want to run both waves on same plot.... running in opposite direction (animation)... can i do that, if yes then how.. please i need answer ASAP

Anonymous said...

u can draw two plots on 1 graph using hold on command.here is the example
t=0:0.01:1
f=3
w=2*pi*f
a=2
f1=2
w=2*pi*f1
a1=-1
x=a*sin(w*t)
y=a1*sin(w1*t)
hold on
plot(t,x)
plot(t,y,'p')
title('Graph')
run this command on matlab.., hope thz will help.., thanks

Anonymous said...

i want to shift the modulated sine wave with period of 31.6microseconds is this possible???? plz answer my q'tn.....

Anonymous said...

super

Anonymous said...

what a program ya amazing ya

Anonymous said...

hey its super ya what ya amazing ya

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes