0% found this document useful (0 votes)
3 views5 pages

Project DSP

The document presents a series of MATLAB scripts that compute the Discrete Fourier Transform (DFT) of various signals using both built-in functions and manual calculations. Each problem includes the generation of a signal, its DFT computation, and the visualization of the original signal, magnitude spectrum, and phase spectrum using subplots. The scripts explore different signal configurations, including prime numbers and specific patterns in the signal values.

Uploaded by

shakibtuhin8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Project DSP

The document presents a series of MATLAB scripts that compute the Discrete Fourier Transform (DFT) of various signals using both built-in functions and manual calculations. Each problem includes the generation of a signal, its DFT computation, and the visualization of the original signal, magnitude spectrum, and phase spectrum using subplots. The scripts explore different signal configurations, including prime numbers and specific patterns in the signal values.

Uploaded by

shakibtuhin8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Source Code :

Problem ! :

clc;
clear all;
close all;

N = 16;
xn = [1 1 0];
xk = fft(xn, N);

disp('N point of DFT of x(n) is = ');


disp(xk);

subplot(2,2,1);
n = 0:length(xn)-1;
stem(n, xn);
xlabel('n');
ylabel('x(n)');
title('Original Signal');

k = 0:N-1;
subplot(2,2,2);
stem(k, abs(xk));
xlabel('k');
ylabel('|X(k)|');
title('Magnitude Spectrum');

subplot(2,2,3);
stem(k, angle(xk));
xlabel('k');
ylabel('?X(k)');
title('Phase Spectrum');

Output :

Fig : DFT Signal 16


Problem 2 :

clc;
clear all;
close all;

N = 16;
i = sqrt(-1);

xn = [1 1 0 1 1 1 1 1 0 1 0 0 1 0 1 1];
%xk = fft(xn, N);
xk = zeros(1,N);
for k =0:1:N-1;
for n=0:1:N-1;
xk(k+1)=xk(k+1)+xn(n+1)*exp(-i*2*pi*k*n/N);
end
end

disp('N point of DFT of x(n) is = ');


disp(xk);

subplot(2,2,1);
n = 0:length(xn)-1;
stem(n, xn);
xlabel('n');
ylabel('x(n)');
title('Original Signal');

k = 0:N-1;
subplot(2,2,2);
stem(k, abs(xk));
xlabel('k');
ylabel('|X(k)|');
title('Magnitude Spectrum');

subplot(2,2,3);
stem(k, angle(xk));
xlabel('k');
ylabel('?X(k)');
title('Phase Spectrum');
Output :

Fig : DFT without using function

Problem 3 :

clc;
clear all;
close all;

N = 3;
xn = [1 1 0];
xk = fft(xn, N);

disp('N point of DFT of x(n) is = ');


disp(xk);

subplot(2,2,1);
n = 0:length(xn)-1;
stem(n, xn);
xlabel('n');
ylabel('x(n)');
title('Original Signal');

k = 0:N-1;
subplot(2,2,2);
stem(k, abs(xk));
xlabel('k');
ylabel('|X(k)|');
title('Magnitude Spectrum');

subplot(2,2,3);
stem(k, angle(xk));
xlabel('k');
ylabel('?X(k)');
title('Phase Spectrum');
Output :

Fig : DFT Signal 3

Problem 4 :

lc;
clear all;
close all;

N = 16;
xn = zeros(1, N);

for n = 0:N-1
if isprime(n)
xn(n+1)=3;
elseif mod(n,3)==0
xn(n+1)=1;
elseif mod(n,2)==0
xn(n+1)=2;
else
xn(n+1)=0;
end
end

xk = fft(xn, N);

disp('N point DFT of x(n) is = ');


disp(xk);

subplot(2,2,1);
n = 0:length(xn)-1;
stem(n, xn);
xlabel('n');
ylabel('x(n)');
title('Original Signal');

k = 0:N-1;
subplot(2,2,2);
stem(k, abs(xk));
xlabel('k');
ylabel('|X(k)|');
title('Magnitude Spectrum');

subplot(2,2,3);
stem(k, angle(xk));
xlabel('k');
ylabel('?X(k)');
title('Phase Spectrum');

Output :

Fig : DFT Prime numbers, divided by 2, 3

You might also like