%%% Signalverarbeitung
% Uebung 6 08.11.2016

clear all
clc
 
% Zeitabhängiges Signal
 t = [-5:0.01:5];

for i = 1:length(t)    % rect-Funktion
    if t(i) >= -0.1 && t(i) <=  0.1
        RECT(i) = 1;
    else
        RECT(i) = 0;
    end
end


% plot RECT
 figure(1)
 subplot(2,1,1)
 plot(t,RECT)
 grid on
 title('Rechteckpuls der Breite T = 0.2 s')
 ylim([-0.1,1.1])   % limits der y-Achse
 xlabel('t [s]')
 ylabel('f(t)')
 
% Frequenzspektrum
 FreqS = abs(fft(RECT));   %fft -> "Fast-Fourier-Transformation"
                           % abs = Betrag (OHNE BETRAG VERSUCHEN!)
 FreqS2 = fftshift(FreqS); % fftshift "schiebt" die Funktion in die Mitte
 
% plot fft(RECT)
 subplot(2,1,2)
 plot(t,FreqS2)    % ohne "t" komplettes "Wirrwarr" der Darstellung :)
 grid on
 title('Frequenzspektrum')
 
 
 
 