# Matlab code for FFT book

Data files for Chapters 8-9

Root-raised-cosine shaped data

Nonlinear device output signal

Intuitive Guide to Fourier Analysis and Spectral Estimation
Matlab code for key figures and examples is given here.

If you find any issues with these programs, please email me.
Last edited 11/24/2017

Matlab files from the book are included here.

% Chapter 1

%% Figure 1.8 - Summation of sines and cosine waves

clf
time = -2 : .0001: 2;
freq1 = 2*pi*1;
freq2 = 2*pi*2;
freq3 = 2*pi*3;

sine1 = sin(freq1*time);
sine2 = sin(freq2*time);
sine3 = sin(freq3*time);
sine4 =  sine1 + sine2 + sine3;

cosine1 = cos(freq1*time);
cosine2 = cos(freq2*time);
cosine3 = cos(freq3*time);
cosine4 = cosine1 + cosine2 + cosine3;

figure(1)
subplot(321)
plot(time, sine1)
title('Sine wave of freq = 1 Hz')
axis([ -1 1 -3 3])
grid on

subplot(323)
plot(time, sine2)
title('Sine wave of freq = 2 Hz')
axis([ -1 1 -2 2])
grid on

subplot(325)
plot(time, sine3)
title('Sine wave of freq = 3 Hz')
axis([ -1 1 -2 2])
grid on

subplot(322)
plot(time, cosine1)
title('Cosine wave of freq = 1 Hz')
axis([ -1 1 -2 2])
grid on
subplot(324)
plot(time, cosine2)
title('Cosine wave of freq = 2 Hz')
axis([ -1 1 -2 2])
grid on
subplot(326)
plot(time, cosine3)
title('Cosine wave of freq = 3 Hz')
axis([ -1 1 -2 2])
grid on

figure(2)
subplot(311)
plot(time, sine4)
title('Sum of 3 Cosine waves')
axis([ -2 2 -3 4])
grid on
subplot(312)

plot(time, cosine4)
title('Sum of 3 Sine waves')
axis([ -2 2 -3 4])
grid on

subplot(313)

plot(time, cosine4+sine4)
title('Sum of both sine and cosines')
axis([ -2 2 -5 5])
grid on

%%
% Figure 1.10 – Sum of large number of sines and cosines together

N = 20; %number of sines or cosines to be summed
time = -2:.0001: 2;
sine_sum = 0;
cosine_sum = 0;

for n = 1:1: N
cosine_sum = cosine_sum + cos(2*pi*n*time)
end

subplot(311)
plot(time, (cosine_sum))
grid on
axis([ -2 2 -N/2 N*1.5])

title('(a) Sum of 20 harmonic cosine waves')
for n = 0:1: N;
sine_sum = sine_sum + sin(2*pi*n*time);
end

subplot(312)
plot(time, sine_sum)
grid on
axis([ -2 2 -N N])

title('(b) Sum of 20 harmonic sine waves')

subplot(313)
plot(time, (abs(cosine_sum))- (abs(sine_sum)))
grid on
axis([ -2 2 -20 N*1.5])

### 2 Comments on “Matlab code for FFT book”

1. Sven E Widmalm says:

You wrote: Posted on November 7, 2016 by Charan L. — No Comments ↓
Intuitive Guide to Fourier Analysis and Spectral Estimation
Matlab code for selected figures and examples is given here.
If you find any issues with these programs, please email me.
Last edited 11/24/2017
Matlab files from the book are included here.
Signal data required for some of these scripts will be uploaded soon.

What is your definition of “soon”?
Sven

• Charan L. says:

I guess soon means today!