DSP LAB - Report
DSP LAB - Report
DSP LAB - Report
Lab-4
Digital Signal Processing
Task 1:
CODE:
function [reX,imX] = myDFT(X)
N = size(X,2);
reX = zeros(1,N/2+1);
imX = zeros(1,N/2+1);
for k = 1:N/2+1
for i = 1:N
reX(k) = reX(k) + X(i)*cos(2*pi*(k-1)*(i-1)/N);
imX(k) = imX(k) + X(i)*sin(2*pi*(k-1)*(i-1)/N);
end
end
end
N = (size(reX,2)-1)*2;
X = zeros(1,N);
imX = imX.*(-1);
reX = reX./(N/2);
imX = imX./(N/2);
reX(1) = reX(1)/2;
reX(N/2+1)= reX(N/2+1)/2;
for i = 1:N
for k = 1:N/2+1
X(i) = X(i) + reX(k)*cos(2*pi*(k-1)*(i-1)/N);
X(i) = X(i) + imX(k)*sin(2*pi*(k-1)*(i-1)/N);
end
end
end
Task 2:
CODE:
X = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
[reX, imX] = myDFT(X);
Xrecons = myIDFT(reX, imX);
Task 1:
Implementing Convolution via Frequency Domain.
CODE:
n = 1:32;
h = 32;
X = sin(n);
Y = cos(n);
Z = conv(X,Y);
[reZ,imZ,ZusingFreqDom] = convFreqDomain(X,Y);
MagZ = MagX.*MagY;
PhaZ = PhaX + PhaY;
reZ = MagZ.*cos(PhaZ);
imZ = MagZ.*sin(PhaZ);
Z = myIDFT(reZ,imZ);
end
Fig : convolution via frequency domain. Error due to cyclic convolution.
Task 2:
Spectral Analysis of a given signal.
CODE:
[X,fs] = audioread('tuning_fork_A4.wav');
X = X(1:8192*4);
X= X';
[reX, imX] = myDFT(X);
MagX = (reX.^2 + imX.^2).^(1/2);
PhaX = atan2(imX,reX);
stem(MagX); title('MagX');xticks(0:500:2000);
This outputs a signal with spike at 512 Hz. Which means, the frequency
of the tuning fork was 512 Hz.
Fig : spectral analysis of tuning_fork.wav
_________________X__________________