clear
close all
f=100;
fs=1000;
Ts=1/fs;
time=5.0; % freq, sampling interval, time
t=Ts:Ts:time; % define a time vector
w0=cos(2*pi*f*t); % define the sinusoid
w1=sin(2*pi*f*t);
w2=exp(j*(2*pi*f*t));
w3=exp(-j*(2*pi*f*t));
figure(1)
plot_spec(w0,fs)
figure(2)
plot_spec(w1,fs)
figure(3)
plot_spec(w2,fs)
figure(4)
plot_spec(w3,fs)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function plot_spec(data,fs)
N=length(data); % length of the signal x
Ts=1/fs;
t=Ts*(1:N); % define a time vector
%ssf=((-N+1)/2:N/2)/(Ts*N); % frequency vector
ssf=(-N/2:N/2-1)/(Ts*N); % frequency vector
fx=fft(data(1:N)); % do DFT/FFT
fxs=fftshift(fx); % shift it for plotting
data_db=10*log10(abs(fxs)); %10*log10? 20*log10?
plot(ssf,data_db) % plot magnitude spectrum
grid on
xlabel('frequency');
ylabel('magnitude') % label the axes