In: Electrical Engineering
given the sequences
x1 = cos (0.5*pi*n) + cos (0.25*pi*n) + cos (0.125*pi*n); for n = 0
to 7;
x2 = sin (0.5*pi*n) - cos (o.25*pi*n) + sin (0.125*pi*n); for n = 0
to 7;
plot the sequences and comment on the results. increasing the
number of samples to n = 0 to 99, compute the DFT of the two
sequences in MATLAB and plot the magnitude and phase of the
computed DFTs. comment on the results
MATLAB CODE:
clc
clear all
close all
n = 0:7;
x1 = cos(0.5.*pi.*n)+cos(0.25.*pi.*n)+cos(0.125.*pi.*n);
x2 = sin(0.5.*pi.*n)-cos(0.25.*pi.*n)+sin(0.125.*pi.*n);
subplot(2,1,1)
stem(n,x1)
xlabel('n')
ylabel('x1')
title('x1')
subplot(2,1,2)
stem(n,x2)
xlabel('n')
ylabel('x2')
title('x2')
OUTPUT:
COMPUTING 'DFT' USING MATLAB:
clc
clear all
close all
n = 0:99;
x1 = cos(0.5.*pi.*n)+cos(0.25.*pi.*n)+cos(0.125.*pi.*n);
x2 = sin(0.5.*pi.*n)-cos(0.25.*pi.*n)+sin(0.125.*pi.*n);
y1 = fft(x1); % computing DFT of x1
y2 = fft(x2); % computing DFT of x1
%Magnitudes of y1 and y2
mag1 = sqrt(real(y1).^2+imag(y1).^2);
mag2 = sqrt(real(y2).^2+imag(y2).^2);
%Phases of y1 and y2
phase1 = atan(imag(y1)./real(y1));
phase2 = atan(imag(y2)./real(y2));
subplot(2,2,1)
stem(n,mag1)
xlabel('n')
ylabel('mag1')
title('Magnitude of y1')
subplot(2,2,2)
stem(n,phase1)
xlabel('n')
ylabel('phase1')
title('Phase of y1')
subplot(2,2,3)
stem(n,mag2)
xlabel('n')
ylabel('mag2')
title('Magnitude of y2')
subplot(2,2,4)
stem(n,phase2)
xlabel('n')
ylabel('phase2')
title('Phase of y2')
MAGNITUDE AND PHASE PLOTS: