clear all
close all

%%%%%%%%%%%%%
% Parameters
%%%%%%%%%%%%
Fs = 128;   % Sampling frequency
N  = 128;   % Number of samples
tx = 0 : 1/Fs : (N-1)*1/Fs; % Time axis
fx = 0 : Fs/N : Fs/N*(N-1); % Frequency axis

%Idõtartománybeli jel
f =10;
x = cos(2*pi*f*tx + pi/2);%rand(1)*2*pi);

%f2 = 8;
%x2 = sin(2*pi*f2*tx + rand(1)*2*pi);

% Négyszögesites
%x = 10*x;
%x = min(x,1);
%x = max(x,-1);

s = x;
% s = abs(x);
% s = x2 + x;
% s = x2 .* x;
S = fft(s)/N; 

figure(1)
subplot(311)
    stem(tx,s)
    ylim([-3 3]); xlim([0 max(tx)])
    xlabel('Time'), ylabel('Amplitude')
    title('Time domain signal')
    grid on

subplot(325)
    stem(fx,angle(S)/pi*180,'markersize',2)
    xlabel('Frequency'), ylabel('Phase')
    title('Frequency domain signal (Phase)')
    ylim([-180 180]), xlim([0 Fs]);
    grid on
    hold on
    
    [value,index]=find(abs(S)>.1);
    stem(fx(index),angle(S(index))/pi*180,'k','markersize',6,'Linewidth',2)    
    
subplot(326)
    stem(fx-Fs/2,fftshift(angle(S)/pi*180),'markersize',4)
    xlabel('Frequency'), ylabel('Phase')
    title('Frequency domain signal (Phase)')
    ylim([-180 180]), xlim([-Fs/2 Fs/2]);
    grid on
    hold on
    
    y = fftshift(S);
    x = fx-Fs/2;
    [value,index]=find(abs(y)>.1);
    stem(x(index),angle(y(index))/pi*180,'k','markersize',6,'Linewidth',2)    
    ylim([-180 180]), xlim([-Fs/2 Fs/2]);

    
subplot(323)
    stem(fx,abs(S),'markersize',2)
    xlabel('Frequency'), ylabel('Amplitude')
    title('Frequency domain signal')
    ylim([0 1]), xlim([0 Fs]);
    grid on
    
    
subplot(324)
    stem(fx-Fs/2,fftshift(abs(S)),'markersize',2)
    xlabel('Frequency'), ylabel('Amplitude')
    title('Frequency domain signal')
    ylim([0 1]), xlim([-Fs/2 Fs/2]);
    grid on
    
shg



% figure(2)
% subplot(211)
%     stem(fx,real(S))
%     xlabel('time'), ylabel('amplitude')
%     title('real part of the frequency domain signal')
%     ylim([0 1]), xlim([0 Fs]);
%     
% subplot(212)
%     stem(fx,imag(S))
%     xlabel('time'), ylabel('amplitude')
%     title('imaginary part of the frequency domain signal')
%     ylim([0 1]), xlim([0 Fs]);