Anda di halaman 1dari 31

PROJECT SIGNAL SYSTEM

FFT SINYAL SUARA DENGAN C++

Nama : Choirun Nisa


NRP : 2020191014

Program Studi Pascasarjana Teknik Informatika dan Komputer


Politeknik Elektronika Negeri Surabaya
Tahun Ajaran 2019/2020
I. TEORI
A. Sinyal
Sinyal adalah suatu isyarat untuk melanjutkan atau meneruskan suatu kegiatan.
Biasanya isyarat ini berbentuk tanda-tanda, lampu-lampu, suara-suara, dan lain-lain.
Dalam kereta api, misalnya, isyarat berarti suatu tanda untuk melanjutkan atau
meneruskan perjalanan ke tempat/stasiun berikutnya, dan biasanya isyarat ini
dikirimkan oleh stasiun yang terkait. Dalam dunia Keteknikan, khususnya Teknik
Elektro, Teknik Informasi, dan Teknik Kendali, isyarat adalah besaran yang berubah
dalam waktu dan atau dalam ruang dan membawa suatu informasi. Menurut ITU
(International Telecommunication Union), sinyal adalah suatu gejala fisika dimana
satu atau lebih dari karakteristiknya melambangkan informasi. Sinyal ini biasanya
berupa sinyal elektrik. Sinyal ini bisa merupakan besaran elektrik murni (tegangan,
arus, dan lain-lain), tetapi pada umumnya adalah besaran fisik lain yang dijadikan
elektrik dengan bantuan sensor. Contoh sinyal elektrik adalah sinyal suara yang
berasal dari radio, sinyal citra yang berasal dari kamera fotografi, dan sinyal video
yang berasal dari kamera video.

B. Sinyal Suara
Audio diartikan sebagai suara atau reproduksi suara. Gelombang suara adalah
gelombang yang dihasilkan dari sebuah benda yang bergetar. Gambarannya adalah
senar gitar yang dipetik, gitar akan bergetar dan getaran ini merambat di udara, atau
air, atau material lainnya. Satu-satunya tempat dimana suara tak dapat merambat
adalah ruangan hampa udara. Gelombang suara ini memiliki lembah dan bukit, satu
buah lembah dan bukit akan menghasilkan satu siklus atau periode. Siklus ini
berlangsung berulang-ulang, yang membawa pada konsep frekuensi. Jelasnya,
frekuensi adalah jumlah dari siklus yang terjadi dalam satu detik. Satuan dari
frekuensi adalah Hertz atau disingkat Hz.
Telinga manusia dapat mendengar bunyi antara 20 Hz hingga 20 KHz (20.000
Hz) sesuai dengan batasan sinyal suara. Karena pada dasarnya sinyal suara adalah
sinyal yang dapat diterima oleh telinga manusia. Angka 20 Hz sebagai frekuensi
suara terendah yang dapat didengar, sedangkan 20 KHz merupakan frekuensi
tertinggi yang dapat didengar.

Gambar 1. Panjang Gelombang, Frekuensi dan Amplitudo


C. Sinyal dan Sistem
Sinyal adalah fenomena dari lingkungan yang terukur atau terkuantisasi, sementara
sistem merupakan bagian dari lingkungan yang menghubungkan sinyal dengan sinyal
lainnya, atau dengan kata lain merespon sinyal masuk dengan menghasilkan sinyal
keluaran. Ada berbagai macam contoh sinyal dan sistem, salah satunya adalah suara
pembicaraan dan sistem komunikasi telepon.
Berdasarkan bentuknya, data dan sinyal dapat dibedakan ke dalam data dan sinyal
analog atau data dan sinyal digital (gambar 2). Suatu data atau sinyal dikatakan analog
apabila amplitudo dari data atau sinyal tersebut terus menerus ada dalam rentang waktu
tertentu (kontinyu) dan memiliki variasi nilai amplitudo tak terbatas. Misalnya, data
yang berasal dari suara (voice) tergolong sebagai data analog. Sebaliknya data atau
sinyal dikatakan digital apabila amplitudo dari data atau sinyal tersebut tidak kontinyu
dan memiliki variasi nilai amplitudo yang terbatas (diskrit).

