Docsity

signal generation for coding in matlab, Study notes of Digital Systems Design

Partial preview of the text

Download signal generation for coding in matlab and more Study notes Digital Systems Design in PDF only on Docsity!

FLOWCHART:

START ENTER THE SIGNAL PARAMETERS (AMPLITUDE, TIME AND FREQUENCY) Generate the waveform by using the appropriate library function PLOT THE WAVEFORMS STOP

AIM:

Write a program in MATLAB to generate the following waveforms (Discrete – Time signal and Continuous – Time signal)

  1. Unit Impulse sequence,
  2. Unit step sequence,
  3. Unit Ramp sequence,
  4. Sinusoidal sequence,
  5. Exponential sequence,
  6. Random sequence,
  7. Pulse signal,
  8. Unit step signal 3. Ramp signal 4. Sinusoidal signal, 5. Exponential signal, 6. R a n d o m s i g n a l APPARATUS REQUIRED: Ex. No : Date:09-12- Ex. No :

Date:09-12-13 WAVEFORM GENERATION

WAVEFORM GENERATION

LIBRARY FUNCTIONS:

clc: CLC Clear command window. CLC clears the command window and homes the cursor. clear all: CLEAR Clear variables and functions from memory. CLEAR removes all variables from the workspace.CLEAR VARIABLES does the same thing. close all: CLOSE Close figure.CLOSE, by itself, closes the current figure window. CLOSE ALL closes all the open figure windows. exp: EXP Exponential. EXP(X) is the exponential of the elements of X, e to the X. input: INPUT Prompt for user input. R = INPUT('How many apples') gives the user the prompt in the text string and then waits for input from the keyboard. The input can be any MATLAB expression, which is evaluated,using the variables in the current workspace, and the result returned in R. If the user presses the return key without entering anything, INPUT returns an empty matrix. linspace: LINSPACE Linearly spaced vector.

LINSPACE(X1, X2) generates a row vector of 100 linearly equally spaced points between X1 and X2. rand: The rand function generates arrays of random numbers whose elements are uniformly distributed in the interval (0,1). ones: ONES(N) is an N-by-N matrix of ones. ONES(M,N) or ONES([M,N]) is an M-by-N matrix of ones. zeros: ZEROS(N) is an N-by-N matrix of Zeros. ZEROS(M,N) or ZEROS([M,N]) is an M- by-N matrix of zeros plot: PLOT Linear plot. PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. subplot: SUBPLOT Create axes in tiled positions. H = SUBPLOT(m,n,p), or SUBPLOT(mnp), breaks the Figure window into an m-by-n matrix of small axes, selects the p-th axes for the current plot, and returns the axis handle. The axes are counted along the top row of the Figure window, then the second row, etc.

close all; t1=-3:1:3; x1=[0,0,0,1,0,0,0]; subplot(2,3,1); plot(t1,x1); xlabel('time'); ylabel('Amplitude'); title('Unit impulse signal'); %UNIT STEP SIGNAL t2=-5:1:25; x2=[zeros(1,5),ones(1,26)]; subplot(2,3,2); plot(t2,x2); xlabel('time'); ylabel('Amplitude'); title('Unit step signal'); %EXPONENTIAL SIGNAL a=input('Enter the value of a:'); t3=-10:1:20; x3=exp(-1at3); subplot(2,3,3); plot(t3,x3); xlabel('time'); ylabel('Amplitude'); title('Exponential signal'); %UNIT RAMP SIGNAL t4=-10:1:20; x4=t4; subplot(2,3,4); plot(t4,x4); xlabel('time'); ylabel('Amplitude'); title('Unit ramp signal'); %SINUSOIDAL SIGNAL A=input('Enter the amplitude:'); f=input('Enter the frequency:'); t5=-10:1:20; x5=Asin(2pift5); subplot(2,3,5);

plot(t5,x5) xlabel('time'); ylabel('Amplitude'); title('Sinusoidal signal'); %RANDOM SIGNAL t6=-10:1:20; x6=rand(1,31); subplot(2,3,6); plot(t6,x6); xlabel('time'); ylabel('Amplitude'); title('Random signal'); %WAVE FORM GENERATION %DT SIGNAL %UNIT IMPULSE clc; clear all; close all; n1=-3:1:3; x1=[0,0,0,1,0,0,0]; subplot(2,3,1); stem(n1,x1); xlabel('time'); ylabel('Amplitude'); title('Unit impulse signal'); %UNIT STEP SIGNAL n2=-5:1:25; x2=[zeros(1,5),ones(1,26)]; subplot(2,3,2); stem(n2,x2); xlabel('time'); ylabel('Amplitude'); title('Unit step signal'); %EXPONENTIAL SIGNAL a=input('Enter the value of a:'); n3=-10:1:20; x3=power(a,n3); subplot(2,3,3);

