Professional Documents
Culture Documents
Program:
t = 1:1.5:20;
x = 2*sin(t);
subplot (3,1,1)
stem(t,x)
xlabel("Time Period")
ylabel("Amplitude")
title ("Original Signal")
subplot (3,1,2)
stem (t-5, x)
xlabel("Time Period")
ylabel("Amplitude")
title ("Signal Shifted Left")
subplot (3,1,3)
stem (t+5, x)
xlabel("Time Period")
ylabel("Amplitude")
title ("Signal Shifted Right")
Output:
∫u(t)=∫1=t=r(t)∫u(t)=∫1=t=r(t)
u(t)=dr(t)dtu(t)=dr(t)dt
Area under the unit ramp is unity.
Program-
t=-2:1:2;
y= [zeros (1,2), ones (1,1), zeros (1,2)];
subplot (2,2,1);
stem(t,y);
ylabel("d(n)");
xlabel("unit impulse");
n=input ("Enter n values");
t=0:1: n-1;
y1=ones (1, n);
subplot (2,2,2);
stem(t, y1);
ylabel("Amplitude");
xlabel("unit step");
Output-
Program-
clc;
clear all;
close all;
x1 = input("Enter First sequence x1(n)[] : ");
t1 = input("Enter Origin location Of Sequence x1 : ");
x2 = input("Enter Second sequence x2(n)[] : ");
t2 = input("Enter Origin location Of Sequence x2 : ");
l1 = length(x1); %length of sequence x1
l2 = length(x2); %length of sequence x2
ln = l1+l2-1; %length of convoluted sequence
y = conv(x1,x2); % performing convolution using conv() function
a = t1+l1-1;
t = t1:a;
subplot(3,1,1);
stem(t,x1);
xlabel("Time");
ylabel("Amplitude");
title("x1");
a = t2+l2-1;
t = t2:a;
subplot (3,1,2);
stem (t, x2);
xlabel("Time");
ylabel("Amplitude");
title('x2');
tn = t1+t2;
a = tn+ln-1;
t = tn:a;
subplot (3,1,3);
disp("Convoluted Sequence ");
disp(y); % For printing the convoluted output in MATLAB
command window
stem(t,y); % For plotting the convoluted output in MATLAB graph
window
xlabel('Time');
ylabel("Amplitude");
title ("Convoluted Sequence");
Output-
Program-
clc;
g=input("Enter the sequence 1:");
h=input("Enter the sequence 2:");
N1=length(g);
N2=length(h);
N=max(N1,N2);
N3=N1-N2;
if(N3>0)
h=[h,zeros(1,N3)];
else
g=[g,zeros(1,-N3)];
end
for n=1:N;
y(n)=0;
for i=1:N;
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=[y(n)+(g(i)*h(j))];
end
end
disp("The resultant is");y
subplot(2,1,1);
stem(y);
xlabel("N->");
ylabel("Amplititude->");
Output-
Program-
clear;
clc;
close all;
Fs = 100e6;
R1 = 2500;
R2 = 50;
C = 30*1e-12;
H = [];
for i = 1:100
f = -Fs/2+(Fs/100)*i; %f=-Fs/2:Fs/128:Fs/2
x(i) = f;
H(i) = R2/(R1/(1+(2*pi*f*C*R1*j)+R2));
end
Habs=abs(H);
plot(x,Habs);
y=abs(ifft((H)));
Output-
Program-
clc;
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit step sequence
s = [zeros(1,10) ones(1,21)];
% Plot the unit step sequence
stem(n,s);
xlabel("Time index n");
ylabel("Amplitude");
title("Unit Step Sequence");
axis([-10 20 0 1.2]);
Output-
Program-
1) Lowpass Butterworth Filter
fc = 300;
fs = 1000;
[b,a] = butter(6,fc/(fs/2));
freqz(b,a)
dataIn = randn(1000,1);
dataOut = filter(b,a,dataIn);
2) Bandstop Butterworth Filter
[b,a] = butter(3,[0.2 0.6],'stop');
freqz(b,a)
dataIn = randn(1000,1);
dataOut = filter(b,a,dataIn);