Week1MATLAB WEEK 2 Merged
Week1MATLAB WEEK 2 Merged
clc;
clear all;
close all;
t=0:.001:1;
f=input('Enter the value of frequency');
a=input('Enter the value of amplitude');
subplot(3,3,1);
y=a*sin(2*pi*f*t);
plot(t,y,'r');
xlabel('time');
ylabel('amplitude');
title('sine wave')
grid on;
subplot(3,3,2);
z=a*cos(2*pi*f*t);
plot(t,z);
xlabel('time');
ylabel('amplitude');
grid on;
subplot(3,3,3);
s=a*square(2*pi*f*t);
plot(t,s);
xlabel('time');
ylabel('amplitude');
title('square wave')
grid on;
subplot(3,3,4);
plot(t,t);
xlabel('time');
ylabel('amplitude');
grid on;
subplot(3,3,5);
plot(t,a,'r');
xlabel('time');
ylabel('amplitude');
grid on;
1
2
Week 1 - Q2
clc;
clear all;
close all;
n=0:1:50;
f=input('Enter the value of frequency');
a=input('Enter the value of amplitude');
N=input('Enter the length of unit step');
subplot(3,3,1);
y=a*sin(2*pi*f*n);
stem(n,y,'r');
xlabel('time');
ylabel('amplitude');
title('sine wave')
grid on;
subplot(3,3,2);
z=a*cos(2*pi*f*n);
stem(n,z);
xlabel('time');
ylabel('amplitude');
title('cosine wave')
grid on;
subplot(3,3,3);
s=a*square(2*pi*f*n);
stem(n,s);
xlabel('time');
ylabel('amplitude');
title('square wave')
grid on;
subplot(3,3,4);
stem(n,n);
xlabel('time');
ylabel('amplitude');
title('ramp wave')
grid on;
x=0:N-1;
d=ones(1,N);
subplot(3,3,5);
stem(x,d,'r');
xlabel('time');
ylabel('amplitude');
title('unit step wave')
grid on;
1
2
WEEK 2– Q1
clc;
clear all;
close all;
n = -5:1:5;
a= 2*(n+2==0)-(n-4==0);
stem(n,a);
OUTPUT
WEEK 2-Q2
>> A = zeros(1,5);
for n = 1:4
for m = 1:3
A = A + n*m;
end
end
disp(A)
OUTPUT
60 60 60 60 60
WEEK 2-Q3
clc;
clear all;
close all;
n=-2:1:22;
subplot(3,3,1);
f=1*(n>=0)-1*((n-4)>=0);
stem(n,f);
xlabel('time');
ylabel('amplitude');
title('fig1');
grid on;
subplot(3,3,2);
g=n.*(n>=0)-2*(n-4).*((n-4)>=0)+(n-8).*((n-8)>=0);
stem(n,g);
xlabel('time');
ylabel('amplitude');
title('fig2');
grid on;
subplot(3,3,3);
x=1*(n==0)-2*((n-4)==0);
stem(n,x);
xlabel('time');
ylabel('amplitude');
title('fig3');
grid on;
subplot(3,3,4);
y=0.9*n.*((n>=0)-((n-20)>=0));
stem(n,y);
xlabel('time');
ylabel('amplitude');
title('fig4');
grid on;
subplot(3,3,5);
v=cos(0.12*pi*n).*(n>=0)
stem(n,v);
xlabel('time');
ylabel('amplitude');
title('fig5');
grid on;
OUTPUT
WEEK 2-Q4
clc;
clear all;
close all;
n=-2:1:10;
f=(n>=0)-((n-4)>=0);
g=n.*(n>=0)-2*(n-4).*((n-4)>=0)+(n-8).*((n-8)>=0);
subplot(3,3,1);
w = conv(f,f);
w_n = n+n:1:length(w)+n+n-1;
stem(w_n,w);
xlabel('time');
ylabel('amplitude');
title('f(n)*f(n)');
grid on;
subplot(3,3,2);
x = conv(f,g);
x_n = n+n:1:length(x)+n+n-1;
stem(x_n,x);
xlabel('time');
ylabel('amplitude');
title('f(n)*g(n)');
grid on;
subplot(3,3,3);
y = conv(g,n==0);
y_n = n+n:1:length(y)+n+n-1;
stem(y_n,y);
xlabel('time');
ylabel('amplitude');
title('g(n)*δ(n)');
grid on;
subplot(3,3,4);
v = conv(g,g);
v_n = n+n:1:length(v)+n+n-1;
stem(v_n,v);
xlabel('time');
ylabel('amplitude');
title('g(n)*g(n)');
grid on;
subplot(3,3,5);
k = conv(f,f);
z= conv(f,k);
z_n = n+n:1:length(z)+n+n-1;
stem(z_n,z);
xlabel('time');
ylabel('amplitude');
title('f(n)*f(n)*f(n)');
grid on;
OUTPUT
WEEK 2-Q5
clc;
clear all;
close all;
n=-2:1:15;
k=1:1:11;
x=(n>=0)-((n-4)>=0);
h=ones(1,11);
subplot(3,3,1);
stem(k,h);
xlabel('time');
ylabel('amplitude');
title('h(n)');
grid on;
subplot(3,3,2);
stem(n,x);
xlabel('time');
ylabel('amplitude');
title('x(n)');
grid on;
subplot(3,3,3);
y = conv(x,h);
y_n = 1+n:1:length(y)+1+n-1;
stem(y_n,y);
xlabel('time');
ylabel('amplitude');
title('x(n)*h(n)');
grid on;
OUTPUT