Gambar 2. Sinyal analog (atas) dan Sinyal digital (bawah)


D. Fast Fourier Transform
Fast Fourier Transform (FFT) yang ditemukan tahun 1965 merupakan
pengembangan dari Fourier Transform (FT). Penemu FT adalah J. Fourier pada
tahun 1822. FT membagi sebuah sinyal menjadi frekuensi yang berbeda-beda dalam
fungsi eksponensial yang kompleks.
Definisi Fast Fourier Transform (FFT) adalah metode yang sangat efisien untuk
menghitung koefisien dari Fourier diskrit ke suatu finite sekuen dari data yang
komplek. Karena substansi waktu yang tersimpan lebih dari pada metoda
konvensional, fast fourier transform merupakan aplikasi temuan yang penting
didalam sejumlah bidang yang berbeda seperti analisis spectrum, speech and optical
signal processing, design filter digital. Algoritma FFT berdasarkan atas prinsip
pokok dekomposisi perhitungan discrete fourier transform dari suatu sekuen
sepanjang N kedalam transformasi diskrit Fourier secara berturut-turut lebih kecil.
Cara prinsip ini diterapkan memimpin ke arah suatu variasi dari algortima yang
berbeda, di mana semuanya memperbandingkan peningkatan kecepatan perhitungan.
Fast Fourier Transform, adalah suatu algoritma untuk menghitung transformasi
fourier diskrit dengan cepat dan efisien. Karena banyak sinyal-sinyal dalam sistem
komunikasi yang bersifat kontinyu, sehingga untuk kasus sinyal kontinyu kita
gunakan transformasi fourier. Transformasi Fourier didefinisikan oleh rumus:

Dimana s(f) adalah sinyal dalam domain frekuensi (frequency domain), s(t)

adalah sinyal dalam domain waktu (time domain), dan adalah konstanta dari
nilai sebuah sinyal, f adalah frekuensi dan t adalah waktu. FFT (Fast Fourier
Transform) merupakan salah satu metode untuk transformasi sinyal suara dalam
domain waktu menjadi sinyal dalam domain frekuensi, artinya proses perekaman
suara disimpan dalam bentuk digital berupa gelombang spectrum suara yang
berbasis frekuensi sehingga lebih mudah dalam menganalisa spectrum frekuensi
suara yang telah direkam.
E. File Wav
File audio ini diciptakan oleh Microsoft. File ini menjadi standar file audio dalam
Personal Computer(PC) baik untuk sistem operasi, game, maupun file suara lain
yang kualitas suaranya setara dengan CD. File ini memiliki ukuran yang cukup
besar, karena suara yang disimpan dalam format ini tidak mengalami proses
kompresi (raw data). Meski buatan Microsoft, bukan berarti file ini tidak dapat
dijalankan oleh sistem operasi selain Windows. Setidaknya, Linux dan Macintosh
juga dapat menjalankan file ini. Beikut ini diagram canonical file wav.

Gambar 3. Diagram Canonical file wav


F. Audacity
Audacity adalah program yang memanipulasi bentuk gelombang audio digital.
Selain rekaman suara langsung dari dalam program, ini impor banyak format file
suara, termasuk WAV, AIFF, MP3, dan Ogg Vorbis. Format PCM dari 8,16,24 dan
32-bit dapat diimpor dan diekspor. Berikut ini beberapa fitur dari audacity.
1. potong, Salin, Tempel, Hapus, Diam, Duplikat, Split
2. berlaku plug-in efek untuk bagian suara
3. built-in editor amplop volume
4. spektrogram disesuaikan trek modus tampilan
5. analisis frekuensi window untuk aplikasi audio analisis
6. tingkat pemutaran kustom untuk melacak setiap, yang hidup-resampled dengan
tingkat Sampel proyek
7. sederhana untuk operasi menyelaraskan kompleks untuk trek dan kelompok
trek

