
clear all
close all
clc

fs = 30000;  %sampling frequency
N = 1000; %number of samples
t = 0:N-1;  %create a time vector which samples our input
t = t/fs;  %sample at the correct rate

f = ((0:N-1)/N)

% fsecond = 300000;
% tsecond = 0:100000;  %create a time vector which samples our input
% tsecond = tsecond/fsecond;  %sample at the correct rate

figure
for(freq = 10000: 1000:30000)
     
    y = cos(2*pi*freq*t);
    
%     y2 = cos(2*pi*freq*tsecond);
    
    subplot(2,1,1);
    stem(t(1:20),y(1:20));
    str = sprintf('The sampling frequency is %d frequency is %d', fs, freq);
    title(str); 
    axis([0, t(25), -2, 2]);
%     hold on
%     plot(t(1:20),y2(1:20));
    
    
    subplot(2,1,2);
    fftOut = fft(y);
    stem(f*fs, 20*log10(fftOut));
    str = sprintf('The frequency is %d', freq);
    title(str); 
    axis

    pause()
%     hold off
end