MAT LAB Programs

*******************%Generation of Continuous Time Signals***************************
clc;
clear all;
close all;

%unit cosine wave
f=5;
t=0:0.001:1;
y=cos (2*pi*f*t);
subplot(3,2,5);
plot (t,y);
ylabel('amplitude');
xlabel('time');

%unit sine wave
f=5;
t=0:0.001:1;
y=sin (2*pi*f*t);
subplot(3,2,6);
plot (t,y);
ylabel('amplitude');
xlabel('time');

%unit impulse signal
N=input('enter the N value');
t=-2:1:2;
y=[zeros(1,2),ones(1,1),zeros(1,2)];
subplot(3,2,3);
plot(t,y);
ylabel('amplitude');
xlabel('time');

%unit ramp signal
N=input('Enter the N value');
t=0:N;
subplot (3,2,4);
plot(t,t);
ylabel('amplitude');
xlabel('time');

%unit step signal
N=input('Enter the N value');
t=0:1:N-1;
y=ones(1,N);
subplot (3,2,2);
plot(t,y);
ylabel('amplitude');
xlabel('time');

%unit exponential signal

N=input('length of a signal');
A=input('Enter the A value');
t=0:N;
y=exp(A*t);
subplot (3,2,1);
plot(t,y);
ylabel('amplitude');
xlabel('time');

***********************% program for linear convolution********************************* 
clc;
clear all;
close all;
x=input('enter the first sequence x(n)=');
h=input('enter the second sequence h(n)=');
n=length(x);
m=length(h);
x1=[x,zeros(1,m)];
h1=[h,zeros(1,n)];
N=n+m-1;
y=zeros(1,n);
for i=1:N   
    y(i)=0;
    for j=1:N
        if(j<i+1)
            y(i)=y(i)+x1(j)*h1(i-j+1);
        end
    end
end
disp('convolved sequence y(n)=');y
subplot(2,2,1);
stem(x);
xlabel('n');
ylabel('x(n)');
grid;
subplot(2,2,2);
stem(h);
xlabel('n');
ylabel('h(n)');
grid;
subplot(2,2,[3,4]);
stem(y);
xlabel('n');
ylabel('y(n)');
grid;
title('convolution of x(n) & h(n)');
v=conv(x,h);
% linear convolution using function
disp('linear convolution using function v(n)=');v
*********************************************************************************