Gambar 4. Antarmuka Audacity


II. PERALATAN
1. 1 buah laptop dengan OS Windows
2. Software Visual Studio
3. Software Audacity
4. Ms. Excel

III. LANGKAH PERCOBAAN


1. Merekam suara A, I, U, E, dan O dengan suara Alami menggunakan software
Audacity. Dimana Frekuensi Samplingnya adalah 12Khz dan Kuantisasinya
adalah 16 bit.

Gambar 5. Trek Hasil Rekam Suara A


Gambar 6. Trek Hasil Rekam Suara I

Gambar 7. Trek Hasil Rekam Suara U

Gambar 8. Trek Hasil Rekam Suara E


Gambar 9. Trek Hasil Rekam Suara O

2. Penyusunan Program dengan C++ dan Plotting FFT ke .CSV


Untuk melakukan ploting data FFT dari sinyal suara ke excel digunakan Bahasa
C++ dan software yang digunakan adalah visual studio. Terdapat 3 File yaitu,
main.cpp, FftComplex.cpp, dan FftComplex.h. Berikut ini adalah sourcode dari
program FFT.
A. main.cpp

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <random>
#include <vector>
#include <fstream>
#include <sstream>
#include <string>
#include "FftComplex.h"

using std::complex;
using std::cout;
using std::endl;
using std::vector;
using namespace std;

// Private function prototypes


static void testFft(int n);
static void testConvolution(int n);
static vector<complex<double> > naiveDft(const vector<complex<double> >& input,
bool inverse);
static vector<complex<double> > naiveConvolve(const vector<complex<double> >&
xvec, const vector<complex<double> >& yvec);
static double log10RmsErr(const vector<complex<double> >& xvec, const
vector<complex<double> >& yvec);
static vector<complex<double> > randomComplexes(int n);

vector<complex<double>> read1DDouble(string filename, bool showLoadedData);


void WavReader(const char* fileName, string fileToSave);

// Mutable global variable


static double maxLogError = -INFINITY;
// Random number generation
std::default_random_engine randGen((std::random_device())());

//Wav Header
struct wav_header_t
{
char chunkID[4]; //"RIFF" = 0x46464952
unsigned long chunkSize; //28 [+ sizeof(wExtraFormatBytes) +
wExtraFormatBytes] + sum(sizeof(chunk.id) + sizeof(chunk.size) + chunk.size)
char format[4]; //"WAVE" = 0x45564157
char subchunk1ID[4]; //"fmt " = 0x20746D66
unsigned long subchunk1Size; //16 [+ sizeof(wExtraFormatBytes) +
wExtraFormatBytes]
unsigned short audioFormat;
unsigned short numChannels;
unsigned long sampleRate;
unsigned long byteRate;
unsigned short blockAlign;
unsigned short bitsPerSample;
//[WORD wExtraFormatBytes;]
//[Extra format bytes]
};

//Chunks
struct chunk_t
{
char ID[4]; //"data" = 0x61746164
unsigned long size; //Chunk data bytes
};

vector<double> data_20ms;
string initFile;

