R.G.SHARATH KUMAR 412519106120 R.G.SHARATH KUMAR 412519106120 FLOWCHART: R.G.SHARATH KUMAR 412519106120 AIM: T o w r ite a pr o gr a m to g e n e r a te d i f fer e nt w a v e forms using M A T L A B ALGORITHM : 1. Clear command window. 2. Get the choice from user to select the waveform to be generated. 3. Use switch case to execute the code for different waveforms. 4. Generate i. Unit impulse: Iterate n from - 20 to 20. Generate output=1 when n = 0. ii. Unit step:Iterate n from - 20 to 20. Generate output=1 when n >= 0. iii. Ramp:Iterate n from - 20 to 20. Generate output=n when n >= 0. iv. Exponential: Iterate n from - 20 to 20. Generate output=exp(n) when n >= 0. v. Sine:Iterate n from 0 to 4*pi. Generate output = sin(n) vi. Cosine:Iterate n from 0 to 4*pi. Generate output = cos(n) vii. Triangular:Iterate n from 0 to 20 in steps of 0.2.Generate output=sawtooth(n,0.5) viii. Sawtooth:Iterate n from 0 to 20 in steps of 0.2. Generate output=sawtooth(n,1) Plot the signal. Get the input from user if another waveform needs to be generated. If yes, jump to Step 4, else terminate the program. PROGRAM: clc close all clear all disp( "Program for Waveform Generator" ) opt = 1; while (opt==1) disp( 'Which waveform do you want to generate?' ); disp( '1.Impulse,2.Step,3.Ramp,4.Exponential,5.Sine,6.Cosine,7.Triangle,8.Sawtooth' ); k=input( 'ENTER YOUR CHOICE:' ); switch k case 1 % I M P U L SE W A VEF O R M Ex. No.1 Date: 11/08/2021 GE N E R A TION OF W A V E F O RM S R.G.SHARATH KUMAR 412519106120 R.G.SHARATH KUMAR 412519106120 n = [ - 20:1:20]; for k=1:1:length(n) if (n(k)==0) x(k)=1; else x(k)=0; end end disp(x); stem(n,x, "LineWidth" ,2); xlabel( 'n -- >' ); ylabel( 'amplitude' ); title( 'UNIT IMPULSE SIGNAL ( R.G.SHARATH KUMAR - 412519106120 )' ); case 2 % S T E P W A VEFO R M n = [ - 20:1:20]; for k=1:1:length(n) if (n(k)>=0) x(k)=1; else x(k)=0; end end disp(x); stem(n,x, "LineWidth" ,2); xlabel( 'n -- >' ); ylabel( 'amplitude' ); title( 'UNIT STEP SIGNAL ( R.G.SHARATH KUMAR - 412519106120 )' ); case 3 % R A MP W A VEF O R M n = [ - 20:1:20]; for k=1:1:length(n) if (n(k)>=0) x(k)=n(k); else x(k)=0; end end disp(x); stem( n,x, "LineWidth" ,2); xlabel( 'n -- >' ); ylabel( 'amplitude' ); title( 'UNIT RAMP SIGNAL ( R.G.SHARATH KUMAR - 412519106120 )' ); case 4 %EX P ONE N T I A L W A V EFO R M n = [ - 20:1:20]; for k=1:1:length(n) if (n(k)>=0) x(k)=exp(n(k)); else x(k)=0; end end disp(x); plot( n,x, "LineWidth" ,2); xlabel( 'n -- >' ); R.G.SHARATH KUMAR 412519106120 OUT P UT W A VE F O R M S : R.G.SHARATH KUMAR 412519106120 ylabel( 'amplitude' ); title( 'EXPONENTIAL SIGNAL ( R.G.SHARATH KUMAR - 412519106120 )' ); case 5 % S INE W A VEF O R M n = [0:(pi/32):( 4*pi)]; x = sin(n); disp(x); stem(n,x, "LineWidth" ,2); xlabel( 'n -- >' ); ylabel( 'amplitude' ); title( 'SINE SIGNAL ( R.G.SHARATH KUMAR - 412519106120 )' ); case 6 % C OSINE W A V E FO R M n = [0:(pi/32):(4*pi)]; x = cos(n); disp(x); stem(n,x, "LineWidth" ,2); xlabel( 'n -- >' ); ylabel( 'amplitude' ); title( 'COSINE SIGNAL ( R.G.SHARATH KUMAR - 412519106120 )' ); case 7 % T R I A NG U LAR W A V EFO R M n = [0:0.2:20]; x=sawtooth(n,0.5); disp(x); stem(n,x, "LineWidth" ,2); xlabel( 'n -- >' ); ylabel( 'amplitude' ); title( 'TRIANGULAR SIGNAL ( R.G.SHARATH KUMAR - 412519106120 )' ); case 8 % S A W T OO T H W A VE F O R M n = [0:0.2:20]; x=sawtooth(n,1); disp(x); stem(n,x, "LineWidth" ,2); xlabel( 'n -- >' ); ylabel( 'amplitude' ); title( 'SAWTOOTH SIGNAL ( R.G.SHARATH KUMAR - 412519106120 )' ); otherwise d i s p( ' IN V A L ID C HO I C E ' ); end disp( 'Do you want to continue?' ); opt=input( 'If YES,press 1:' ); end R.G.SHARATH KUMAR 412519106120 R.G.SHARATH KUMAR 412519106120 R.G.SHARATH KUMAR 412519106120 R.G.SHARATH KUMAR 412519106120 R.G.SHARATH KUMAR 412519106120 R.G.SHARATH KUMAR 412519106120 RESULT: Thus a M A T L A B pr o g ra m is w r itten to g e n e r a te d i f f e r e nt w a v e fo r ms. R.G.SHARATH KUMAR 412519106120 FLOWCHART: R.G.SHARATH KUMAR 412519106120 AIM: To compute linear convolution of two sequences using in - built function in M A T L A B ALGORITHM: 1. Clear command window. 2. Get the input sequence x(n). 3. Get the impulse response h(n). 4. Compute the linear convolution using conv(x,h) command. 5. Display the output. 6. Plot the input sequence, impulse response and output sequence in a single window. PROGRAM: clc; clear all ; close all ; x1=input( 'Enter the first sequence x1(n) = ' ); x2=input( 'Enter the second sequence x2(n) = ' ); L=length(x1); M=length(x2); N=L+M - 1; yn =conv(x1,x2); %Linear Convolution %yn = cconv(x1,x2); %Circular Convolution disp( 'The values of yn are=' ); disp(yn); n1=0:L - 1; subplot(3,1,1); stem(n1,x1, 'lineWidth' ,2); grid on ; xlabel( 'n1 --- >' ); ylabel( 'amplitude --- >' ); title( 'First sequence' ); subplot(3,1,2); stem(n1,x2, 'lineWidth' ,2); grid on ; n1 = 0:M - 1; xlabel( 'n2 --- >' ); ylabel( 'amplitude --- >' ); title( 'Second sequence' ); subplot(3,1,3); n1 = 0:N - 1; stem(n1,yn, 'lineWidth' ,2); grid on ; xlabel( 'n3 --- >' ); ylabel( 'amplitude --- >' ); title( 'Convoluted Output' ); title( "Linear Convolution ( R.G.SHARATH KUMAR - 412519106120 ) " ); Ex. No.2a Date: 12/08/2021 LINEAR CONVOLUTION OF A SEQUENCE R.G.SHARATH KUMAR 412519106120 OUTPUT: Enter the input sequence :[2 4 6 8] Enter the impulse response of the system :[1 3 5 7] The linear convolution output is : 2 10 28 60 82 82 56 R.G.SHARATH KUMAR 412519106120 RESULT: Thus the Program to compute Linear Convolution using inbuilt function has been executed su cce ssful l y usi n g M A T L A B a nd t h e outputs w e r e v e ri f ied. R.G.SHARATH KUMAR 412519106120 FLOWCHART: R.G.SHARATH KUMAR 412519106120 AIM: T o c ompute the c i r c ular c onvolution of two s e qu e n ce s using i n - built fun c tion in M A T L A B ALGORITHM: 1. Clear command window. 2. Get the two sequences x(n) and h(n) from user. 3. Calculate the length of sequences len_x, len_h and find the maximum value. 4. Perform the circular convolution using ‘cconv’ function by specifying output length as maximum length of x and h. 5. Display the output. 6. Plot the two input sequences and the output sequence. PROGRAM: %Program to perform circular convolution using inbuilt command clc clear all close all disp( 'This is the program to perform circular convolution using inbuilt' ); disp( 'command' ); fprintf( ' \ n' ); %Getting the input and impulse response from user x = input( 'Enter the first sequence :' ); h = input( 'Enter the second sequence :' ); %To perform circular convolution, x and h should be of same size. %Find the length of x and length of h. Find the maximum value. len_x = length(x); len_h = length(h); len_y = max(len_x,len_h); %Use cconv() command for circular convolution. Specify the output %length as the maximum value.Display the output y = cconv(x,h,len_y); disp( 'The circular convolution output is :' ); disp(y); %Plotting the first sequence, second sequence and output figure(1); subplot(3,1,1); %We need to plot the values from n = 0 till length - 1. ax = 0:1:length(x) - 1; stem(ax,x); xlabel( 'samples n - >' ); ylabel( 'amplitude' ); title( 'first input sequence x(n)' ); subplot(3,1,2); ah = 0:1:length(h) - 1; stem(ah,h); xlabel( 'samples n - >' ); ylabel( 'amplitude' ); title( 'second input sequence h(n)' ); subplot(3,1,3); ay = 0:1:length(y) - 1; Ex. No.2b Date: 12/08/2021 CIRCULAR CONVOLUTION U SI N G I N - B U I L T FUNC TION R.G.SHARATH KUMAR 412519106120 OUTPUT: