+ Post New Thread
Results 1 to 5 of 5

6th November 2013, 04:16 #1
 Join Date
 Aug 2010
 Posts
 159
 Helped
 7 / 7
 Points
 1,748
 Level
 9
simple matlab code displays different graph
Hi,
I don't understand why the following simple sine wave code displays different waveform when simulated repeatedly?
fc=10;
fs=2*fc;
ts=1/fs;
t=0:ts:50;
x=sin(2*pi*fc*t);
plot(t,x);
the first run showed a correct sine wave, when i rerunned the code I get the following waveform
sinewave.bmp
thanks

Advertisment

6th November 2013, 05:04 #2
 Join Date
 Jul 2011
 Location
 India
 Posts
 1,162
 Helped
 199 / 199
 Points
 7,319
 Level
 20
 Blog Entries
 4
Re: simple matlab code displays different graph
See the amplitude its 10^13 which you can assume to zero.
Its negligible.
What do you mean by rerun.
   Updated   
Have a look at this link:
https://sites.google.com/site/coolembeddedlaboratory/home/matlab
Code:% This Script file Plots the Sine Wave with respect to time %The red text are comments clc; %Used to clear the screen (Just Clears the Screen) clear; %Used to clear the Variable Window (This clears the Memory) fSampling = 1000; %Sampling Frequency t = 0:1/fSampling:1; %Time Interval f = 3; %Carrier Frequency sine_wave = sin(2*pi*f*t); plot(t,sine_wave); %For Plotting the Sine Wave with Respect to time xlabel('Time Axis'); ylabel('Sine Wave Amplitude'); title('Sine Wave Plot'); grid on;

Advertisment

6th November 2013, 08:19 #3
 Join Date
 Aug 2010
 Posts
 159
 Helped
 7 / 7
 Points
 1,748
 Level
 9
Re: simple matlab code displays different graph
hi xpress, thanks but my code is fine, when the sampling frequency is increased the waveform is fine...
I don't understand why the figure is like the one attached when I set the sampling frequency fs=2*fc that is twice the carrier???
at fs=2fc the signal waveform is like an exponential increasing sinusoid.
looking forward for answer

Advertisment

7th November 2013, 08:15 #4
 Join Date
 Feb 2008
 Location
 Turkiye
 Posts
 259
 Helped
 60 / 60
 Points
 3,270
 Level
 13
Re: simple matlab code displays different graph
Since fs=2*fc in this case sampling timing (ts) occurs on time 2*pi*fc*(1/2fc), 2*pi*fc*(2/2fc), 2*pi*fc*(3/2fc) etc. at this moment ( pi, 2pi, 3pi,...) sin funciton is zero.
So you see graph around zero. You need to increase the sampling freq.
Another words, in this case you always sample sin wave at zero crossing points, so sampled values are zero.
PS: But i don't understand why it is plotted correctly at the first run.

7th November 2013, 09:13 #5
 Join Date
 Jul 2011
 Location
 India
 Posts
 1,162
 Helped
 199 / 199
 Points
 7,319
 Level
 20
 Blog Entries
 4
Re: simple matlab code displays different graph
Sampling Frequency >= 2* Signal Frequency
Nyquist Criteria, so in order to reconstruct your signal, Sampling frequency must be 2 times greater than the Signal Frequency.
The greater Sampling Frequency the better signal you will make but will also increase the bandwidth
+ Post New Thread
Please login