int main() {
/*
//// Test power-of-2 size FFTs
//for (int i = 0; i <= 12; i++)
// testFft(1 << i);

//// Test small size FFTs


//for (int i = 0; i < 30; i++)
// testFft(i);

//// Test diverse size FFTs


//for (int i = 0, prev = 0; i <= 100; i++) {
// int n = static_cast<int>(std::lround(std::pow(1500.0, i / 100.0)));
// if (n > prev) {
// testFft(n);
// prev = n;
// }
//}
//// Test power-of-2 size convolutions
//for (int i = 0; i <= 12; i++)
// testConvolution(1 << i);

//// Test diverse size convolutions


//for (int i = 0, prev = 0; i <= 100; i++) {
// int n = static_cast<int>(std::lround(std::pow(1500.0, i / 100.0)));
// if (n > prev) {
// testConvolution(n);
// prev = n;
// }
//}

//cout << endl;


//cout << "Max log err = " << std::setprecision(3) << maxLogError << endl;
//cout << "Test " << (maxLogError < -10 ? "passed" : "failed") << endl;
*/
int i;

initFile = "Say O";


//ekstrak data wav
WavReader("desktop/nissa/u.wav", "data_wav_"+ initFile +".csv");

vector<complex<double>> dataInFFT;
//dataInFFT = read1DDouble("dataSampling.csv", false);
for (auto& row : data_20ms) {
complex<double> y= (complex<double>)row;
dataInFFT.push_back(y);
}

//proses FFT
cout << "\n\nproses FFT...\n";
Fft::transform(dataInFFT);

//simpan hasil FFT


cout << "simpan hasil FFT...\n";
fstream fout;
fout.open("outputFFT_" + initFile + ".csv", ios::out);
vector<double> dtReal;
dtReal.clear();
for (int i = 0; i < dataInFFT.size(); i++) {
double x = dataInFFT[i].real();
dtReal.push_back(x);
fout << x << "\n";
}
fout.close();

//smoothing
cout << "Smoothing...\n";
fout.open("outputFFTSmoothing_" + initFile + ".csv", ios::out);
vector<double> dtSmooth;
//smoothing
cout << "Smoothing...\n";
fout.open("outputFFTSmoothing_" + initFile + ".csv", ios::out);
vector<double> dtSmooth;
dtSmooth.clear();
for (int i = 0; i < dtReal.size(); i++) {
double jPrev, jNow, jNext;
if (i == 0) {
jPrev = 0; jNow = dtReal[i]; jNext = dtReal[i + 1];
}
else if (i == (dtReal.size() - 1)) {
jPrev = dtReal[i - 1]; jNow = dtReal[i]; jNext = 0;
}
else {
jPrev = dtReal[i - 1]; jNow = dtReal[i]; jNext =
dtReal[i + 1];
}

double Val = (jPrev + jNow + jNext);


double smoothVal = Val / 3;
dtSmooth.push_back(smoothVal);
fout << smoothVal << "\n";
}
fout.close();

cout << "SELESAI\n\n\n";


return EXIT_SUCCESS;
}

void WavReader(const char* fileName, string fileToSave)


{
//////////////////////ambil data wav
FILE* fin = fopen(fileName, "rb");

//Read WAV header


wav_header_t header;
fread(&header, sizeof(header), 1, fin);

//Print WAV header


printf("WAV File Header read:\n");
printf("File Type: %s\n", header.chunkID);
printf("File Size: %ld\n", header.chunkSize);
printf("WAV Marker: %s\n", header.format);
printf("Format Name: %s\n", header.subchunk1ID);
printf("Format Length: %ld\n", header.subchunk1Size);
printf("Format Type: %hd\n", header.audioFormat);
printf("Number of Channels: %hd\n", header.numChannels);
printf("Sample Rate: %ld\n", header.sampleRate);
printf("Sample Rate * Bits/Sample * Channels / 8: %ld\n", header.byteRate);
printf("Bits per Sample * Channels / 8.1: %hd\n", header.blockAlign);
//skip wExtraFormatBytes & extra format bytes
//fseek(f, header.chunkSize - 16, SEEK_CUR);

//Reading file
chunk_t chunk;
printf("id\t" "size\n");
//go to data chunk
while (true)
{
fread(&chunk, sizeof(chunk), 1, fin);
printf("%c%c%c%c\t" "%li\n", chunk.ID[0], chunk.ID[1], chunk.ID[2],
chunk.ID[3], chunk.size);
if (*(unsigned int*)&chunk.ID == 0x61746164)
break;
//skip chunk data bytes
fseek(fin, chunk.size, SEEK_CUR);
cout << "ok \n";
}

//Number of samples
int sample_size = header.bitsPerSample / 8;
int samples_count = chunk.size * 8 / header.bitsPerSample;
printf("Samples count = %i\n", samples_count);

short int* value = new short int[samples_count];


memset(value, 0, sizeof(short int) * samples_count);

//Reading data
for (int i = 0; i < samples_count; i++)
{
fread(&value[i], sample_size, 1, fin);
}

//Write data wav into the file


fstream fout;
fout.open(fileToSave, ios::out);
for (int i = 0; i < samples_count; i++)
{
//fprintf(fout, "%d\n", value[i]);
fout << value[i] << "\n";
}
fclose(fin);
fout.close();
////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///ambil data sample
///20mS => (1/12000) * 1000 * 20 = 240 data
//vector<int> dt;
int d0 = samples_count / 2; //mulai dari tengah2
int n = d0 + 240; //data selama 20mS
data_20ms.clear();
////write 20mS from wav File
fout.open("data_20mS_" + initFile + ".csv", ios::out);
for (int i = d0; i < n; i++) {
data_20ms.push_back((double)value[i]);
fout << value[i] << "\n";
}

//zero padding, untuk melengkapi format 2^9 (512 data)


for (int i = 240; i < 512; i++) {
data_20ms.push_back(0);
fout << "0\n";
}
fout.close();
}

