Dsp Record_word Nirmal
-
Upload
rijo-jackson-tom -
Category
Documents
-
view
221 -
download
0
Transcript of Dsp Record_word Nirmal
-
8/2/2019 Dsp Record_word Nirmal
1/10
NIRMAL KUMAR. P. Reg. No: 3135127
AIM:To Write a MATLAB Code for sampling & aliasing.
ALGORITHM: Get the sinusoidal wave as input. Get three different frequencies as per sampling theorem. Get three different output based on that three frequencies.
THEORY:
When a function is evaluated by numerical procedures, it is always
necessary to sample the function in some manner, because digital computers
cannot deal with analog, continuous functions
Sampling: If delta is the time interval between consecutive samples, then the
sampled time data can be represented as
Examples where sampled time domain data is used in engineering include
simple and complex vibration analysis of machinery, as well as measurements of
other variables such as boiler pressures, temperatures, flow rates and turbine
speeds and many other machine parameters. It is also used in areas where
computers and microcontrollers are used to automate processes and react to
input data from the processes.
Aliasing and the Nyquist Theorem
One would expect that if the signal has significant variation then Ts must be
small enough to provide an accurate approximation of the signalx(t). Significant
signal variation usually implies that high frequency components are present in the
signal. It could therefore be inferred that the higher the frequency of the
components present in the signal, the higher the sampling rate should be. If the
sampling rate is not high enough to sample the signal correctly then a
phenomenon called aliasing occurs.
EX.NO:1SAMPLING & ALIASING
06/ 02/ 12
-
8/2/2019 Dsp Record_word Nirmal
2/10
NIRMAL KUMAR. P. Reg. No: 3135127The term aliasing refers to the distortion that occurs when a continuous
time signal has frequencies larger than half of the sampling rate. The process of
aliasing describes the phenomenon in which components of the signal at high
frequencies are mistaken for components at lower frequencies.
The Nyquist Sampling Theorem states that to avoid aliasing occurring in the
sampling of a signal the sampling rate should be greater than or equal to twice
the highest frequency present in the signal. This is referred to as the Nyquistsampling rate
SAMPLING & ALIASING: MATLAB PROGRAM
clc; clear all; close all;
fm= 1/20; % frequency
t= -20 : 20; % time axis from -20,-19,-18.....0, 1,.....19,20,
g= sin ( 2* pi * fm * t ); % continuous sine wave
subplot( 2, 2, 1), plot ( t, g); % t- x-axis, g- y axis
title(' Continuous Sine wave');
f1= 1.3 * fm;
f2= 2 * fm;
f3= 5 * fm;
% for freq < 2* fm
t1= -4 : 4; % time scale x- axisg1= sin( 2* pi * fm/f1 * t1 ); % discrete signal - y axis
subplot( 2, 2, 2), stem ( t1, g1);
title(' when freq < 2 * fm');
% for freq = 2* fm
t2= -5 : 5; % time scale x- axis
g2= sin( 2* pi * fm/f2 * t2 ); % discrete signal - y axis
subplot( 2, 2, 3), stem ( t2, g2);
title(' when freq = 2 * fm');
% for freq > 2* fm
t3= -20 : 20; % time scale x- axis
g3= sin( 2* pi * fm/f3 * t3 ); % discrete signal - y axis
subplot( 2, 2, 4), stem ( t3, g3);
title(' when freq > 2 * fm');
-
8/2/2019 Dsp Record_word Nirmal
3/10
NIRMAL KUMAR. P. Reg. No: 3135127OUTPUT FOR SAMPLING & ALIASING
RESULT:
Thus the MATLAB code for sampling & aliasing was written and executed.
-
8/2/2019 Dsp Record_word Nirmal
4/10
NIRMAL KUMAR. P. Reg. No: 3135127
AIM:To Write a MATLAB Code for up sampling & down sampling.
ALGORITHM:
UP SAMPLING:
Get the length of input sequence. Get the up sampling factor. Generate the output sequence.
DOWN SAMPLING:
Get the length of input sequence. Get the down sampling factor. Generate the output sequence.
THEORY:
Down sampling:
The process of reducing a sampling rate by an integer factor is referred to as
down sampling of a data sequence. We also refer to down sampling as
''decimation'' The term ''decimation'' used for the down sampling process has
been accepted and used in many textbooks and fields. To down sample a data
sequence x(n) by an integer factor of M, we use the following notation:
y(m) = x(mM), (12.1)Where y (m) is the down sampled sequence, obtained by taking a sample from
the data sequence x (n) for every M samples (discarding M 1 samples for every
M samples).
As an example, if the original sequence with a sampling period T = 0.1 second
(sampling rate = 10 samples per sec) is given by
x(n):8 7 4 8 9 6 4 2257764
EX.NO:2
UP SAMPLING & DOWN SAMPLING09/ 02/ 12
-
8/2/2019 Dsp Record_word Nirmal
5/10
NIRMAL KUMAR. P. Reg. No: 3135127and we down sample the data sequence by a factor of 3, we obtain the down
sampled sequence as
y(m):8 8 4 5 6 ,
with the resultant sampling period T = 3 0.1 = 0.3 second (the sampling rate now
is 3.33 samples per second). Although the example is straightforward, there is a
requirement to avoid aliasing noise.
From the Nyquist sampling theorem, it is known that aliasing can occur in the
down sampled signal due to the reduced sampling rate. After down sampling by afactor of M, the new sampling period becomes MT, and therefore the new
sampling frequency is
fsM = 1/(MT) = fs /M, (12.2)
Where fs is the original sampling rate.
Hence, the folding frequency after down sampling becomes
fsM/2 = fs/(2M). (12.3)
This tells us that after down sampling by a factor of M, the new folding frequency
will be decreased M times. If the signal to be down sampled has frequency
components larger than the new folding frequency, f > fs/(2M), aliasing noise willbe introduced into the down sampled data.
Up sampling
Increasing a sampling rate is a process of up sampling by an integer factor of L.
This process is described as follows:
y(m) = { x(m/L) m=nL,
0 otherwise
where n = 0, 1, 2, , x(n) is the sequence to be up sampled by a factor of L, and
y(m) is the up sampled sequence. As an example, suppose that the data sequence
is given as follows:
x(n):8 8 4 5 6
After up sampling the data sequence x(n) by a factor of 3 (adding L 1 zeros for
each sample), we have the up sampled data sequence w(m) as:
w(m): 8 0 0 8 0 0 4 0 0 5 0 0 6 0 0
-
8/2/2019 Dsp Record_word Nirmal
6/10
NIRMAL KUMAR. P. Reg. No: 3135127UP SAMPLING & DOWN SAMPLING
clc; clear all; close all;
% UP SAMPLING
N= 10; % no of samples
t= 1 : N; % time axis from 0 - 9,
g= sin( 2* pi * t/10 ) + sin( 2* pi * t/5 ) ; % continuous sine wave
subplot( 2, 2, 1), stem ( t, g); % n- x axis, g- y axis
xlabel('time'),ylabel('Amplitude');
title(' INPUT SEQUENCE ');
L= 3;
K= L* N; % 30 samples.g1= zeros ( 1, K); % a zero row- matrix- 30 samples
t1= 1: K;
g1( 1 : L : K ) = g ; % up sampling. saving ' g' into g1-matrix
subplot( 2, 2, 2), stem ( t1, g1);
xlabel('time'),ylabel('Amplitude');
title(' UP SAMPLING OF THE SEQUENCE');
% DOWN SAMPLING
N= 20; % no of samples
t= 1 : N; % time axis from 0 - 19,
g= sin( 2* pi * t/10 ) + sin( 2* pi * t/5 ) ; % input sequence
subplot( 2, 2, 3), stem ( t, g); % n- xaxis, g- y axis
xlabel('time'),ylabel('Amplitude');
title(' INPUT SEQUENCE ');
t2= 1 : N/2 ; % half the time scale x- axis
g2= g( 1: 2: N ) ; % sampling the signal 'y' 2 samples apart
subplot( 2, 2, 4), stem ( t2, g2);
xlabel('time'),ylabel('Amplitude');
title(' DOWN SAMPLED SEQUENCE');
-
8/2/2019 Dsp Record_word Nirmal
7/10
NIRMAL KUMAR. P. Reg. No: 3135127
OUTPUT
RESULT
Thus the MATLAB code for UP sampling & DOWN sampling was written and
executed.
-
8/2/2019 Dsp Record_word Nirmal
8/10
NIRMAL KUMAR. P. Reg. No: 3135127
AIM:To Write a MATLAB Code for power spectral density.
ALGORITHM: Get the frequencies of two sinusoidal waves Get sampling frequency Get length of sequence to be considered Get the two FFT lengths for comparing the corresponding power spectral
densities
THEORY:
The power spectral density (PSD) is intended for continuous spectra. The
integral of the PSD over a given frequency band computes the average power in
the signal over that frequency band. In contrast to the mean-squared spectrum,
the peaks in these spectra do not reflect the power at a given frequency.
A one-sided PSD contains the total power of the signal in the frequency intervalfrom DC to half of the Nyquist rate. A two-sided PSD contains the total power in
the frequency interval from DC to the Nyquist rate.
Power spectral density (PSD), which describes how the power of a signal or time
series is distributed with frequency. Here power can be the actual physical power,
or more often, for convenience with abstract signals, can be defined as the
squared value of the signal, that is, as the actual power dissipated in a load if the
signal were a voltage applied to it. This instantaneous power (the mean or
expected value of which is the average power) is then given by,
P(t) = s(t)2
for a signal s(t).
Since a signal with nonzero average power is not square integrable, the Fourier
transforms do not exist in this case. Fortunately, the WienerKhinchin theorem
provides a simple alternative. The PSD is the Fourier transform of the
autocorrelation function, R(), of the signal if the signal can be treated as a wide-
sense stationary random process
EX.NO:3
POWER SPECTRAL DENSITIES13/ 02/ 12
-
8/2/2019 Dsp Record_word Nirmal
9/10
-
8/2/2019 Dsp Record_word Nirmal
10/10
NIRMAL KUMAR. P. Reg. No: 3135127OUTPUT FOR POWER SPECTRAL DENSITY
RESULT
Thus the MATLAB code for power spectral density was written and
executed.