signals and systems using matlab

Share Embed Donate


Short Description

Download signals and systems using matlab...

Description

Systems Lab

DATE: 08-02-2011 EXPERIMENT NO.1 FAMILIARISATION OF MATLAB AIM To familiarize with MATLAB and its functions. THEORY MATLAB is an ideal software tool for studying digital signal processing. The plotting capacity of MATLAB makes it possible to view the result of processing and gain understanding into complicated operations. The tool box support a wide range of signal processing from waveform generation to filter design and implementation, parametric modelling and spectral analysis. There are two categories of tools Signal processing functions Graphical interaction tools. The first category of tools is made of functions that we can call from the common line or from your own application. Many of the functions are MATLAB statements that implement specialized signal processing algorithm. (a) DEFINTION OF VARIABLES Variables are assigned numerical values by typing the expression directly Eg: a=1+2 yields a=3 The answer will not be displayed when semicolon is put at the end of an expression Eg: a=1+2 MATLAB utilizes the following arithmetic operations + Addition - Subtraction * Multiplication / Division ˆpower operation „Transpose A variable can be assigned using a formula that utilizes these operations and either numbers or previously defined variables. Eg: since „a‟ was defined previously the following expression is valid, B=z*a.To determine the value of a previously defined quantity type the quantity by b=6. If your expression does not fill on the line, use an ellipse and continue on the next line. C=1+2+3+. . . . . . . . . . . . ..+5+6+7. These are certain predefined variables which can be used at any time, in the same manner as user defined variables. i=sqrt(-1); j=sqrt(-1) Dept. Of ECE, SJCET, Palai

1

Systems Lab

pi=3.1416 Eg: y=2*(1+4*j)yields y=2.000+8.000y These are also a number of predefined functions that can be used when defining a variable. Some common functions that are used in this text are Abs- magnitude of a number Angle- angle of a complex numberCos- cosine function, assume arguments in radian. Exp-exponential functions For example with y defined as aboveE= abs(y), yields e=8.2462, c=angle(y) yields c=1.3258 with a=3 as defined previously c=cos(a)yields, c= -0.9900c = exp(a), yields c=20.0855.Note that exp can be used on complex numbers example with y = 2 + 8i as defined above c = -1.0751 + 7.3104i which can be verified by using Euler‟s formula c = c2cos(8) + jc2sin(8). (b) DEFINTION OF MATRICES MATLAB is based on matrix and vector algebra. Even scalars are treated 1x1 matrix. Therefore, vector and matrix operation are simple as common calculator operations. Vectors can be defined in two ways. The first method is used for arbitrary elements, v=[1 3 5 7] creates 1x4 vector elements with elements 1 3 5 &7. Note that commas would have been used in the place of spaces to separate the elements. Additional elements can be added to the vector v(5)=8 yields the vector v = [1357]. Previously defined vectors can be used to define a new vectors. For example with we defined above a= [910]; b = [v a]; creates the vector b = [1357910]. The second method is used for creating vector with equally spaced elements t=0:0.1:10; creates 1x101 vector with elements0,0.1,0.2. . . . . 10. Note that the middle number defines the increments is set to a default of 1k=0,10 creates 1x11 vector with the elements 0,1,2. . . .10. Matrices are defined by entering the element row by row. M = [124; 368] creates the matrix M= 1 2 43 6 8 There are number of special matrices that can be defined Null matrix: [ ]; Nxm matrixes of zero: M=zeros (m,m); Nxm matrix of ones: M= ones (n,m); Nxn matrix of identity: M=eye (n) A particular elements of matrix can e assigned M(1,2)=5 place the number 5 in the first row,2nd column. Operations and functions that were defined for scalars in the previous section can be used on vectors and matrices. For example a=[1 2 3]; b=[4 5 6]; c=a+b yield c=579. Functions are applied element by element. For example t=0:„0; x=cos(2*t) creates a vector „x‟ with elements equal to cos(2t) for t=0,1,2. . . ..10 (c) GENERAL INFORMATION MATLAB is case sensitive. So „a‟ and „A‟ are two different names. Comment statements are preceded by a %. Dept. Of ECE, SJCET, Palai

