-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
48 lines (39 loc) · 1.29 KB
/
mainwindow.cpp
File metadata and controls
48 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//JFFT usage example
//load time data in this case two real sine waves
QVector<JFFT::cpx_type> x;
x.resize(16384);//use a power of 2 else JFFT will change it to be so
for(int i=0;i<x.size();++i)
{
x[i]=JFFT::cpx_type(sin(((double)i)/2.0),0);
x[i]+=JFFT::cpx_type(sin(((double)i)/4.6),0);
}
//tranform it to the frequency domain
fft.fft(x);
//display frequency information
//if you have matlab or octave you can copy and paste the resulting text to display the frequency spectrum
QString str;
str+="f=[";
for(int i=0;i<x.size();++i)
{
str+=QString::number(x[i].real());
str+="+";
str+=QString::number(x[i].imag());
str+="i";
if(i+1<x.size())str+=",";
else str+="];\nplot(abs(f));xlim([1 numel(f)]);title('JFFT example usage output');xlabel('Sample');ylabel('magnitude');set(gca, 'YScale', 'log');\n";
}
ui->plainTextEdit->setPlainText(str);
//tranform it back to the time domain using an inverse FFT
fft.ifft(x);
}
MainWindow::~MainWindow()
{
delete ui;
}