You are on page 1of 11

3/8/2017 SamplingaSignalinMatlabGaussianWaves

Published July 10, 2014 by Mathuranathan

Sampling a Signal in Matlab


Generating a continuous signal and sampling it at a given rate is
demonstrated here. In simulations, we may require to generate a
continuous time signal and convert it to discrete domain by appropriate
sampling.

For baseband signal, the sampling is straight forward. By Nyquist Shannon


sampling theorem, for faithful reproduction of a continuous signal in
discrete domain, one has to sample the signal at a rate fs higher than at-
least twice the maximum frequency fm contained in the signal (actually, it
is twice the one-sided bandwidth occupied by a real signal. For a baseband
signal bandwidth (0 to fm ) and maximum frequency fm in a given band
are equivalent).

Matlab or any other simulation softwares process everything in digital i.e,


discrete in time. Therefore, we cannot generate a real continuous-time
signal on it, rather we can generate a continuous-like signal by using a
http://www.gaussianwaves.com/2014/07/samplingasignalinmatlab/ 1/11
3/8/2017 SamplingaSignalinMatlabGaussianWaves

very very highsampling rate. When plotted, such signals look like a
continuous signal.

Lets generate a simple continuous-like sinusoidal signal with frequency


fm = 10kHz. In order to make it appear as a continuous signal when
plotting, a sampling rate offs =500kHz is used.

fs=500e3; %Very high sampling rate 500 kHz


f=10e3; %Frequency of sinusoid
nCyl=5; %generate five cycles of sinusoid
t=0:1/fs:nCyl*1/f; %time index
x=cos(2*pi*f*t);

plot(t,x)
title('Continuous sinusoidal signal');
xlabel('Time(s)');
ylabel('Amplitude');

Continous time signal in Matlab

Pretending the above generated signal as a sinusoidal signal, we would like


to convert the signal to discrete-time equivalent by sampling. By Nyquist
Shannon Theorem, the signal has to be sampled at at-least
f s = 2 f m = 20kH z . Lets sample the signal at f s1 = 30kH z and then

at fs1 = 50kH z for illustration.

http://www.gaussianwaves.com/2014/07/samplingasignalinmatlab/ 2/11
3/8/2017 SamplingaSignalinMatlabGaussianWaves
fs1=30e3; %30kHz sampling rate
t1=0:1/fs1:nCyl*1/f; %time index
x1=cos(2*pi*f*t1);

fs2=50e3; %50kHz sampling rate
t2=0:1/fs2:nCyl*1/f; %time index
x2=cos(2*pi*f*t2);

subplot(2,1,1);
plot(t,x);
hold on;
stem(t1,x1);
subplot(2,1,2);
plot(t,x);
hold on;
stem(t2,x2);

Sampling a Continous time signal in Matlab

Share this:

Share 119 Tweet Share 6 Share 2 submit

More

http://www.gaussianwaves.com/2014/07/samplingasignalinmatlab/ 3/11
3/8/2017 SamplingaSignalinMatlabGaussianWaves

Previous Post
Power Delay Profile

Next Post
Generating correlated random numbers

Mathuranathan
Mathuranathan Viswanathan - Founder and Author @
gaussianwaves.com which has garnered worldwide
readership. He is a masters in communication
engineering and has 9 years of technical expertise in
channel modeling and has worked in various
technologies ranging from read channel design for hard
drives, GSM/EDGE/GPRS, OFDM, MIMO, 3GPP PHY layer
and DSL. He also specializes in tutoring on various
subjects like signal processing, random process, digital
communication etc.., LinkedIn Profile

L AT E ST A RT I C L E S M AT L A B C O D E S S I G N A L P RO C E S S I N G

BA N D PA S S SA M P L I N G M AT L A B C O SA M P L I N G T H E O R E M

http://www.gaussianwaves.com/2014/07/samplingasignalinmatlab/ 4/11
3/8/2017 SamplingaSignalinMatlabGaussianWaves

2Comments Gaussianwaves
1 Login

Recommend 1 Share SortbyBest

Jointhediscussion

PTMayearago
Ithinkthereisalittlemistakeincodecommentsandplots:samplingfrequencyis
fs1=30kHzandfs2=50kHz(not3kHzand5kHz).
Reply Share

Mathuranathan Mod >PTM ayearago

Thanksforspottingthat.Willcorrectthemistake
1 Reply Share

ALSOONGAUSSIANWAVES