vector<complex<double>> read1DDouble(string filename, bool showLoadedData) {


vector<complex<double>> vec;
string line;
ifstream f_data(filename);

while (getline(f_data, line)) {


string val;
vector<string> row;
stringstream s(line);
while (getline(s, val, ',')) {
double x = stod(val);
complex<double> y = (complex<double>)x;
vec.push_back(y);
}
}
f_data.close();

if (showLoadedData) {
cout << "complete loaded data" << endl << endl;
for (auto& val : vec)
cout << val << " ";
cout << endl;
}

return vec;
}

static void testFft(int n) {


const vector<complex<double> > input = randomComplexes(n);
const vector<complex<double> > refout = naiveDft(input, false);
vector<complex<double> > actualout = input;
Fft::transform(actualout);
cout << "fftsize=" << std::setw(4) << std::setfill(' ') << n << " "
<< "logerr=" << std::setw(5) << std::setprecision(3) <<
std::setiosflags(std::ios::showpoint)
<< log10RmsErr(refout, actualout) << endl;
static void testConvolution(int n) {
const vector<complex<double> > input0 = randomComplexes(n);
const vector<complex<double> > input1 = randomComplexes(n);
const vector<complex<double> > refout = naiveConvolve(input0, input1);
vector<complex<double> > actualout(n);
Fft::convolve(input0, input1, actualout);
cout << "convsize=" << std::setw(4) << std::setfill(' ') << n << " "
<< "logerr=" << std::setw(5) << std::setprecision(3) <<
std::setiosflags(std::ios::showpoint)
<< log10RmsErr(refout, actualout) << endl;
}
/*---- Naive reference computation functions ----*/

static vector<complex<double> > naiveDft(const vector<complex<double> >& input,


bool inverse) {
int n = static_cast<int>(input.size());
vector<complex<double> > output;
double coef = (inverse ? 2 : -2) * M_PI / n;
for (int k = 0; k < n; k++) { // For each output element
complex<double> sum(0);
for (int t = 0; t < n; t++) { // For each input element
double angle = coef * (static_cast<long long>(t)* k% n);
sum += input[t] * std::polar(1.0, angle);
}
output.push_back(sum);
}
return output;
}

static vector<complex<double> > naiveConvolve(


const vector<complex<double> >& xvec, const vector<complex<double> >&
yvec) {
int n = static_cast<int>(xvec.size());
vector<complex<double> > outvec(n); // All zeros
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int k = (i + j) % n;
outvec[k] += xvec[i] * yvec[j];
}
}
return outvec;
}

/*---- Utility functions ----*/


/*---- Utility functions ----*/

static double log10RmsErr(const vector<complex<double> >& xvec, const


vector<complex<double> >& yvec) {
int n = static_cast<int>(xvec.size());
double err = std::pow(10, -99 * 2);
for (int i = 0; i < n; i++)
err += std::norm(xvec.at(i) - yvec.at(i));
err /= n > 0 ? n : 1;
err = std::sqrt(err); // Now this is a root mean square (RMS) error
err = std::log10(err);
maxLogError = std::max(err, maxLogError);
return err;
}

