~ubuntu-branches/ubuntu/quantal/linpsk/quantal

« back to all changes in this revision

Viewing changes to linpsk/cdisplay.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bruce Walker
  • Date: 2002-02-06 11:43:38 UTC
  • Revision ID: james.westby@ubuntu.com-20020206114338-xqmjmhh01lpjm0g4
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          cdisplay.cpp  -  description
 
3
                             -------------------
 
4
    begin                : Sat Mar 18 2000
 
5
    copyright            : (C) 2000 by Volker Schroer
 
6
    email                : DL1KSV@gmx.de
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *    based on the work of  Moe Wheatly, AE4JY                             *  
 
16
 ***************************************************************************/
 
17
 
 
18
 
 
19
#include "cdisplay.h"
 
20
#include <qpixmap.h>
 
21
 
 
22
CDisplay::CDisplay(QWidget *parent, const char *name ): QFrame(parent,name)
 
23
 
 
24
{
 
25
 
 
26
modus = BPSK;
 
27
setBackgroundColor(white);
 
28
setFrameStyle(QFrame::Box | QFrame::Raised);
 
29
setLineWidth(2);
 
30
 
 
31
 
 
32
minfreq=300;
 
33
maxfreq=2500;
 
34
from=int((minfreq*1024)/2756.25);
 
35
to=int((maxfreq*1024)/2756.25);
 
36
 
 
37
 
 
38
for (int i=0; i<4;i++)
 
39
        rxfrequency[i]=1000;
 
40
slow=FALSE;
 
41
 
 
42
pdisplay = 0;
 
43
pwaterfall=0;
 
44
 
 
45
 
 
46
}
 
47
 
 
48
CDisplay::~CDisplay()
 
49
{
 
50
}
 
51
 
 
52
void CDisplay::paintEvent(QPaintEvent *)
 
53
{
 
54
 
 
55
 int ave;
 
56
 double gain;
 
57
 
 
58
 
 
59
  switch(akttab)
 
60
 {
 
61
        case INPUT:
 
62
                plotrawinput();
 
63
   break;
 
64
        case SPECTRUM:
 
65
  if (slow)
 
66
                ave=6;
 
67
        else
 
68
                ave=2;
 
69
  gain=double(0.1*height());
 
70
        plotspectrum(fft.CalcFFT(inputdata,from,to,gain,ave,fftdata));
 
71
        break;
 
72
        case WATERFALL:
 
73
        gain=25.5;
 
74
        if (slow)
 
75
                ave=4;
 
76
        else
 
77
                ave=1;
 
78
        plotwaterfall(fft.CalcFFT(inputdata,from,to,gain,ave,fftdata));
 
79
        break;
 
80
/*  case SYNC:
 
81
          PlotSyncData();
 
82
                break;*/
 
83
        
 
84
        default:
 
85
                break;
 
86
 }
 
87
        
 
88
}
 
89
 
 
90
void CDisplay::mousePressEvent(QMouseEvent *e)
 
91
 
 
92
{
 
93
 
 
94
int freq;
 
95
 
 
96
switch(akttab)
 
97
 {
 
98
        case SPECTRUM:                          //Changing frequency only if frequency is displayed
 
99
  case WATERFALL:
 
100
                freq= (e->x()*(maxfreq-minfreq))/width()+minfreq;
 
101
 
 
102
                        if (freq != rxfrequency[settings.actChannel])
 
103
                        {
 
104
                rxfrequency[settings.actChannel]=freq;
 
105
                        emit rxFreqChanged(freq);
 
106
                        }
 
107
                break;
 
108
        default:
 
109
        break;
 
110
 }
 
111
}
 
112
 
 
113
void CDisplay::plotrawinput()
 
114
{
 
115
 
 
116
int i,dist,y,z;
 
117
QPainter p;
 
118
bool overload;
 
119
 
 
120
overload= FALSE;
 
121
 
 
122
dist=ymax/10;
 
123
 
 
124
pdisplay->fill();
 
125
p.begin(pdisplay);
 
126
p.setPen(black);
 
127
p.setBrush(white);
 
128
//drawFrame( &p);
 
129
y=ymax-dist;
 
130
// Plot Grid
 
131
for (i=1;i<10; i++)
 
132
        {
 
133
   p.drawLine(0,y,xmax,y);
 
134
   y -=dist;
 
135
  }
 
136
p.setPen(blue);
 
137
// Plot sample
 
138
y=ymax/2;
 
139
p.moveTo(0,y);
 
140
for (i=0;i<xmax;i++)
 
141
        {
 
142
                z=int(*(inputdata+i));
 
143
                if(!overload)
 
144
                        {
 
145
                         if( (z > 16384) || (z < -16384) )
 
146
                          {
 
147
                                 overload = true;
 
148
                                 p.setPen(red);
 
149
                                }
 
150
                         }
 
151
                 z=y-(y*z)/32768;
 
152
                 p.lineTo(i,z);
 
153
    }
 
154
 
 
155
p.end();
 
156
bitBlt(this,0,0,pdisplay);
 
157
}
 
158
// Plot Spectrum of decimated Input
 
