Professional Documents
Culture Documents
No: 3135127
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 signal x(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.
The 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 Nyquist sampling rate SAMPLING & ALIASING: MATLAB PROGRAM
clc; clear all; close all; fm= 1/20; t= -20 : 20; g= sin ( 2* pi * fm * t ); subplot( 2, 2, 1), plot ( t, g); title(' Continuous Sine wave'); f1= 1.3 * fm; f2= 2 * fm; f3= 5 * fm; % for freq < 2* fm t1= -4 : 4; g1= sin( 2* pi * fm/f1 * t1 ); subplot( 2, 2, 2), stem ( t1, g1); title(' when freq < 2 * fm'); % for freq = 2* fm t2= -5 : 5; g2= sin( 2* pi * fm/f2 * t2 ); subplot( 2, 2, 3), stem ( t2, g2); title(' when freq = 2 * fm'); % for freq > 2* fm t3= -20 : 20; g3= sin( 2* pi * fm/f3 * t3 ); subplot( 2, 2, 4), stem ( t3, g3); title(' when freq > 2 * fm'); % time scale x- axis % discrete signal - y axis % frequency % time axis from -20,-19,-18.....0, 1,.....19,20, % continuous sine wave % t- x-axis, g- y axis
RESULT: Thus the MATLAB code for sampling & aliasing was written and executed.
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 2 2 5 7 7 6 4
and 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 a factor 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 will be 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
UP SAMPLING & DOWN SAMPLING clc; clear all; close all; % UP SAMPLING % no of samples % time axis from 0 - 9, % continuous sine wave % n- x axis, g- y axis
N= 10; t= 1 : N; g= sin( 2* pi * t/10 ) + sin( 2* pi * t/5 ) ; subplot( 2, 2, 1), stem ( t, g); xlabel('time'),ylabel('Amplitude'); title(' INPUT SEQUENCE '); L= 3; K= L* N; g1= zeros ( 1, K); t1= 1: K; g1( 1 : L : K ) = g ;
subplot( 2, 2, 2), stem ( t1, g1); xlabel('time'),ylabel('Amplitude'); title(' UP SAMPLING OF THE SEQUENCE'); % DOWN SAMPLING N= 20; t= 1 : N; g= sin( 2* pi * t/10 ) + sin( 2* pi * t/5 ) ; subplot( 2, 2, 3), stem ( t, g); xlabel('time'),ylabel('Amplitude'); title(' INPUT SEQUENCE '); t2= 1 : N/2 ; g2= g( 1: 2: N ) ; % no of samples % time axis from 0 - 19, % input sequence % n- xaxis, g- y axis
% half the time scale x- axis % sampling the signal 'y' 2 samples apart
subplot( 2, 2, 4), stem ( t2, g2); xlabel('time'),ylabel('Amplitude'); title(' DOWN SAMPLED SEQUENCE');
OUTPUT
RESULT Thus the MATLAB code for UP sampling & DOWN sampling was written and executed.
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 interval from 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 widesense stationary random process
% []-window and 6- fft length % periodogram is the absolute of the square of the fourier transform of the signal.
RESULT Thus the MATLAB code for power spectral density was written and executed.