IntroductiontoMultipleAntenna HowtoInterpretFFTresultscomplex
Systems DFT,frequencybinsandFFTShift
9comments3yearsago 3commentsayearago
mikelThankyouverymuchforyour MathuranathanThanksforyour
fastreply! valuablefeedback.Iwilltrytoincorporate
yoursuggestionstofurtherimprovethe
article.
GeneratingBasicsignalsSquare ChirpSignalFrequencySweeping
WaveandPowerSpectralDensityusing FFTandpowerspectraldensity
FFT
5comments3yearsago 6comments3yearsago
MathuranathanDharman MathuranathanThefrequencyofthe
JeyaramanSomebookslistedbelow1) chirpsignalvarieswithtime,hencethe
MATLAB/SimulinkforDigital amplitudeofeachfrequencycomponent
CommunicationbyWonY.Yanget doesnot
Subscribe d AddDisqustoyoursiteAddDisqusAdd Privacy

Log in with:

http://www.gaussianwaves.com/2014/07/samplingasignalinmatlab/ 5/11
3/8/2017 SamplingaSignalinMatlabGaussianWaves

SEARCH ARTICLES

Search... Go

LIKE THIS WEBSITE ? SUBSCRIBE

Enter your email address to subscribe to this blog and receive notifications of new posts by
email.

Join 109 other subscribers

EmailAddress

Subscribe

PARTICIPATE AND WIN

Participate in Forums and win 32-GB microSD every month. Just top the leaderboard with
maximum reps at the end of each month

http://www.gaussianwaves.com/2014/07/samplingasignalinmatlab/ 6/11
3/8/2017 SamplingaSignalinMatlabGaussianWaves

SEARCH QUESTIONS

Searchquestions&answers Search

GRAB THIS EBOOK TODAY

RECENT QUESTIONS

BER for BPSK modulation in AWGN, Rayleigh, and Rician fading channels

1 Answer | 0 Votes

OFDM with QPSK

http://www.gaussianwaves.com/2014/07/samplingasignalinmatlab/ 7/11
3/8/2017 SamplingaSignalinMatlabGaussianWaves

0 Answers | 0 Votes

QPSK Complex input

1 Answer | 0 Votes

Correct the statement

1 Answer | 0 Votes

Could not able to get the results,can u help me in this concern

1 Answer | 0 Votes

RECENTLY SUBMITTED

A mathematical theory of communication Shannon

An Introduction to Information Theory and Applications

http://www.gaussianwaves.com/2014/07/samplingasignalinmatlab/ 8/11
3/8/2017 SamplingaSignalinMatlabGaussianWaves

More tutorials

CATEGORIES

8-PSK

Book reviews

BPSK

Channel Coding

Channel Modelling

Constellations

Correlative Coding

Digital Modulations

DPSK

Estimation Theory

Free Books

GMSK

Hamming Codes

Inter Symbol Interference

Interleaver

Introduction

Latest Articles

http://www.gaussianwaves.com/2014/07/samplingasignalinmatlab/ 9/11
3/8/2017 SamplingaSignalinMatlabGaussianWaves

Line Coding

M-PSK

M-QAM

Matlab Codes

MIMO systems

OFDM

Probability

Pulse Shaping

QPSK

Quiz

Random Process

Reed Solomon codes

Shannon Theorem

Signal Processing

Software Defined Radio

Source Coding

Spread Spectrum

Tips & Tricks

Tutorials

User submitted Codes

http://www.gaussianwaves.com/2014/07/samplingasignalinmatlab/ 10/11
3/8/2017 SamplingaSignalinMatlabGaussianWaves

VLSI

FOLLOW

DigitalCommunicatio
6,188likes

LikePage ShopNow

Bethefirstofyourfriendstolikethis

GaussianWaves

Follow +1

+ 456

TAGS

AR Auto-Correlation Auto regressive AWGN BPSK Channel Capacity Channel Coding

Channel Modelling cholesky convolution Cramer Rao Lower Bound CRLB Cross-

Correlation Digital Modulations Estimation Fading FFT Fisher Information Fisher

Matrix Fourier Analysis Fourier transform gray code M-QAM Matlab Code
Matlab Codes matrix algebra Maximum Likelihood Estimation Minimum Variance Unbiased
Estimator MLE Multi-carrier Modulation OFDM Orthogonal Frequency Division Multiplexing

oversampling positive definite Power spectral Density PSD Pulse Shaping Random Process
Random Variables Rayleigh Score Shannon Capacity Signal Processing Spread
Spectrum Tips & Tricks

http://www.gaussianwaves.com/2014/07/samplingasignalinmatlab/ 11/11

You might also like