159
void CDisplay::plotspectrum(bool overload)
 
160
{
 
161
 
 
162
QPainter p;
 
163
 
 
164
 
 
165
 
 
166
int i,dist,y,z;
 
167
 
 
168
dist=ymax/10;
 
169
y=ymax-dist;
 
170
 
 
171
pdisplay->fill();
 
172
p.begin(pdisplay);
 
173
p.setBrush(white);
 
174
drawFrame(&p);
 
175
 
 
176
//Plot Frequencylines for the different Rx- Windows
 
177
for (i=0; i<settings.RxChannels;i++)
 
178
        {
 
179
                p.setPen(settings.colours[i]);
 
180
                // Calculate Centerfrequency Coordinates
 
181
                z=((rxfrequency[i]-minfreq)*xmax)/(maxfreq-minfreq);
 
182
                p.drawLine(z,0,z,ymax);
 
183
 
 
184
                if ( settings.DemodulatorType[i] == RTTY ) // RTTY demands to lines
 
185
                        {
 
186
                                z=((rxfrequency[i]-minfreq+170)*xmax)/(maxfreq-minfreq);
 
187
                                p.drawLine(z,0,z,ymax);         
 
188
                        }
 
189
        }
 
190
p.setPen(black);
 
191
                                
 
192
// Plot Grid
 
193
for (i=1;i<10; i++)
 
194
        {
 
195
 
 
196
   p.drawLine(0,y,xmax,y);
 
197
   y -=dist;
 
198
  }
 
199
 
 
200
if ( (settings.status == TX_OFF_STATE) && (modus != RTTY) )
 
201
                         plotVector(&p);
 
202
 
 
203
if(overload)
 
204
        p.setPen(red);
 
205
else
 
206
        p.setPen(blue);
 
207
  p.moveTo(0,ymax);
 
208
for(i=0;i<xmax;i++)
 
209
 {
 
210
  z=xtranslate[i];
 
211
  y=ymax-fftdata[z];
 
212
        p.lineTo(i,y);
 
213
        }
 
214
// paintLineal(&p);
 
215
p.end();
 
216
bitBlt(this,0,0,pdisplay);
 
217
}
 
218
 
 
219
void CDisplay::selecttab(int tab)
 
220
 
 
221
{
 
222
akttab=tab;
 
223
}
 
224
 
 
225
 
 
226
 
 
227
void CDisplay::scaleminfreq(int freq)
 
228
{
 
229
minfreq=freq;
 
230
translate();
 
231
}
 
232
 
 
233
void CDisplay::scalemaxfreq(int freq)
 
234
{
 
235
maxfreq=freq;
 
236
translate();
 
237
}
 
238
 
 
239
void CDisplay::filtertype(bool type)
 
240
{
 
241
slow=type;
 
242
}
 
243
 
 
244
void CDisplay::translate(void)
 
245
{
 
246
int i;
 
247
from=int(minfreq*1024/2756.25);
 
248
to=int(maxfreq*1024/2756.25);
 
249
for (i=0;i<width();i++)
 
250
        xtranslate[i]=(((maxfreq-minfreq)*i*to/width())+minfreq*to)/maxfreq;
 
251
}
 
252
 
 
253
/** plots the filtered signal  vector
 
254
to recognize phase of signal */
 
255
void CDisplay::plotVector(QPainter *p)
 
256
{
 
257
 
 
258
int x,y,x1,y1;
 
259
double mag;
 
260
double tmpx;
 
261
double tmpy;
 
262
 
 
263
 
 
264
xc=xmax/8;
 
265
yc=ymax/8;
 
266
p->drawEllipse(xc,yc,40,40);
 
267
xc=xc+20;
 
268
yc=yc+20;
 
269
p->setPen(green);
 
270
        for( x=196,y=0; x<10*196; y+=196, x+=196 )// 196 = (612.5/31.25)*10
 
271
        {
 
272
                x1 = x/10;
 
273
                y1 = y/10;
 
274
                tmpx =vector[y1].real() * vector[x1].real() +
 
275
                                vector[y1].imag() * vector[x1].imag();
 
276
                tmpy = vector[y1].imag() * vector[x1].real() -
 
277
                                vector[y1].real() * vector[x1].imag();
 
278
                p->moveTo( xc,  yc );
 
279
                mag = 2*sqrt(tmpx * tmpx + tmpy * tmpy);
 
280
 
 
281
                p->lineTo( xc+(int)(yc*tmpy/mag), yc-(int)(yc*tmpx/mag) );
 
282
 
 
283
        }
 
284
 
 
285
}
 
286
 
 
287
/*void CDisplay::PlotSyncData()
 
288
{
 
289
QPainter p;
 
290
int x,i,k1,k2;
 
291
int ys;
 
292
 
 
293
        k1 = 13000/ymax;
 
294
        k2 = xmax/20;
 
295
pdisplay->fill();
 
296
p.begin(pdisplay);
 
297
p.setPen(black);
 
298
p.setBrush(white);
 
299
drawFrame(&p);
 
300
        
 
301
        for( x=k2/2,i=0; i<20; i++,x+=k2)
 
302
        {
 
303
                ys = m_SyncHist[i]/k1;
 
304
                m_SyncHist[i] = 0;
 
305
                p.moveTo( x, ymax );
 
306
                p.lineTo( x, ymax-ys );
 
307
        }
 
308
p.end();
 
309
bitBlt(this,0,0,pdisplay);
 
310
}*/
 
