MATLAB Code
clc;
clear;
close all;
% Parameters
fs = 100; % Sampling frequency
t = 0:1/fs:1-1/fs; % Time vector
% Signal definition
x = cos(2*pi*15*t - pi/4) - sin(2*pi*40*t);
% Compute Fourier Transform
y = fft(x);
z = fftshift(y);
% Frequency vector
ly = length(y);
f = (-ly/2:ly/2-1)/ly*fs;
% Compute phase
phase = angle(z);
% Plot magnitude of the Fourier Transform
figure;
subplot(2, 1, 1);
stem(f, abs(z), 'b');
xlabel('Frequency (Hz)');
ylabel('|y|');
title('Magnitude of Fourier Transform');
grid on;
% Plot phase of the Fourier Transform
subplot(2, 1, 2);
stem(f, phase, 'b');
xlabel('Frequency (Hz)');
ylabel('Phase (radians)');
title('Phase of Fourier Transform');
grid on;