2

Systems Lab

1) M-files M-files are macros of MATLAB commands that are stored as ordinary text file with the extension „in‟ that is „filename.m‟. An m-file can be either a function with input and output variables or a set of commands. MATLAB requires that the m-file must be stored either in the working directory or in a directory that is specified in the MATLAB path list. The following commands typed from within MATLAB demonstrate how this m-file is used. X=2,y=3,z=y plusx(y,x) MATLAB m-files are most efficient when written in a way that utilizes matrix or vector operations, loops and if statements are available, but should be used sparingly since they are computationally inefficient. An examples is For k=1:10 x(k)=cos(k) end; This creates a 1x10vector „x‟ containing the cosine of the positive integers from 1 to 10. This operation is performed more efficiently with the commands k=1:10 x=cos(k) which utilizes a function of a vector instead of a for loop. An if statement can be used to define combinational statement. (d) REPRESENTATION OF SIGNALS A signal can be defined as function that conveys information, generally about or behaviour of physical system; signals are represented mathematically as functions of one or more independent variables. The independent variables is the mathematical expression of a signal may be either continuous is discrete. Continuous time signals are defined along a number of times and thus they are represented by a continuous independent variable. TheMATLAB is case sensitive. Discrete time signals are represented mathematically.Continuoustimesignals are often referred to as analog signals. Discrete time signals are defined at discrete times and thus the independent variable has discrete values. In a sequence of numbers x, the nthnumber in the sequence is denoted as x[n]. The basic signals used in digital signal processing are the unit impulse signal [U+0260](n), exponential of the form au[n], sine waves and their generalization to complex exponentials. Since the only numerical data type in MATLAB is the m x nmatrix, signals must be represented as vectors either mx1 matrix if column vector 1xn matrices if row vectors. A constant will be treated as 1x1 matrix. The signals are sampling frequency Fs,which is greater than twice the maximum frequency of the signal. In time domain, the signals are represented as time versus amplitude. In MATLAB you can generate time base for given signals T=t start: 1/Fs:t-stop,tstart is the starting time of the signal t-sto is the stop time of the signal and Fs sampling frequency. 1/Fs is the time period between the two samples. In signals like speech if the data secured length is too long, plotting of the whole signal will not be clean view. In that case we can use step function.

RESULT The familiarization of MATLAB was completed.

Dept. Of ECE, SJCET, Palai

3

Systems Lab

DATE: 08-02-2011 EXPERIMENT NO: 2 BASIC DISCRETE TIME SIGNALS AIM To plot the following waveforms 1. Step Function 2. Impulse Function 3. Exponential Function 4. Ramp Function 5. Sine Function

THEORY A digital signal can be either deterministic signal that can be predicted with certainty or random signal that is unpredictable. Due to ease in signal generation and need for predictability, deterministic signal can be used for system simulation studies.Standard forms of some deterministic signal that is frequently used in DSP are discussed below: 1. Impulse:the simplest signal is the unit impulse signal which is defined as δ (n) = 1 for n = 0 = 0 for n ≠ 0 2. Step:the general form of step function is u (n) = 1 for n ≥ 0 = 0 for n< 0 3. Exponential:the decaying exponential is a basic signal in DSP.Their general form is given by

x (n) = a n for all n. 4. Ramp:signal is given by ur (n) = n for n ≥ 0 = 0 for n < 0 5. Sine:A sinusoidal sequence is defined as x(n) = sin(n). ALGORITHM 1. Start 2. Generate the time axis 3. Define A as sine function 4. Plot the sine wave Dept. Of ECE, SJCET, Palai

4

Systems Lab

