In: Electrical Engineering
Use MATLAB to find the 8 point DFT of x(n) = cos(2πmn/8) (m=3) for 0 ≤ n ≤ 7.
Plot both x(n) and its DFT and explain your results. The "dct" and "fft" functions in MATLAB may be useful. Please post MATLAB code.
The matlab code is attached below. It is well commented and self explanatory. Following it are the screen shots of code for readability and resultant plots.
% Code starts from here
clc % Clear the command window
close all % Close any open window
n = 0:1:7; % Create index vector for n [0,7]
m = 3; % defining variable m
x = cos(2*pi*m.*n./8); % defining the signal x(n)
figure % creating a new figure
plot(n,x,'r','Linewidth',2); % plotting x[n] against n
grid on; % Turning on the grid
xlabel('Index n-->'); % labelling X axis
ylabel('Amplitude-->'); % labelling Y axis
X = fft(x); % FFT of the signal x[n]
X_mag = abs(X); % Finding the magnitude spectrum of x
figure % creating a new figure
plot(n,X_mag,'r','Linewidth',2); % plotting X against n
grid on; % Turning on the grid
xlabel('Digital frequency bin n-->'); % labelling X axis
ylabel('Magnitude-->'); % labelling Y axis
% Code ends here
Outputs
We see that there are two peaks one at n = 3 which corresponds to m = 3 and its aliased image at n = 5.