0% found this document useful (0 votes)
16 views

Signals Computing Assignment 2 Deepan Final

Uploaded by

deepanryan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Signals Computing Assignment 2 Deepan Final

Uploaded by

deepanryan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Signal Processing Computing Assignment: 2

Music Synthesis with Fourier Series

Deepan N Balaji (23B3916)

25th October, 2024

Question 1 and 2
To synthesize a sinusoid of a given frequency and experiment with adding harmonics, we can break the
task into two parts:

1. Synthesizing a Sinusoid in the given frequency (F0 ))range of 100Hz - 400Hz

The mathematical expression for generating a sinusoidal waveform is:

x(t) = A · sin(2πf t + ϕ)

Where:
• A is the amplitude of the sinusoid (A1 = 1)
• f is the frequency in hertz (F0 = 200 Hz)
• t is time
• ϕ is the phase (Inital phase = 0)
This waveform can be created in Python by leveraging the NumPy library.

2. Transform the waveform by blending in harmonics


Harmonics, which are multiples of the fundamental frequency F0 , can be used to build complex wave-
forms. Varying their amplitudes and phases allows us to shape the waveform. The harmonic series can
be written as:

x(t) = A1 · sin(2π(F0 )t) + A2 · sin(2π(2F0 )t + ϕ2 ) + A3 · sin(2π(3F0 )t + ϕ3 ) + . . .


Where A1 , A2 , A3 , . . . are the amplitudes, and ϕ1 , ϕ2 , ϕ3 , . . . are the phases of each harmonic.

1
3. Main Features of the Code
• Sinusoid generation: The initial sinusoidal waveform is derived from numpy.sin().
• Harmonics: New harmonics with different parameters are incorporated.
• Graphing and Audio Playback: Using Matplotlib, waveforms are plotted, and audio is gen-
erated to assess changes in timbre
• Fourier Transform: The fft function from scipy.fftpack is used to compute the magnitude
spectrum.

Figure 1: The Code

2
Figure 2: Two harmonics

4. Observations
• Waveform: The inclusion of harmonics makes it more complex and enhances its timbre
• Magnitude Spectrum: The fundamental frequency F0 remains the same, with peaks appearing
at harmonics (e.g., 2F0 , 3F0 , . . .).

Experimenting with Timbre


By changing parameters, we can create waveforms to sound like various instruments. Adding more
harmonics makes the sound better, with stronger peaks in the magnitude spectrum.

Question 3
To generate a song from given notes and durations, the process can be broken down as follows:

Steps
1. Note Generation: For each note, generate a sinusoidal waveform of the specified frequency and
duration.
2. Concatenation: Combine all the notes to form the complete song.

3. Save as Audio file: Save the final waveform as a .wav file.

Figure 3: First Song - We Shall Overcome

3
Figure 4: Second Song - My Heart Will Go On

Key Components of the Code


• generate tone Function: This function creates a sinusoidal waveform for each note according to
its frequency and duration.

• Concatenation: The waveforms of each note are joined together to form a continuous piece of
music.
• Normalization: The resulting waveform is normalized to avoid clipping.

• Saving as .wav: The final waveform is saved in a 16-bit PCM .wav file format.

How It Works
• A sine wave is generated for each note based on its frequency and duration.

• The sine waves are combined in sequence to create the complete song.
• The final output is exported as a .wav file, making it playable on any media player.

Google Drive Link


https://drive.google.com/drive/folders/1Ch19kLuhlcHKI3tUqzC4Oc4nAEikA4TB?usp=sharing

You might also like