5. Define B as exponential signal 6. Plot the exponential signal 7. Define r(n) as ramp signal 8. Plot the ramp signal 9. Define unit impulse signal 10. Plot the signal 11. Define unit step signal 12. Plot the signal 13.Stop MATLAB FUNCTIONS USED • CLC: clc clears all input and output from the Command Window display, giving you a ”clean screen. “After using clc, you cannot use the scroll bar to see the history of functions, but you still can use the up arrow to recall statements from the command history. • CLEAR ALL: clear removes all variables from the workspace. This frees up system memory. • CLOSE ALL: Closes all the open figure windows • SUBPLOT: subplot divides the current figure into rectangular panes that are numberedrowwise. Each pane contains an axes object. Subsequent plots are output to the current pane. • STEM: A two-dimensional stem plot displays data as lines extending from a baseline along the xaxis. A circle (the default) or other marker whose y-position represents the data value terminates each stem. • TITLE: Each axes graphics object can have one title. The title is located at the top and in the centre of the axes. • XLABEL: Each axes graphics object can have one label for the x-, y-, and z-axis. The label appears beneath its respective axis in a two-dimensional plot and to the side or beneath the axis in a threedimensional plot. • YLABEL: Each axes graphics object can have one label for the x-, y-, and z-axis. The label appears beneath its respective axis in a two-dimensional plot and to the side or beneath the axis in a threedimensional plot. • ZEROS: Create array of all zeros • ONES: Create array of all ones • SIN: The sin function operates element-wise on arrays. The function‟s domains and ranges include complex values. All angles are in radians. • EXP: The exp function is an elementary function that operates element-wise on arrays. Its domain includes complex numbers.

Dept. Of ECE, SJCET, Palai

5

Systems Lab

PROGRAM %Generation of Basic Discrete Signals clear all clc close all %Generation of Sinusoidal signal n =0:0.5:10; y=sin(n); subplot(3,2,1); stem(n,y); xlabel(' Samples '); ylabel(' Amplitude'); title (' Sine'); %Generation of Exponential signal y=exp(n); subplot(3,2,2); stem(n,y); xlabel (' Samples '); ylabel(' Amplitude'); title (' Exponential'); %Generation of Ramp signal n =1:10; y=n; subplot(3,2,3); stem(n,y); xlabel (' Samples '); ylabel(' Amplitude'); title (' Ramp'); %Generation of Unit Impulse signal n =-10:10; y=[zeros(1,10) 1 zeros(1,10)]; subplot(3,2,4); stem(n,y); xlabel (' Samples '); ylabel (' Amplitude'); Dept. Of ECE, SJCET, Palai

6

Systems Lab

title(' Impulse'); %Generation of Unit Step signal n =-10:10; y=[zeros(1,10) 1 ones(1,10)]; subplot(3,2,5); stem(n,y); xlabel (' Samples '); ylabel(' Amplitude'); title (' Step');

OUTPUT

RESULT

The MATLAB program to generate basic discrete signals is executed and output

waveforms are obtained.

Dept. Of ECE, SJCET, Palai

7

Systems Lab

DATE: 17-02-2011 EXPERIMENT NO: 3 IMPULSE RESPONSE & STEP RESPONSE AIM Write a MATLAB program to find the impulse response and step response of the system given by y(n) = x(n) + x(n-1) – 0.7y(n-1) at -20 ≤ n ≤ 100. THEORY The impulse response of a given system is its response to impulse function input. We know that y[n]=impulse response h[n],when input x[n] is unit impulse function Step response of a system is its output for step function. ALGORITHM 1. Start 2. Input the coefficients of x(n). 3. Generate impulse signal. 4. Input the coefficients of y(n). 5. Obtain the impulse response using filter function 6. Plot the impulse response. 7. Generate step signal. 8. Obtain the step response using filter function. 9. Plot the step response. 10. Stop. MATLAB FUNCTIONS USED FILTER: One dimensional digital filter. Y=FILTER (B, A, X) filter the data in vector X with the filter described by vectors A and B to create the filtered data Y. The filter is a “Direct Form II Transposed” implementation of the standard difference equation: a(1) * y(n) = b(1) * x(n) +b(2) * x(n - 1) + .... + b(nb + 1) * x(n - nb) - a(2) * y(n - 1) - . . . a(na + 1) * y(n - na) If a(1) is not equal to 1, filter normalizes the filter coefficients by a(1).

