Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

plotting in Matlab, why does it do it?

Status
Not open for further replies.

andrew257

Member level 2
Joined
Feb 22, 2007
Messages
42
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,648
Hi All,

I am having trouble understanding why my plots in matlab are looking the way they look.

For example i am plotting 3 sine waves with 3 different frequencies and amplitudes.
I am then sampling the 3 waves at a given frequency and at a given number of samples.

i then plot the 3 waves vs sample number. This works great and all is visible and clear.

However when i come to plot the 3 waves vs time rather than sample the waves become distorted and triangular like. Is there a reason for this? i assumed if the sample and time were identical in the same point in time (i.e after 200 samples this equates to 1 second, therefore showing a plot after 200 samples or 1 second would look the exact same????

am i missing something here?

Thank you

Andy

the code i am using is as follows

fs=1e3;f=[100;200;400]; n=0:1000;
a=[1,2,3,];
s=sin(f/fs*n*2*pi);
plot(n,s)

or for time i include
t=n/fs
plot(t,s)
 

hi

the 2 plots you have in your code should look the same disregarding the X axis, You can solve your problem incrementing the value of Fs

if you think this info is helpful click on "helped me" for statistics

Sal
 

Hi Sal,

Thanks for the replies, can you explain why they are different when plotted againt the x axis?

They are both the same point in time in my mind so should look the same? You are correct if i increase Fs the waves do look the same but i dont understand why.

Thank you

Andy
 

Hi andrew,

In first plot u plotted 'n' vs 's' where 'n' is 0:1000 and for every 'n' and for every every
'n' => 's' means u ahve 1000 's' values and 1000 'n' values .

so here u r using more samples.

In the second case u plotted 't' vs 's' but u r calculating s using 'n' and t is varying from 1e-3 to 1 only i.e only two samples available ('s' for t=0 and t=1 )

here u have 1000 's' values but only two 't' values suitable for 's' i.e 0 and 1.

I think ur doubt clear by this time.

If there is any wrong correct me.

Regards,
Goud
 

HI again

The reason why you can see the sine waves clearly when you increment fs is because of the "sampling theorem", according to it you need only double the frequency of the sine, But when you plot this sine with 2 points per wave, you wont see a sine.unless you increment the number of samples per pulse, and that is what you do when increment fs.

if you find it hard to understand, I recommend to read the sampling theorem which may be in many books and sites in the internet.

Sal
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top