I'm reading "Digital Signal Processing", written by Michael Weeks. In section Representing a Digital Signal as a Sum of Sinusoids, there is this Matlab code that I cannot understand. (code given below)
What I don't get is what does the term inside cos argument 1/Xsize mean (in part %Do the sinusoids as discrete points only
, I guess it is fundamental frequency, but how can we conclude it). And why is the whole function divided by Xsize.
Same thing with smooth0, smooth1, smooth2... I also don't get this smoothing process.
Thank you for any explanations, or links to helpful stuff.
%sum_of_sins.m
%Show a random signal as a sum of sins
%
%Make our x signal
x=round(rand(1,8)*10);
Xsize=length(x);
%Get FFT of x
X=fft(x);
Xmag=abs(X);
Xphase=angle(X);
%Show the freq-domain info as sum of sinusoids
%Find the IFFT (the hard way) part 1
n=0:Xsize-1;
%Do the sinusoids as discrete points only
s0=Xmag(1)*cos(2*pi*0*n/Xsize+Xphase(1))/Xsize;
s1=Xmag(2)*cos(2*pi*1*n/Xsize+Xphase(2))/Xsize;
s2=Xmag(3)*cos(2*pi*2*n/Xsize+Xphase(3))/Xsize;
s3=Xmag(4)*cos(2*pi*3*n/Xsize+Xphase(4))/Xsize;
s4=Xmag(5)*cos(2*pi*4*n/Xsize+Xphase(5))/Xsize;
s5=Xmag(6)*cos(2*pi*5*n/Xsize+Xphase(6))/Xsize;
s6=Xmag(7)*cos(2*pi*6*n/Xsize+Xphase(7))/Xsize;
s7=Xmag(8)*cos(2*pi*7*n/Xsize+Xphase(8))/Xsize;
%Redo the sinusoids as smooth curves
t=0:0.05:Xsize-1;
smooth0=Xmag(1)*cos(2*pi*0*t/Xsize+Xphase(1))/Xsize;
smooth1=Xmag(2)*cos(2*pi*1*t/Xsize+Xphase(2))/Xsize;
smooth2=Xmag(3)*cos(2*pi*2*t/Xsize+Xphase(3))/Xsize;
smooth3=Xmag(4)*cos(2*pi*3*t/Xsize+Xphase(4))/Xsize;
smooth4=Xmag(5)*cos(2*pi*4*t/Xsize+Xphase(5))/Xsize;
smooth5=Xmag(6)*cos(2*pi*5*t/Xsize+Xphase(6))/Xsize;
smooth6=Xmag(7)*cos(2*pi*6*t/Xsize+Xphase(7))/Xsize;
smooth7=Xmag(8)*cos(2*pi*7*t/Xsize+Xphase(8))/Xsize;
%Find the IFFT (the hard way) part 2
my_sum_of_sins=s0+s1+s2+s3+s4+s5+s6+s7;
smooth_sum=smooth0+smooth1+smooth2+smooth3+smooth4+smooth5+smooth6+smooth7;
%Show both discrete points and smooth curves together
xaxis1=(0:length(smooth0)-1)/20; %for 8 points
xaxis2=(0:length(s0)-1);
figure(1);
subplot(4,1,1); plot(xaxis1, smooth0, 'g', xaxis2, s0,'r*');
subplot(4,1,2); plot(xaxis1, smooth1, 'g', xaxis2, s1,'r*');
subplot(4,1,3); plot(xaxis1, smooth2, 'g', xaxis2, s2,'r*');
subplot(4,1,4); plot(xaxis1, smooth3, 'g', xaxis2, s3,'r*');
figure(2);
subplot(4,1,1); plot(xaxis1, smooth4, 'g', xaxis2, s4, 'r*');
subplot(4,1,2); plot(xaxis1, smooth5, 'g', xaxis2, s5, 'r*');
subplot(4,1,3); plot(xaxis1, smooth6, 'g', xaxis2, s6, 'r*');
subplot(4,1,4); plot(xaxis1, smooth7, 'g', xaxis2, s7, 'r*');