Dept. Of ECE, SJCET, Palai

8

Systems Lab

PROGRAM clc clear all close all x = [ 1 1]; y = [1 0.7]; n = -20:1:10; imp = [zeros(1,20) 1 zeros(1,10)]; h = filter (x, y, imp); subplot (2, 1, 1); stem (n,h); title(' Impulse Response '); xlabel (' Samples '); ylabel (' Amplitude '); stp = [zeros(1,10 1 ones(1,20)]; h = filter(x,y,stp); subplot ( 2, 1, 2); stem(n,h); title (' Step Response '); xlabel (' Samples '); ylabel (' Amplitude ');

Dept. Of ECE, SJCET, Palai

9

Systems Lab

OUTPUT

RESULT The MATLAB program to find the impulse response and step response of the given system is executed and output waveform is obtained.

Dept. Of ECE, SJCET, Palai

10

Systems Lab

DATE: 24-02-2011 EXPERIMENT NO: 4

LINEARITY, STABILITY & CAUSALITY

AIM Write a MATLAB program to find whether the given systems are linear, stable and causal. 1. y(n) = x(n) – 0.9y(n-1) 2. y(n) = exp x(n) THEORY A system is linear if and only if T [a1x1[n] + a2x2n]] = a1T [x1[n]] + a2T [x2[n]], for any arbitrary constants a1 and a2. Let x[n] be bounded input sequence and h[n] be impulse response of the system and y[n], the output sequence. Necessary and sufficient boundary condition for stability is8n = -8|h[n]| < 8. Causal system is a system where the output depends on past or current inputs but not on the future inputs. The necessary condition is h[n] = 0; < 0, where h[n] is the impulse response. ALGORITHM 1. Start 2. Input the coefficients of x(n) and y(n) 3. Generate random signals x1 and x2. 4. Check for linearity using filter function of the given system and display 5. Generate impulse signal. 6. Check for causality using filter function of the given system and display 7. Obtain the absolute value of impulse response and check for the stability of the system and display. 8. Stop MATLAB FUNCTIONS USED • RAND: Uniformly distributed pseudo random numbers. R=RAND (N) returns an N-by-N matrix containing pseudo-random values drawn from a uniform distribution on the unit interval. RAND (M , N)or RAND([M, N]) returns an M-by-N matrix.

Dept. Of ECE, SJCET, Palai

11

Systems Lab

• DISP: Display array. DISP(X) displays the array, without printing the array name. In all other ways it‟s the same as leaving the semicolon of an expression except that empty arrays don‟t display. • ABS: Absolute value. ABS(X) is the absolute value of the elements of X. • SUM: Sum of elements. S=SUM(X) is the sum of the elements of the vector X.

PROGRAM %Program to find linearity of system 1 clc clear all close all

% System 1 % Linearity b = [1 0]; a = [1 0.9];

x1 = rand (1,10); x2 = rand (1,10); y2 = filter (b, a, 2.*x1); y5 = filter (b, a,2.* x2); y = filter (b, a, x1); y0 = filter (b, a, x2); y6 = y2+y5; y7 = y+y0; if (y6-y7 ~= 0) disp (' Linear ') else disp (' Non Linear ') end; % Causality--------%%%

n= -10:1:10; x = [zeros(1,10) 1 zeros(1,10)]; y1 = filter (a, b, x); Dept. Of ECE, SJCET, Palai

12

Systems Lab

subplot (2, 1, 1); stem (n1,y1); xlabel (' Samples '); ylabel (' Amplitude ');

% Stability T = abs (y1); t = sum (T); if (t < 1000) disp (' Stable ') else disp (' Unstable ') end;

%%%%%%%%%% % System 2%%%%%%%%%%%%%%%%%%%%% % 1 % Linearity

y8 = exp (x2); y9 = exp ( x3); y10 = 5*y8+5*y9; y11 = exp(5*x2+5*x3); if (y11-y10~=0) disp (' 2Linear ') else disp (' 2Non Linear ') end;

% 2 % Causality

Y8= exp (x); subplot (2, 1, 2); stem (n1,y8); xlabel (' Samples '); ylabel (' Amplitude ');

Dept. Of ECE, SJCET, Palai

13

Systems Lab

% 3 % Stability T1= abs (y8); t1 = sum (T1); if (t1 < 1000) disp (' 2Stable ') else disp (' 2Unstable ') end; OUTPUT

System 1 Linear. Stable. System 2 Non Linear. Stable. Dept. Of ECE, SJCET, Palai

14

Systems Lab

RESULT The MATLAB program to find the linearity, causality, and stability of 2 systems given is executed and output is obtained System 1 Linear Stable Causal

Dept. Of ECE, SJCET, Palai

System 2 Non Linear Stable Non Causal

15

Systems Lab

DATE: 15-03-2011 EXPERIMENT NO: 5

CONVOLUTION AIM Write a MATLAB program to obtain linear and circular convolution of the following sequences 1.

x(n) = [1 2 3 4] h(n) = [1 2 3]

2.

x(n) = u(n) h(n) = u(n-2)

THEORY Convolution is used to find the output response of a digital system. The linear convolution of two continuous time signals x[n] and h[n] is defined by y[n] = x[n] * h[n]. Circular Convolution of two sequences x1[n] and x2[n], each of length N is given by y[n] = If the length of sequence is not equal, zero padding is done. Convolution operation will result in the convolved signal be zero outside of the range n= 0,1,...,N-1. ALGORITHM 1. Start 2. Input the sequences 3. Input the length of sequences 4. Calculate the linear convolution. 5. Calculate the circular convolution. 6. Stop

MATLAB FUNCTIONS USED

• CONV: Convolution and polynomial multiplication. C = CONV (A,B) convolves vectors A and B. The resulting vector is length LENGTH(A) + LENGTH(B) – 1 .If A and Bare vectors of polynomial coefficients, convolving them is equivalent to multiplying the two polynomials. • LENGTH: Length of vector. LENGTH(X) returns the length of vector X.

Dept. Of ECE, SJCET, Palai

16

Systems Lab

• CCONV: Convolution and polynomial multiplication. C = CONV (A,B) convolves vectors A and B. The resulting vector is length LENGTH(A) + LENGTH(B) – 1 .If A and Bare vectors of polynomial coefficients, convolving them is equivalent to multiplying the two polynomials.

PROGRAM %program to find convolution of two sequences clc close all clear all n = -10:10; x1 = [1 2 3 4]; subplot(4,2,1); stem(x1); title('-----x1(n)----'); h1 = [1,2,3]; subplot(4,2,3); stem(h1); title('-----h1(n)----'); %%%%%linear convolution%%%%%% l1 = conv(x1,h1) subplot(4,2,5); stem(l1); title('-----linear convolution-1--'); %%%%%%%%%% circular convolution %%%%%%%%%%%5 x1 = [1 2 3 4]; h1 = [1 2 3 0]; c1 = cconv(x1,h1,4)

Dept. Of ECE, SJCET, Palai

17

Systems Lab

subplot(4,2,7); stem(c1); title('-----circular convolution-1---');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% x2 = [zeros(1,10) ones(1,11)]; subplot(4,2,2); stem(n,x2); title('-----x2(n)----'); h2 = [zeros(1,12) ones(1,9)]; subplot(4,2,4); stem(n,h2); title('-----h2(n)----'); %%%%%linear convolution%%%%%% l2= conv(x2,h2) subplot(4,2,6); stem(l2); title('-----linear convolution--2--'); %%%%%%%%%% circular convolution %%%%%%%%%%% c2 = cconv(x2,h2,8) subplot(4,2,8); stem(c2); title('-----circular convolution--2----');

Dept. Of ECE, SJCET, Palai

18

Systems Lab

OUTPUT

