You are on page 1of 2

In this lab, students will write a program that analyzes the sound signal and determine its

dominant frequency. The input data is obtained from a musical note generator from the
previous lab. Similar to the MATLAB spectral analysis, the program will apply the Fast
Fourier Transform to output complex numbers. Then compute the magnitude for each
data point and keep track of the location of the maximum value. The index value will
help the program calculate the dominant frequency using the given formula.

Analysis
The first function that I created for the program is dominantFre(). It takes the index,
sampleRate and blockSize as the arguments. The function returns the frequency by
performing the calculation of the given formula in the lab instruction. dominantFre() is a
not required to declare as a separate function. However, I think the code become easier to
read and edit later.
The program takes two single input values: sample rate and block size. These values are
entered directly through the command line arguments. The form is shown below
./spectral s SAMPLERATE n BLOCKSIZE
Because we assume that the user always enter a correct format command line, we can
assign the certain index for the argv[] array. We ignored the first, second, and third
argument. By using the index of 2 and 4, the program can obtain the string of sample rate
and block size.
The spectral program primarily takes the input data from the musical note generator. The
note generator produces the amplitudes of signal. Since the data is very long and being
formatted in the CSV, we need to create a for loop that keep scanning the data until the
last line of the signal.
The goal of the program is finding the index of the maximum magnitude of the discrete
Fourier transform. To meet this requirement, we need to use the Fastest Transform in the
West library. The library provides the ability to compute the Fourier transform in the
complex numbers.
There will be two arrays created in the program to store the signal, one is being used to
store the amplitude from the musical note generator, and the other array stores the
computed complex data. The output is not very helpful until we calculate the magnitude
of each data point. This task can be done easily by using the magnitude formula.
V tomto cvien budou studenti pst program, kter analyzuje zvukov signl a urit jej
dominantn frekvenci. Vstupn data jsou zskna z hudebn poznmka genertoru z
pedchozho laboratoe. Podobn jako MATLAB spektrln analzy, program pouije pro
rychlou Fourierovu transformaci na vstupn komplexnch sel. Pak vypot velikost

pro kad datov bod a sledovat umstn na maximln hodnotu.Hodnota indexu pome
program spot, dominantn frekvenci pomoc danho vzorce.
analza
Prvn funkce, kter jsem vytvoil pro tento program je dominantFre (). Bere index,
vzorkovac a velikost bloku, jako argument.Funkce vrac frekvenci provdn vpotu
danho vzorce v laboratoi vuky. dominantFre () se nemus deklarovat jako samostatn
funkce. Myslm si vak, kd snadnji st a pozdji upravit.
Program m dv samostatn vstupn hodnoty: vzorkovac kmitoet a velikost bloku. Tyto
hodnoty se zadvaj pmo pes argumenty pkazovho dku.Formul je uvedeno ne
./spectral s vzorkovac n BLOCKSIZE
Vzhledem k tomu, pedpokldme, e uivatel vdy zadat pkaz sprvn formt dku,
meme piadit urit index pro argv [] pole. My ignoroval prvn, druh a tet
argument. Pouitm index 2 a 4, me program zskat etzec vzorkovac frekvenci a
velikosti bloku.
Spektrln Program v prvn ad m vstupn data z hudebn poznmky
genertoru.Poznmka genertor produkuje amplitudy signlu. Vzhledem k tomu, data je
velmi dlouh a je ve formtu CSV, musme vytvoit pro smyce, kter se dret snmn
dat a do poslednho dku signlu.
Clem programu je nalezen index maximln velikosti diskrtn Fourierova
transformace. Ke splnn tohoto poadavku, musme pout Nejrychlej transformace v
zpadnm knihovn.Knihovna poskytuje schopnost potat Fourierova transformace v
komplexnch slech.
K dispozici budou dv pole vytvoen v programu pro ukldn signlu, jeden se pouv
k ukldn amplitudy z hudebn poznmky genertoru, a dal obchody pole potna
komplexn data.Vstup je pli nepome, dokud vypotat velikost kadho datovho
bodu. Tento kol lze snadno provst pomoc magnitudy vzorce.