DISCRETE TIME :

OUTPUT WAVEFORM(CONTINUOUS

TIME):

OUTPUT WAVEFORM (DISCRETE TIME):

The program to generate various waveforms is written, executed and the output is verified. FLOWCHART: START READ THE INPUT SEQUENCE PLOT THE WAVEFORMS STOP READ THE CONSANT FOR (SCALAR) AMPLITUDE AND TIME MANIPULATION READ THE (VECTOR) SEQUENCE FOR SIGNAL ADDTION AND MULTIPLICATION PERFORM OPERTAION ON THE D.T. SIGNAL

AIM: Write a program in MATLAB to study the basic operations on the Discrete – time signals. (Operation on dependent variable (amplitude manipulation) and Operation on independent variable (time manipulation)). APPARATUS REQUIRED: Pentium 4 Processor, MATLAB software THEORY: Let x ( n ) be a sequence with finite length.

  1. Amplitude manipulation
    • Amplitude scaling: y [n] = ax [ n] , where a is a constant. If a > 1, then y[n] is amplified sequence If a < 1, then y[n] is attenuated sequence If a = - 1, then y[n] is amplitude reversal sequence Ex. No : Date :21-12- Ex. No :

Date :21-12-13 BASIC OPERATIONS ON D.T SIGNALS

BASIC OPERATIONS ON D.T SIGNALS

TIC, operation, TOC prints the number of seconds required for the operation. Fprintf Write formatted data to file. The special formats \n,\r,\t,\b,\f can be used to produce linefeed, carriage return, tab, backspace, and formfeed characters respectively. Use \ to produce a backslash character and %% to produce the percent character. ALGORITHM/PROCEDURE:

  1. Start the program
  2. Get the input for signal manipulation
  3. Use the appropriate library function
  4. Display the waveform Source code : clc; clear all; close all; %operations on the amplitude of signal x=input('Enter input sequence:'); a=input('Enter amplification factor:'); b=input('Enter attenuation factor:'); c=input('Enter amplitude reversal factor:'); y1=ax; y2=bx;

y3=c*x; n=length(x); subplot(2,2,1); stem(0:n-1,x); xlabel('time'); ylabel('amplitude'); title('Input signal'); subplot(2,2,2); stem(0:n-1,y1); xlabel('time'); ylabel('Amplitude'); title('Amplified signal'); subplot(2,2,3); stem(0:n-1,y2); xlabel('time'); ylabel('Amplitude'); title('Attenuated signal'); subplot(2,2,4); stem(0:n-1,y3); xlabel('time'); ylabel('Amplitude'); title('Amplitude reversal signal'); %scalar addition d=input('Input the scalar to be added:'); y4=d+x; figure(2); stem(0:n-1,y4); xlabel('time'); ylabel('Amplitude'); title('Scalar addition signal'); clc; clear all; close all; %Operations on the independent variable %Time shifting of the independent variable x=input('Enter the input sequence:'); n0=input('Enter the +ve shift:');

stem(0:l1-1,x1); xlabel('time'); ylabel('Amplitude'); title('Input sequence 1'); subplot(2,2,2); stem(0:l2-1,x2); xlabel('time'); ylabel('Amplitude'); title('Input sequence 2'); if l1>l l3=l1-l2; x2=[x2,zeros(1,l3)]; y1=x1+x2; subplot(2,2,3); stem(0:l1-1,y1); xlabel('time'); ylabel('Amplitude'); title('Addition of two signals'); y2=x1.x2; subplot(2,2,4); stem(0:l1-1,y2); xlabel('time'); ylabel('Amplitude'); title('Multiplication of two signals'); end if l2>l l3=l2-l1; x1=[x1,zeros(1,l3)]; y1=x1+x2; subplot(2,2,3); stem(0:l2-1,y1); xlabel('time'); ylabel('Amplitude'); title('Addition of two signals'); y2=x1.x2; subplot(2,2,4); stem(0:l2-1,y2); xlabel('time'); ylabel('Amplitude');

title('Multiplication of two signals'); else y1=x1+x2; subplot(2,2,3); stem(0:l1-1,y1); xlabel('time'); ylabel('Amplitude'); title('Addition of two signals'); y2=x1.*x2; subplot(2,2,4); stem(0:l1-1,y2); xlabel('time'); ylabel('Amplitude'); title('Multiplication of two signals'); end operations on the amplitude of signal : Time shifting of the independent variable :