RESULT The MATLAB program to find the linear convolution and circular convolution of given sequences is executed and output is obtained.

Dept. Of ECE, SJCET, Palai

19

Systems Lab

DATE: 15-03-2011 EXPERIMENT NO: 6

CONVOLUTION USING DFT

AIM 1. Write a MATLAB program to obtain linear convolution of x(n) = [1 2 3 4] h(n) = [1 2 2 -1] using DFT. 2. Write a MATLAB program to obtain circular convolution of x(n) = u(n),

h(n) = u(n-3)

THEORY Convolution is used to find the output response of a digital system. The linear convolution of two continuous time signals x[n] and h[n] is defined by y[n] = x[n] * h[n] = Let X(k) and H(k) be the Fourier transforms of x[n] and h[n] respectively. Then by DFT method, convolution of x[n] and h[n] is given by: x[n]*h[n]= Inverse Fourier transform of X(k).H(k). Circular convolution of two sequences x1[n] and x2[n], each of length N is given by y[n] = If the length of sequence is not equal, zero padding is done. Convolution operation will result in the convolved signal be zero outside of the range n= 0,1,...,N-1.Then by DFT method, convolution of x[n] and h[n] is given by: x[n]*h[n]= Inverse Fourier transform of X(k).H(k). ALGORITHM 1. Start 2. Input the sequences 3. Input the length of the sequences. 4. Find the FFT of the sequences 5. Multiply the FFT of the sequences. 6. Calculate the IFFT 7. Stop

Dept. Of ECE, SJCET, Palai

20

Systems Lab

MATLAB FUNCTIONS USED • FFT: Discrete Fourier Transform. FFT(X) is the discrete Fourier transform(DFT) of vectorX. FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points and truncated if it has more. • IFFT: Inverse discrete Fourier transform. IFFT(X) is the inverse discrete Fourier transform of X. IIF(X,N) is the N-point inverse transform.

PROGRAM clc; close all; clear all; x1 = [1 2 3 4]; subplot(4,2,1); stem(x1); title('-----x1(n)----'); h1 = [1 2 2 -1]; subplot(4,2,3); stem(h1); title('-----h1(n)----'); l = conv(x1,h1) subplot(4,2,5); stem(l); title('-----linear convolution----') dx1 = fft(x1,7); dh1 = fft(h1,7); dl = dx1.*dh1; k1 = ifft(dl) subplot(4,2,7); stem(k1);

Dept. Of ECE, SJCET, Palai

21

Systems Lab

title('-----linear convolution--dft--'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% x2 = ones(1,6); subplot(4,2,2); stem(x2); title('-----x2(n)----'); h2 = [zeros(1,3) ones(1,3)]; subplot(4,2,4); stem(h2); title('-----h2(n)----'); c = cconv(x2,h2,6) subplot(4,2,6); stem(c); title('-----circular convolution------'); dx2 = fft(x2,6); dh2 = fft(h2,6); dc = dx2.*dh2; k2 = ifft(dc) subplot(4,2,8); stem(k2); title('-----circular convolution--dft----');

Dept. Of ECE, SJCET, Palai

22

Systems Lab

OUTPUT

RESULT The MATLAB program to find linear convolution and circular convolution of given sequences using DFT is executed and output is obtained.

Dept. Of ECE, SJCET, Palai

23

Systems Lab

DATE: 22-03-2011 EXPERIMENT NO: 7

CORRELATION

AIM a) Write a MATLAB program to compute autocorrelation of sequence x(n) = 0.9 n , n= 0 to 20 and verify the property. b) Compute cross-correlation of sequences x(n) = {1,2,3,4,5,6} and y(n) = x(n-3) and verify the property.

THEORY Autocorrelation is the cross-correlation of a signal with itself. The autocorrelation sequence of x(n) is given by RXX[l] = ∑

( ) (

)

Cross correlation is a measure of similarity of two signals, commonly used to find features in an unknown signal by comparing it to a known one. The correlation sequence of x(n) and y(n) is given by RXY[l] = ∑