static vector<complex<double> > randomComplexes(int n) {


std::uniform_real_distribution<double> valueDist(-1.0, 1.0);
vector<complex<double> > result;
for (int i = 0; i < n; i++)
result.push_back(complex<double>(valueDist(randGen),
valueDist(randGen)));
return result;
}

B. FftComplex.cpp

/* C. FftComplex.h
* Free FFT and convolution (C++)
*
* Copyright (c) 2019 Project Nayuki. (MIT License)
* https://www.nayuki.io/page/free-small-fft-in-multiple-languages
*

#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <stdexcept>
#include "FftComplex.h"

using std::complex;
using std::size_t;
using std::vector;
// Private function prototypes
static size_t reverseBits(size_t x, int n);

void Fft::transform(vector<complex<double> >& vec) {


size_t n = vec.size();
if (n == 0)
return;
else if ((n & (n - 1)) == 0) // Is power of 2
transformRadix2(vec);
else // More complicated algorithm for arbitrary sizes
transformBluestein(vec);
}

void Fft::inverseTransform(vector<complex<double> >& vec) {


std::transform(vec.cbegin(), vec.cend(), vec.begin(),
static_cast<complex<double>(*)(const
complex<double>&)>(std::conj));
transform(vec);
std::transform(vec.cbegin(), vec.cend(), vec.begin(),
static_cast<complex<double>(*)(const
complex<double>&)>(std::conj));
}

void Fft::transformRadix2(vector<complex<double> >& vec) {


// Length variables
size_t n = vec.size();
int levels = 0; // Compute levels = floor(log2(n))
for (size_t temp = n; temp > 1U; temp >>= 1)
levels++;
if (static_cast<size_t>(1U) << levels != n)
throw std::domain_error("Length is not a power of 2");

// Trignometric table
vector<complex<double> > expTable(n / 2);
for (size_t i = 0; i < n / 2; i++)
expTable[i] = std::polar(1.0, -2 * M_PI * i / n);

// Bit-reversed addressing permutation


for (size_t i = 0; i < n; i++) {
size_t j = reverseBits(i, levels);
if (j > i)
std::swap(vec[i], vec[j]);
}
// Cooley-Tukey decimation-in-time radix-2 FFT
for (size_t size = 2; size <= n; size *= 2) {
size_t halfsize = size / 2;
size_t tablestep = n / size;
for (size_t i = 0; i < n; i += size) {
for (size_t j = i, k = 0; j < i + halfsize; j++, k += tablestep) {
complex<double> temp = vec[j + halfsize] *
expTable[k];
vec[j + halfsize] = vec[j] - temp;
vec[j] += temp;
}
}
if (size == n) // Prevent overflow in 'size *= 2'
break;
}
}

void Fft::transformBluestein(vector<complex<double> >& vec) {


// Find a power-of-2 convolution length m such that m >= n * 2 + 1
size_t n = vec.size();
size_t m = 1;
while (m / 2 <= n) {
if (m > SIZE_MAX / 2)
throw std::length_error("Vector too large");
m *= 2;
}

// Trignometric table
vector<complex<double> > expTable(n);
for (size_t i = 0; i < n; i++) {
unsigned long long temp = static_cast<unsigned long long>(i)* i;
temp %= static_cast<unsigned long long>(n) * 2;
double angle = M_PI * temp / n;
expTable[i] = std::polar(1.0, -angle);
}

// Temporary vectors and preprocessing


vector<complex<double> > av(m);
for (size_t i = 0; i < n; i++)
av[i] = vec[i] * expTable[i];
vector<complex<double> > bv(m);
bv[0] = expTable[0];
for (size_t i = 1; i < n; i++)
bv[i] = bv[m - i] = std::conj(expTable[i]);
// Convolution
vector<complex<double> > cv(m);
convolve(av, bv, cv);

// Postprocessing
for (size_t i = 0; i < n; i++)
vec[i] = cv[i] * expTable[i];
}

void Fft::convolve(
const vector<complex<double> >& xvec,
const vector<complex<double> >& yvec,
vector<complex<double> >& outvec) {

size_t n = xvec.size();
if (n != yvec.size() || n != outvec.size())
throw std::domain_error("Mismatched lengths");
vector<complex<double> > xv = xvec;
vector<complex<double> > yv = yvec;
transform(xv);
transform(yv);
for (size_t i = 0; i < n; i++)
xv[i] *= yv[i];
inverseTransform(xv);
for (size_t i = 0; i < n; i++) // Scaling (because this FFT implementation omits
it)
outvec[i] = xv[i] / static_cast<double>(n);
}

static size_t reverseBits(size_t x, int n) {


size_t result = 0;
for (int i = 0; i < n; i++, x >>= 1)
result = (result << 1) | (x & 1U);
return result;
}
c. FftComplex.h

#pragma once

#include <complex>
#include <vector>

namespace Fft {

/*
* Computes the discrete Fourier transform (DFT) of the given complex
vector, storing the result back into the vector.
* The vector can have any length. This is a wrapper function.
*/
void transform(std::vector<std::complex<double> >& vec);

