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.

simple matlab code displays different graph

Status
Not open for further replies.

rameshrai

Full Member level 3
Full Member level 3
Joined
Aug 16, 2010
Messages
158
Helped
7
Reputation
14
Reaction score
7
Trophy points
1,298
appliedelectronicsengineering.blogspot.com
Activity points
2,272
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-

View attachment sinewave.bmp

thanks
 

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;

Try re-running this code.
 

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
 

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.
 

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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top