( ) (

)

l=0,±1,±2,…

ALGORITHM 1. Start 2. Input the sequences 3. Find the autocorrelation of the sequence 4. Check for the symmetry property of the sequence 5. Find the cross correlation of the sequences 6. Check for the symmetry property of the sequence 7. Stop

Dept. Of ECE, SJCET, Palai

24

Systems Lab

MATLAB FUNCTIONS USED XCORR(A): when A is a vector, is the auto-correlation sequence.XCORR(A), when A is an M-by-N matrix, is a large matrix with2*M-1 rows whose N^2 columns contain the cross-correlation sequences for all combinations of the columns of A. XCORR(A,B): where A and B are length M vectors (M>1), returns the length 2*M-1 crosscorrelation sequence C. If A and B are of different length, the shortest one is zero-padded. FLIPLR: Flip matrix in left/right direction. FLIPLR(X) returns X with row preserved and columns flipped in the left/right direction. PROGRAM clc; clear all; close all; %autocorrelation of x(n) n=0:20; x=0.9.^n;

% input sequence

y =xcorr(x);

% autocorrelation

subplot(2,2,1); stem (y); xlabel (' Samples ') ylabel ('Amplitude'); title(' Autocorrelation of x(n)'); %autocorrelation ofx(-n) z =fliplr (y);

% flip the matrix y

subplot(2,2,2); stem (z); xlabel (' Samples '); ylabel(' Amplitude'); title (' Autocorrelation of x(-n)'); %cross correlation of x(n) & y(n) x1= [1 2 3 4 5 6 0 0 0];

%input

h1 = [0 0 0 1 2 3 4 5 6];

% input

y1 =xcorr (x1, h1);

% cross correlation of e and f

subplot(2,2,3); stem (y1); Dept. Of ECE, SJCET, Palai

25

Systems Lab

xlabel (' Samples ') ;ylabel(' Amplitude'); title(' Cross correlation of x(n) and y(n)'); %cross correlation property z1= fliplr (y1); subplot(2,2,4); stem (z1); xlabel (' Samples '); ylabel(' Amplitude'); title (' Cross correlation of x(-n) and h(-n)'); OUTPUT

RESULT The MATLAB program to compute autocorrelation and cross correlation of the given sequences is executed and output is obtained.

Dept. Of ECE, SJCET, Palai

26

Systems Lab

DATE: 22-03-2011 EXPERIMENT NO: 8

SAMPLING THEOREM

AIM Write a MATLAB program to generate x(n) = sin 0.5πn for n to 50. Verify sampling theorem.

THEORY Sampling Theorem: A band limited signal can be reconstructed exactly if it is sampled at a rate at least twice the maximum frequency component in it.” Figure 1 shows a signal g(t) that is band limited.

Figure 1: Spectrum of band limited signal g(t)

The maximum frequency component of g(t) is fm. To recover the signal g(t) exactly from its samples it has to be sampled at a rate fs=2fm. The minimum required sampling rate fs = 2fm iscalled Nyquist rate.

Dept. Of ECE, SJCET, Palai

27

Systems Lab

ALGORITHM 1. Start 2. Generate the sine wave 3. Resample the signal at various values. 4. Obtain the output waveforms 5. Stop MATLAB FUNCTIONS USED RESAMPLE : Change the sampling rate of a signal. Y = RESAMPLE(X,P,Q) resamples the sequence in vector X at P/Q times the original sample rate using a polyphase implementation. Y is P/Q times the length of X (or the ceiling of this if P/Q is not an integer). P and Q must be positive integers. PROGRAM % Verification of sampling theorem clc; clear all; close all; n = 0:0.5:50; x = sin(0.5*pi*n); subplot(4,1,1); stem(x); title('original'); y = resample(x,2,1); subplot(4,1,2); stem(y); title('fs = 2fm'); y = resample(x,4,1); subplot(4,1,3); stem(y); title('fs > 2fm'); y = resample(x,1,2); subplot(4,1,4); stem(y); title('fs
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF