34 lines
415 B
Matlab
34 lines
415 B
Matlab
clear; close all; clc;
|
|
|
|
N = 128;
|
|
n = 0:N-1;
|
|
w1 = 2*pi*0.1;
|
|
w2 = 2*pi*0.15;
|
|
x = cos(w1*n) + cos(w2*n);
|
|
|
|
% a)
|
|
|
|
X = fft(x);
|
|
magX = abs(X);
|
|
|
|
figure;
|
|
stem(n, magX, 'filled');
|
|
xlabel('n');
|
|
ylabel('|X[n]|');
|
|
title('Magnitude Spectrum of x[n]');
|
|
grid on;
|
|
|
|
% b)
|
|
|
|
y = hamming(N)' .* x;
|
|
|
|
Y = fft(y);
|
|
magY = abs(Y);
|
|
|
|
figure;
|
|
stem(n, magY, 'filled');
|
|
xlabel('n');
|
|
ylabel('|Y[n]|');
|
|
title('Magnitude Spectrum of y[n]');
|
|
grid on;
|