/*
* Computes the inverse discrete Fourier transform (IDFT) of the given
complex vector, storing the result back into the vector.
* The vector can have any length. This is a wrapper function. This transform
does not perform scaling, so the inverse is not a true inverse.
*/
void inverseTransform(std::vector<std::complex<double> >& vec);

/*
* Computes the discrete Fourier transform (DFT) of the given complex
vector, storing the result back into the vector.
* The vector's length must be a power of 2. Uses the Cooley-Tukey
decimation-in-time radix-2 algorithm.
*/
void transformRadix2(std::vector<std::complex<double> >& vec);

/*
* Computes the discrete Fourier transform (DFT) of the given complex
vector, storing the result back into the vector.
* The vector can have any length. This requires the convolution function,
which in turn requires the radix-2 FFT function.
* Uses Bluestein's chirp z-transform algorithm.
*/
void transformBluestein(std::vector<std::complex<double> >& vec);

/*
* Computes the circular convolution of the given complex vectors. Each
vector's length must be the same.
*/
void convolve(
const std::vector<std::complex<double> >& vecx,
const std::vector<std::complex<double> >& vecy,
std::vector<std::complex<double> >& vecout);

IV. HASIL PERCOBAAN


Setelah melakukan penyusunan program langkah selanutnya adalah running program
dan melihat hasilnya:

A. Running untuk A.wav

Hasil compile untuk file A.wav

Hasil outputnya jika di plotting ke excel adalah sebagai berikut:


raw audio A.wav
8000

6000

4000

2000

0
12 324 636 948 126015721884219625082820313234443756406843804692500453165628
-2000

-4000

-6000

Gambar 9. Raw Data A.wav


Gambar diatas adalah gambar sinyal suara raw dari huruf A. kemudian jika
dilakukan FFT dan diambil 20ms dari tengah maka hasilnya adalah sbb:

data 20 ms file A.wav


1000

500

0
2 24 46 68 90 112134156178200222244266288310332354376398420442464486508

-500

-1000

-1500

Gambar 10. Sinyal hasil FFT dan hasil cuplik 20ms dari tengah

Kemudian melakukan smoothing:


Smoothing file A.wav
25000

20000

15000

10000

5000

0
2 26 50 74 98 122 146 170 194 218 242 266 290 314 338 362 386 410 434 458 482 506
-5000

-10000

-15000

Gambar 10. Hasil Smoothing untuk file A.wav

B. Running untuk I.wav

Hasil compile untuk file I.wav


Hasil outputnya jika di plotting ke excel adalah sebagai berikut:

Data Raw file I.wav


6000
5000
4000
3000
2000
1000
0
19 551 1083161521472679321137434275480753395871640369357467799985319063
-1000
-2000
-3000
-4000

Gambar 11. Raw Data I.wav

Gambar diatas adalah gambar sinyal suara raw dari huruf I. kemudian jika dilakukan
FFT dan diambil 20ms dari tengah maka hasilnya adalah sbb:

