




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































START ENTER THE SIGNAL PARAMETERS (AMPLITUDE, TIME AND FREQUENCY) Generate the waveform by using the appropriate library function PLOT THE WAVEFORMS STOP
Write a program in MATLAB to generate the following waveforms (Discrete ā Time signal and Continuous ā Time signal)
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);
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.
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:
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 :