311
 
 
312
void CDisplay::plotwaterfall(bool overload)
 
313
{
 
314
 
 
315
QPainter p;
 
316
 
 
317
int i,x,z;
 
318
 
 
319
pdisplay->fill();
 
320
p.begin(pdisplay);
 
321
p.setBrush(white);
 
322
 
 
323
for (i=0; i<settings.RxChannels;i++)
 
324
        {
 
325
                // Calculate Centerfrequency Coordinates
 
326
                        z=((rxfrequency[i]-minfreq)*xmax)/(maxfreq-minfreq);
 
327
                                p.setPen(settings.colours[i]);
 
328
                                p.drawLine(z,2,z,ymax);
 
329
                if ( settings.DemodulatorType[i] == RTTY ) // RTTY demands to lines
 
330
                        {
 
331
                                z=((rxfrequency[i]-minfreq+170)*xmax)/(maxfreq-minfreq);
 
332
                                p.drawLine(z,2,z,ymax);         
 
333
                        }
 
334
 
 
335
                }
 
336
p.setPen(black);
 
337
if ( (settings.status == TX_OFF_STATE) && (modus != RTTY) )
 
338
        plotVector(&p);
 
339
drawFrame(&p);
 
340
p.end();
 
341
bitBlt(pwaterfall,0,2,pwaterfall);
 
342
 
 
343
p.begin(pwaterfall);
 
344
for (x=2;x<xmax;x++)
 
345
 {
 
346
        z=xtranslate[x];
 
347
        i=fftdata[z];
 
348
  p.setPen(color[i]);
 
349
        p.drawPoint(x,0);
 
350
        p.drawPoint(x,1);
 
351
 }
 
352
p.end();
 
353
bitBlt(pdisplay,0,100,pwaterfall);
 
354
bitBlt(this,0,0,pdisplay);
 
355
}
 
356
 
 
357
void CDisplay::resizeEvent(QResizeEvent *)
 
358
 
 
359
{
 
360
xmax=width();
 
361
ymax=height();
 
362
translate();    // Translate x- Coordinates for Painting
 
363
if ( pdisplay !=0)
 
364
        pdisplay->resize(xmax,ymax);
 
365
else
 
366
        pdisplay = new QPixmap(xmax,ymax);
 
367
 
 
368
 
 
369
pdisplay->fill();
 
370
 
 
371
if ( pwaterfall !=0)
 
372
        pwaterfall->resize(xmax,40);
 
373
else    
 
374
        pwaterfall= new QPixmap(xmax,40);
 
375
pwaterfall->fill();
 
376
}
 
377
 
 
378
void CDisplay::setRxFrequency(int channelNumber,int freq)
 
379
{
 
380
rxfrequency[channelNumber] = freq;
 
381
}
 
382
 
 
383
 
 
384
void CDisplay::newPhaseValue(int j,float_complex z)
 
385
{
 
386
 
 
387
        vector[j]=z;
 
388
 
 
389
}
 
390
/** Paints a Lineal in the Spectrum or Waterfall Display */
 
391
 
 
392
/*void CDisplay::paintLineal(QPainter* p)
 
393
{
 
394
 
 
395
int stepfrequency,stepwidth;
 
396
int i,ix,iy;
 
397
QString frequency;
 
398
QFontMetrics fm(settings.font);
 
399
 
 
400
stepfrequency=(maxfreq-minfreq)/7;
 
401
stepwidth=width()/7;
 
402
iy=fm.height()+2;
 
403
 
 
404
for( i=1; i < 7; i++)
 
405
                {
 
406
                frequency.setNum(minfreq+stepfrequency*i);
 
407
                ix=i*stepwidth-fm.width(frequency)/2;
 
408
                p->drawText(ix,iy,frequency);
 
409
                ix=i*stepwidth;
 
410
                p->drawLine(ix,iy,ix,iy+5);
 
411
                }
 
412
        
 
413
}*/
 
414
 
 
415
/** Calculates the IMD Value of the Signal */
 
416
float CDisplay::calcIMD()
 
417
{
 
418
float total,ratio;
 
419
 
 
420
total=fftdata[int((rxfrequency[settings.actChannel]+46.875)*1024./2756.25)]
 
421
        -fftdata[int((rxfrequency[settings.actChannel]+15.625)*1024./2756.25)];
 
422
 
 
423
ratio=fftdata[int((rxfrequency[settings.actChannel]-46.875)*1024./2756.25)]
 
424
        -fftdata[int((rxfrequency[settings.actChannel]-15.625)*1024./2756.25)];
 
425
total=(total+ratio)/2;
 
426
return total;
 
427
}
 
428
 
 
429
void CDisplay::setMode(Mode mod)
 
430
{
 
431
modus=mod;
 
432
}
 
433