며칠전 질문드렸던 함수 호출에 대해서 다시 질문드려요....ㅜ.?
글쓴이: leo~~~~ / 작성시간: 일, 2005/10/02 - 8:30오후
제가요 Qt로 프로그램을 짜는데요...
전에 질문 드렸었던거에 대한 추가적인 질문입니다....
moonzoo님하고 쿨링펜님이 답변 주셨었습니다..
=================receive.h============
#include <qradiobutton.h>
#include <qbuttongroup.h>
#include <qpushbutton.h>
#include <qlabel.h>
#include <qwidget.h>
#include <qtimer.h>
#include <qpixmap.h>
#include <qpainter.h>
#define TRUE 1
typedef struct {
double real, imag;
} COMPLEX;
#define PI 3.141592
void fft(COMPLEX *x, int m);
class mywid:public QWidget
{
Q_OBJECT
public:
char buff[10];
int fd, res, num, cat[1000], tmp, c, sta,d,i,n,j,x,type,z,t,gar;
int res2,num2,cat2,sta2, count;
int tmp2[1000];
float fr[500];
mywid();
private slots:
void slotTimer1();
void slotClicked1();
void slotClicked2();
void slotClicked3();
void slotClicked4();
void slotClicked5();
void slotClicked6();
private:
void paintEvent(QPaintEvent*);
QButtonGroup*bg;
QRadioButton*rb1;
QRadioButton*rb2;
QRadioButton*rb3;
QTimer* timer1;
QLabel* lab1;
QLabel* lab2;
QLabel* lab3;
QLabel* lab4;
QLabel* lab5;
QLabel* lab6;
QLabel* lab7;
QPushButton* bt1;
QPushButton* bt2;
QPushButton* bt3;
QPushButton* bt4;
QPushButton* bt5;
QPushButton* bt6;
};
=================receive.cpp============
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <qapplication.h>
#include <sys/signal.h>
#include <signal.h>
#include <math.h>
#include "receive.h"
#define BAUDRATE B115200
#define MODEMDEVICE "/dev/ttySA0"
#define _POSIX_SOURCE 1
int stop_flag=TRUE;
mywid::mywid()
{
c=0,j=0,x=0,z=0,type=1,i=0,d=0,t=0,tmp2[1000],gar=0;
struct termios oldtio, newtio;
struct sigaction saio;
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
tcgetattr(fd, &oldtio);
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD | CRTSCTS;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 1;
setCaption("PDA DOCTOR");
QButtonGroup* bg = new QButtonGroup("Language", this);
bg->setGeometry(10,5,280,50);
rb1 = new QRadioButton("English", bg);
rb1->move(10,15);
rb2 = new QRadioButton("Japanese", bg);
rb2->move(90,15);
rb3 = new QRadioButton("Korean", bg);
rb3->move(170,15);
lab1 = new QLabel(this);
lab2 = new QLabel(this);
lab3 = new QLabel(this);
lab4 = new QLabel(this);
lab5 = new QLabel(this);
lab6 = new QLabel(this);
lab7 = new QLabel(this);
timer1 = new QTimer(this);
bt1 = new QPushButton("Line",this);
bt2 = new QPushButton("Bar",this);
bt3 = new QPushButton("Start",this);
bt4 = new QPushButton("Stop",this);
bt5 = new QPushButton("Reset",this);
bt6 = new QPushButton("Result",this);
lab1->setFrameStyle(QFrame::Panel | QFrame::Sunken);
lab1->setLineWidth(2);
lab1->setGeometry(10,75,100,55);
lab2->setFrameStyle(QFrame::Panel | QFrame::Sunken);
lab2->setLineWidth(2);
lab2->setGeometry(10,150,100,30);
lab3->setFrameStyle(QFrame::Panel | QFrame::Sunken);
lab3->setLineWidth(2);
lab3->setGeometry(120,75,170,105);
lab4->setFrameStyle(QFrame::Panel | QFrame::Sunken);
lab4->setLineWidth(2);
lab4->setGeometry(120,75,170,105);
lab4->hide();
lab5->setText("Explanation");
lab5->setGeometry(10,60,80,10);
lab6->setText("Numberical Value");
lab6->setGeometry(10,135,80,10);
lab7->setText("Graph");
lab7->setGeometry(120,60,80,10);
bt1->setGeometry(45,185,30,25);
bt2->setGeometry(80,185,30,25);
bt3->setGeometry(10,185,30,25);
bt4->setGeometry(115,185,30,25);
bt5->setGeometry(150,185,30,25);
bt6->setGeometry(185,185,30,25);
connect(bt1, SIGNAL(clicked()), this, SLOT(slotClicked1()));
connect(bt2, SIGNAL(clicked()), this, SLOT(slotClicked2()));
connect(bt3, SIGNAL(clicked()), this, SLOT(slotClicked3()));
connect(bt4, SIGNAL(clicked()), this, SLOT(slotClicked4()));
connect(bt5, SIGNAL(clicked()), this, SLOT(slotClicked5()));
connect(bt6, SIGNAL(clicked()), this, SLOT(slotClicked6()));
}
void mywid::paintEvent(QPaintEvent*)
{
QPainter p(lab3);
QPainter p1(lab4);
sta=0,sta2=0,tmp=0;
QBrush brush1(green,SolidPattern);
QBrush brush2(red,SolidPattern);
QBrush brush3(yellow,SolidPattern);
if(stop_flag==FALSE)
{
res2=read(fd, buff, 10);
tmp2[t] = atoi(buff);
for(z=0;z<=i;z++)
{
if(type==2){
if(tmp2[z]>80){d=2;}
else if(tmp2[z]<60){d=3;}
else{d=1;}
switch(d){
case 1: p1.fillRect(sta2,105-tmp2[z], 2, 105, brush1);
sta2 = sta2+2;break;
case 2: p1.fillRect(sta2, 105-tmp2[z], 2, 105, brush2);
sta2 = sta2+2;break;
case 3: p1.fillRect(sta2, 105-tmp2[z], 2, 105, brush3);
sta2 = sta2+2;break;
}
}
else{
p.drawLine(sta, 105-tmp, sta+2, 105-tmp2[z]);
tmp = tmp2[z];
sta = sta+2;
}
}
i++;
t++;
}
}
void mywid::slotTimer1()
{
repaint();
}
void mywid::slotClicked1()
{
type = 1;
lab4->hide();
stop_flag=FALSE;
lab3->show();
repaint();
}
void mywid::slotClicked2()
{
type = 2;
lab3->hide();
stop_flag=FALSE;
lab4->show();
repaint();
}
void mywid::slotClicked3()
{
stop_flag=FALSE;
timer1->start(1000,false);
connect(timer1, SIGNAL(timeout()), this, SLOT(slotTimer1()));
}
void mywid::slotClicked4()
{
stop_flag=TRUE;
timer1->stop();
}
void mywid::slotClicked5()
{
mywid();
}
void mywid::slotClicked6()
{
}
void fft(COMPLEX *x, int m)
{
static COMPLEX *w;
static int mstore = 0;
static int n = 1;
COMPLEX u,temp,tm;
COMPLEX *xi,*xip,*xj,*wptr;
int i,j,k,l,le,windex;
double arg,w_real,w_imag,wrecur_real,wrecur_imag,wtemp_real;
if(m != mstore) {
if(mstore != 0) free(w);
mstore = m;
if(m == 0) return;
n = 1 << m;
le = n/2;
w = (COMPLEX *) calloc(le-1,sizeof(COMPLEX));
if(!w) {
printf("\nUnable to allocate complex W array\n");
exit(1);
}
arg = PI/le;
wrecur_real = w_real = cos(arg);
wrecur_imag = w_imag = -sin(arg);
xj = w;
for (j = 1 ; j < le ; j++) {
xj->real = (double)wrecur_real;
xj->imag = (double)wrecur_imag;
xj++;
wtemp_real = wrecur_real*w_real - wrecur_imag*w_imag;
wrecur_imag = wrecur_real*w_imag + wrecur_imag*w_real;
wrecur_real = wtemp_real;
}
}
le = n;
windex = 1;
for (l = 0 ; l < m ; l++) {
le = le/2;
for(i = 0 ; i < n ; i = i + 2*le) {
xi = x + i;
xip = xi + le;
temp.real = xi->real + xip->real;
temp.imag = xi->imag + xip->imag;
xip->real = xi->real - xip->real;
xip->imag = xi->imag - xip->imag;
*xi = temp;
}
wptr = w + windex - 1;
for (j = 1 ; j < le ; j++) {
u = *wptr;
for (i = j ; i < n ; i = i + 2*le) {
xi = x + i;
xip = xi + le;
temp.real = xi->real + xip->real;
temp.imag = xi->imag + xip->imag;
tm.real = xi->real - xip->real;
tm.imag = xi->imag - xip->imag;
xip->real = tm.real*u.real - tm.imag*u.imag;
xip->imag = tm.real*u.imag + tm.imag*u.real;
*xi = temp;
}
wptr = wptr + windex;
}
windex = 2*windex;
}
j = 0;
for (i = 1 ; i < (n-1) ; i++) {
k = n/2;
while(k <= j) {
j = j - k;
k = k/2;
}
j = j + k;
if (i < j) {
xi = x + i;
xj = x + j;
temp = *xj;
*xj = *xi;
*xi = temp;
}
}
}
소스 보시기 정신없으실텐데요......
위에 코드 보시면요....
시리얼을 통해서 데이터가 들어오면
그 데이터를 tmp2라는 배열에
차례대로 저장하게 되는데요....
버튼 6을 누르면 fft함수를 호출해서
푸리에 변환을 시키는 건데요....
tmp2배열에 저장되어 있는 값을
fft함수에 어떻게 적용해야할지 몰라서요...ㅜ.ㅜ
Forums:


소스가 정신없는거 같아서 요점만 간단히 말씀드리겠습니다.시리얼을 통해
소스가 정신없는거 같아서 요점만 간단히 말씀드리겠습니다.
시리얼을 통해 데이터를 받아서 tmp2라는 int형 변수에 순서대로 넣습니다.
그리고나서 그 데이터를 가지구 푸리에 변환을 하려는데요....
푸리에 변환 함수는
fft(COMPLEX *x, int m);
이것입니다....
COMPLEX는 구조체이구요...
typedef struct {
double real, imag;
}COMPLEX;
문제는요 데이터를 다 받은 후에 fft 함수를 호출할때 tmp2라는 변수에 저장되어 있는 값을 fft 함수로 넘겨줘야 하는데요..... 어떻게 해야 할까요....
fft함수의 COMPLEX *x 이부분을 어떻게 해야할지.....ㅜ.ㅜ
댓글 달기