Matlab Task: All All
Matlab Task: All All
t=-2:2;
y=zeros(1,5);
y(1,3)=1;
stem(t,y);
ylabel('Amplitude');
xlabel('Time Index');
Plot:
syms n
u(n)=heaviside(n);
N = 0.1;
x = u(n) - u(n-N);
ezplot(x);
grid on
Plot:
A=10;
f=50;
fs=600;
n=-pi:0.1:pi;
x= A*cos((2*pi*f*n)/fs);
plot(n,x);
ylabel('x(n)');
xlabel('time period');
grid on
Plot:
figure(1)
m = [-5:0.25:5];
x = 5*cos(pi*(m/2)-(pi/2));
stem(m,x);
ylabel('x(m)');
xlabel('time period');
grid on
figure(2)
p = [-5:0.25:5];
h = 10*cos(pi*(p/2));
stem(p,h);
ylabel('h(p)');
xlabel('time period');
grid on
figure(3)
n = [-5:0.25:5];
y=conv(x,h,'same')
stem(n,y);
ylabel('y(n)');
xlabel('time period');
grid on
Plots:
Q2. (a) Matlab code:
close all
clear
a = [1 0.8 0.64];
b = [0.866];
impulse = [1 zeros(1,99)];
h = filter(b,a,impulse);
stem([0:length(h)-1],h)
Plot:
(b) Matlab code:
close all
clear
n = 0:10
a = [1 0.8 0.64];
b = [0.866];
[s,x] = dstep(b,a,length(n));
stem(n,s)
title('Step response')
Plot:
(c) Matlab code:
close all
clear
a = [1 0.8 0.64];
b = [0.866];
impulse = [1 zeros(1,99)];
h = filter(b,a,impulse);
b = fir1(18,30/(100/2),'high',kaiser(19,4));
impz(b,h,[],100)
(d) Comparison of 2b and 2c
Similarities:
Step and Impulse responses are closely related, In discrete time the unit impulse is the
first difference of the unit step, and the unit step is the running sum of the unit impulse.
Differences:
The step response gives information about how the system responds to a signal which
will be there for a longer time the impulse response will say something about how the
system reacts when it gets a smack to start, how long will it go on.
Answer:
Plot:
(d) Matlab code:
clc
close all
clear all
Plot:
Answer: The result obtained using FFT and by using inbuilt command both are equal.
t= 0:0.01:0.1;
t1=0:1/1e8:period;
figure;
plot (t1,y)
title('x(t) plot')
xlabel('t')
ylabel('x(t)')
Plot:
(b) Answer : maximum frequency component of the signal x(t) from above
period is fm
clc
close all
clear all
t= 0:0.01:0.1;
t1=0:1/1e8:period;
plot (t1,y)
title('x(t) plot')
xlabel('t')
ylabel('x(t)')
fs=2*(1/period)
fsactual=(4*fs);
xn = cos(600*pi.*n)+cos(100*pi.*n);%sampled data
figure;
stem(n,xn)
title('x(n) plot')
xlabel('n')
ylabel('x(n)')
Plot:
t= 0:0.01:0.1;
t1=0:1/1e8:period;
figure;
plot (t1,y)
title('x(t) plot')
xlabel('t')
ylabel('x(t)')
fs=2*(1/period)
fsactual=(4*fs);
xn = cos(600*pi.*n)+cos(100*pi.*n);%sampled data
figure;
stem(n,xn)
title('x(n) plot')
xlabel('n')
ylabel('x(n)')
%d)
P2 = abs(z/L);
P1 = P2(1:(L/2)+1);
P1(2:end-1) = 2*P1(2:end-1);
f = fsactual*(0:(L/2))/L;%frequency vector
figure;
xlabel('f (Hz)')
ylabel('|xn(f)|')
Plot: