20BEC1192 DSP 4
20BEC1192 DSP 4
Name: Ajeetha
Reg No.: 20BEC1192
Aim:
figure(1)
x = input("Enter the discrete time signal: ");
N = length(x);
Y = fft(x,N)
Yi = ifft(Y,N)
subplot(3,1,1)
stem(x)
xlabel("time")
ylabel("amplitude")
title("Input signal")
grid on
subplot(3,1,2)
D = abs(Y);
%magnitude
stem(D)
xlabel("frequency")
ylabel("amplitude")
title("DFT")
grid on
subplot(3,1,3)
stem(Yi)
xlabel("time")
ylabel("amplitude")
title("IDFT")
grid on
OUTPUT:
Task-2
Compute DFT and IDFT without using built in function
CODE:
figure(2)
xk = zeros(1,N);
ixk = zeros(1,N);
i = sqrt(-1);
for k=0:N-1
for n=0:N-1
xk(k+1) = xk(k+1)+ (x(n+1)*exp((-i)*2*pi*k*n/N));
end
end
t=0:N-1;
subplot(3,1,1)
stem(t,x)
xlabel("time")
ylabel("amplitude")
title("Input signal")
grid on
Mag = abs(xk);
t = 0:N-1;
subplot(3,1,2)
stem(t,Mag)
xlabel("frequency")
ylabel("amplitude")
title("DFT without built-in function")
grid on
for n=0:N-1
for k=0:N-1
ixk(n+1) = ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/N-1));
end
end
ixk = ixk./N;
t = 0:N-1;
subplot(3,1,3)
stem(t,ixk)
grid on
xlabel("time")
ylabel("amplitude")
title("IDFT withut built-in function")
Output:
Task-3
Compute DFT for sine function
Code:
figure(3)
a = input("Enter amplitude: ");
f = input("Enter frequency: ");
t = 0:0.01:1;
x = a*sin(2*pi*f*t);
X = fft(x);
y = abs(X);
subplot(2,1,1)
plot(t,x)
grid on
xlabel("time")
ylabel("amplitude")
title("Sine signal")
subplot(2,1,2)
plot(y)
grid on
xlabel("frequency")
ylabel("amplitude")
title("FT with mirror image")
Output:
Task-4
Compute DFT for addition of sine functions
Code:
figure(4)
a1 = input("Enter amplitude: ");
f1= input("Enter frequency: ");
t = 0:0.01:1;
x1= a1*sin(2*pi*f1*t)+a*sin(2*pi*f*t);
X1= fft(x1);
y1 = abs(X1);
subplot(2,1,1)
plot(t,x1)
grid on
xlabel("time")
ylabel("amplitude")
title("Sine signal")
subplot(2,1,2)
plot(y1)
xlim([0 50])
grid on
xlabel("frequency")
ylabel("amplitude")
title("FT without mirror image")
Output:
Verification:
Result:
Hence the DFT and IDFT for the given tasks are performed and
visualized through MATLAB.