Lab 5 Signal Analyzer/Generator

22
Lab 5 Signal Analyzer/Generator

description

Lab 5 Signal Analyzer/Generator. Introduction. Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or DirectX. Digitally analyze and generate analog waveforms Reconstruct the waveform using the sampled signal . Spartan 3 board. Tutorial 1. - PowerPoint PPT Presentation

Transcript of Lab 5 Signal Analyzer/Generator

Page 1: Lab 5 Signal Analyzer/Generator

Lab 5

Signal Analyzer/Generator

Page 2: Lab 5 Signal Analyzer/Generator

Introduction

Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or DirectX.

Digitally analyze and generate analog waveforms

Reconstruct the waveform using the sampled signal

Page 4: Lab 5 Signal Analyzer/Generator

Acquiring an Analog Signal

Input is a signal with peak to peak of 5 V Voltage input in the range -2.5 to 2.5 V Use Analog to Digital Converter

ADC0820 Input’s analog voltage 0 to 5 V Requires adding 2.5 Volts to input signal

before converted.

Page 5: Lab 5 Signal Analyzer/Generator

Voltage compatibility issue

Spartan 3 uses a 5 V adapter Internal voltage levels are 3.3 V, 2.5 V and 1.2 V. ADC0820 needs a 5V, Output levels are close to 5V Inputs cannot handle 5 V without a current limiting

resister. Use R > 170 Ohms to limit current to 10 mA. Alternately, since the FPGA I/O are TTL compatible,

you may want to use TTL buffers to limit the voltage levels to about 3.4 V.

Page 6: Lab 5 Signal Analyzer/Generator

Sampling Signals on Serial Port

Max Baud Rate 115,200 115,200 bits per second

Max Sampling Frequency 115,200 / 10 bits (8 data, 1 start, 1 stop)

Max Input Frequency to avoid aliasing (Max Sampling Frequency) / 2 = 5760 Hz

Page 7: Lab 5 Signal Analyzer/Generator

Discrete Fourier Transform (DFT)

Can be processor intensive thus use Fast Fourier Transform (FFT) to calculate DFT

Algorithm requires a sampling frequency as a power of 2

Refer to FFT function on UL-99 (C++)

Page 8: Lab 5 Signal Analyzer/Generator

Windows GDI

If you took 408 you probably already know this

Page 9: Lab 5 Signal Analyzer/Generator

Device context classes

CPaintDC - for drawing on windows client handlers (on paint only)

CClientDC - for drawing on windows client handlers (anytime other then on paint)

CWindowDC – for drawing anywhere in a window

CMetafileDC - Drawing to a GDI metafile

Page 10: Lab 5 Signal Analyzer/Generator

How to draw

Create paint object Move to point Draw line

Page 11: Lab 5 Signal Analyzer/Generator

How to draw

CClientDC DC(this) DC.MoveTo(0,0); DC.LineTo(100,100);

When the window calls on_paint the window will clear the area.

Page 12: Lab 5 Signal Analyzer/Generator

How to keep a drawing on a screen

Void draw(CDC* pDC,CRect rect) {

pDC->Rectangle(rect) }

Page 13: Lab 5 Signal Analyzer/Generator

How to keep a drawing on screen

Onpaint() {

CRect rect; GetClientRect (&rect);

CPaintDC dc(this);draw(&dc,rect);

}

Page 14: Lab 5 Signal Analyzer/Generator

Other draw functions

Rectangle Arc PolyLine MoveTo Pie Ellipse RoundRect

Page 15: Lab 5 Signal Analyzer/Generator

Coordinatestaken from programming with MFC second edition

Page 16: Lab 5 Signal Analyzer/Generator

Coordinates

How to set

CClientDC dc(this)

dc.SetMapMode (MM_LOMETRIC);

Page 17: Lab 5 Signal Analyzer/Generator

Why you should use a pixel coordinate systems and pitfalls

There are only so many pixels on a screen, this is set by a screen resolution.

In a pixel coordinate system, how many pixels on a client window can be found by finding the size by using:

GetClientRect(CRect rect); 1 pixel is the most accurate there is (no such

thing as ½ pixel in GDI)

Page 18: Lab 5 Signal Analyzer/Generator

Changing Color

CPen pen;

pen.CreatePen (PS_SOLID, 1, RGB (255, 0, 0));

CClientDC dc(this)

CPen *oldPen = dc.SelectObject(&pen);

Page 19: Lab 5 Signal Analyzer/Generator

Changing Color

Taken from programming with MFC, Second Edition

Page 20: Lab 5 Signal Analyzer/Generator

Different Lines

Taken from programming with MFC, Second Edition

Page 21: Lab 5 Signal Analyzer/Generator

Draw Text

CPaint dc(this)

dc.SetTextAlign(TA_RIGHT);

dc.TextOut(0,0,”hello”);

Page 22: Lab 5 Signal Analyzer/Generator

Anything else?

THERE IS MORE YOU CAN DO

This is just on the basics

Anything other details can be found on the MSDN.