%Magnitude and Phase Spectrum
clc;clear;close all;
x=[1 1 1 1 1 1 0 0];
N=length(x);
y=zeros(1,N);
for k=0:N-1
y(x+1)=0;
for n=0:N-1
y(k+1)=y(k+1)+x(n+1)*exp(-1i*2*pi*n*k/N);
end
end
disp(y);
ymag=abs(y);
yph=phase(y);
n=0:N-1;
subplot(2,1,1)
stem(n,ymag);
title('Magnitude of X(k)');
xlabel('n');
ylabel('Magnitude');
subplot(2,1,2);
stem(n,yph);
title('Phase of X(k)');
xlabel('n');
ylabel('Phase');
%Frequency domain analysis for sinusoidal signals
clc;clear;close all;
f1=100;f2=250;f3=350;
l=1500;fs=1500;
t=(0:l-1)*1/fs;
x=sin(2*pi*f1*t)+sin(2*pi*f2*t)+sin(2*pi*f3*t);
plot(t,x);
title('Frequency Domain Signal');
xlabel('Frequency');
xlim([0,0.1]);
y=fft(x);
ymag=abs(y);
ymagh=ymag(1:l/2);
f=(1:l/2)*fs/l;
figure;
plot(f,ymagh);
title('Frequency Domain Signal');
xlabel('Frequency');