data 20ms file I.wav


1000

500

0
2 24 46 68 90 112134156178200222244266288310332354376398420442464486508

-500

-1000

-1500

Gambar 12. Sinyal hasil FFT dan hasil cuplik 20ms dari tengah
Kemudian jika dilakukan smoothing maka akan sbb:

Sinyal Hasil Smoothing I.wav


15000

10000

5000

0
2 26 50 74 98 122 146 170 194 218 242 266 290 314 338 362 386 410 434 458 482 506

-5000

-10000

-15000

Gambar 13. Sinyal Hasil Smoothing

C. Running untuk U.wav

Hasil compile untuk file U.wav


Hasil outputnya jika di plotting ke excel adalah sebagai berikut:

Raw data file U.wav


8000

6000

4000

2000

0
10 280 550 820 10901360163019002170244027102980325035203790406043304600
-2000

-4000

-6000

Gambar 13. Raw Data U.wav

Gambar diatas adalah gambar sinyal suara raw dari huruf U. kemudian jika
dilakukan FFT dan diambil 20ms dari tengah maka hasilnya adalah sbb:

20 ms data file U.wav


8000

6000

4000

2000

0
2 24 46 68 90 112134156178200222244266288310332354376398420442464486508
-2000

-4000

-6000

Gambar 13. Sinyal hasil FFT dan hasil cuplik 20ms dari tengah
Jika dilakukann smoothing maka akan sbb:

Smoothing file U.wav


200000

150000

100000

50000

0
2 26 50 74 98 122 146 170 194 218 242 266 290 314 338 362 386 410 434 458 482 506
-50000

-100000

-150000

-200000

Gambar 14. Sinyal hasil smoothing

D. Running untuk E.wav

Hasil compile untuk file U.wav


Hasil outputnya jika di plotting ke excel adalah sebagai berikut:

Raw data file E.wav


10000
8000
6000
4000
2000
0
27 999 1971 2943 3915 4887 5859 6831 7803 8775 9747 107191169112663
-2000
-4000
-6000
-8000
-10000

Gambar 15. Raw Data E.wav

Gambar diatas adalah gambar sinyal suara raw dari huruf E. kemudian jika
dilakukan FFT dan diambil 20ms dari tengah maka hasilnya adalah sbb:

20 ms data file U.wav


2000

1500

1000

500

0
2 24 46 68 90 112134156178200222244266288310332354376398420442464486508
-500

-1000

-1500

Gambar 16. Sinyal hasil FFT dan hasil cuplik 20ms dari tengah
Jika dilakukann smoothing maka akan sbb:

Smoothing file E.wav


80000

60000

40000

20000

0
2 26 50 74 98 122 146 170 194 218 242 266 290 314 338 362 386 410 434 458 482 506

-20000

-40000

Gambar 17. Sinyal hasil smoothing

E. Running untuk O.wav

Hasil compile untuk file O.wav


Hasil outputnya jika di plotting ke excel adalah sebagai berikut:

Raw data file O.wav


10000

5000

0
54 1998 3942 5886 7830 9774 1171813662156061755019494214382338225326

-5000

-10000

-15000

Gambar 18. Raw Data O.wav

Gambar diatas adalah gambar sinyal suara raw dari huruf O. kemudian jika
dilakukan FFT dan diambil 20ms dari tengah maka hasilnya adalah sbb:

20ms data file O.wav


1500

1000

500

0
2 24 46 68 90 112134156178200222244266288310332354376398420442464486508
-500

-1000

-1500

-2000

Gambar 19. Sinyal hasil FFT dan hasil cuplik 20ms dari tengah
Jika dilakukann smoothing maka akan sbb:

Smothing file O.wav


60000

40000

20000

0
2 26 50 74 98 122 146 170 194 218 242 266 290 314 338 362 386 410 434 458 482 506
-20000

-40000

-60000

-80000

Gambar 17. Sinyal hasil smoothing

Anda mungkin juga menyukai