%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ODD HARMONIC GENERATOR
% Author : Reza Ghassemi
% Date : 14 June 2005
% email : rghassemi@gmail.com
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function gives you a summation of N
% odd harmonics starting from the fundamental
% frequency.
% f0 is the fundamental
% Fs is the sampling rate
% length is the length of the vector
% N is the number of terms to be summed.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x=oddharmonic(f0,Fs,length,N)
t=1:length;
x=zeros(1,length);
for i=0:N-1
x=x+sin(2*pi*((2*i+1)*f0/Fs)*t);
end
subplot(211);
plot(t,x);
xlabel('time');
title('Time Domain');
Xf=abs(fft(x));
subplot(212);
f=linspace(-Fs/2,Fs/2,length);
stem(f,fftshift(Xf));
xlabel('Hertz');
title('Frequency Domain');
wavwrite(x,Fs,16,'odd_harmonics.wav');