联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2020-04-08 09:52

CSCI291 Programming for Engineers UOW

Laboratory Exercises - Week 4

Topics:

- User defined data types

- User defined functions

1. Create a sub-folder lab4 inside your CSCI291 folder.

2. Write a prototype and a definition of the function iirFilter() that implements a

low-pass digital IIR filter used for noise reduction of corrupted signals

A simple low-pass IIR filter produces an output sample that is an average of an input

sample and of the filter output from the previous time interval. For example:

Input: 0 10 15 10 12 14

Output: 5 10 10 11 12.5

(10+0)/2 = 5

(15 +5)/2 = 10

(10 + 10)/2 = 10

(12 + 10)/2 = 11


The function shall take one parameter of type float and return value of type float.

/* -- function prototype-- */

float iirFilter( float input );

A hint: You can use a static variable to keep the previous output sample

Test the function to make sure it works according to the requirements.

Implement a top level function that calls iirFilter() to filter an array of signal samples.

/* -- function prototype-- */

void suppressNoise( const float inData[ ], float outData[ ], int signalLength );

Test the function to make sure it works according to the requirements.

IIR

Input

(with noise)

Output

(noise filtered out)

CSCI291 Programming for Engineers UOW

Implement the main() function that declares an array of 12 float values (initialized at

the time of declaration) and uses supressNoise() to filter them and store the result

in an array of filtered samples. The result of filtering shall be displayed with the 1-

decimal point precision.

3. Radio signals are described by complex numbers. As a result, all digital signal

processors have to support operations on complex numbers. Each complex number is

comprised of two parts: Real and Imaginary. Define a function getModulus(), that

calculates the module of a complex number according to the formula

modulus = (real2

+ imaginary2

)

1/2

The function shall take a parameter of struct type complexnumber that represents

the real part and the imaginary part of a number. The function shall return a value of type

float equal to the modulus of that complex number. To raise numbers to power of 2

and calculate a square root you can use standard function pow(x,y) and sqrt(x)

from math.h library.

float getModulus( compnumber number );

Implement the main() function that calls getModulus() to calculate modules of

three different complex numbers.

4. Implement a program that performs basic 2D geometrical transformations on points in

a 2D coordinate space.

The coordinate can be defined as a structure

typedef struct

{

float x;

float y;

}coordinate;

A point in 2D coordinate space can now be declared as a variable

Example:

coordinate pointA = { 1.0, 2.5};

Transformations to be implemented as three functions:

1. Horizontal shift:

xNew = xOriginal + horisontalOffset

2. Vertical shift:

yNew = yOriginal + verticalOffset

3. Rotation (about the origin)

xNew = cos(angle)*xOriginal + sin(angle)*yOriginal;

yNew = -sin(angle)*xOriginal + cos(angle)*yOriginal;

CSCI291 Programming for Engineers UOW

Test the functions with two different points.

Implement the main() function that

- declares a variable triangle (its type shall be defined as a nested struct with

three nodes of type coordinate)

- uses functions for three basic transformations on triangles. As you declare a new data

type for triangles, you may need to define a set of new functions, which will utilize

the low level functions defined earlier for coordinates in order to manipulate

triangles (shift horizontally, shift vertically and rotate).

- Your main program should accept data in the following format:

? P0 x y (set first triangle point)

? P1 x y (set second triangle point)

? P2 x y (set third triangle point)

? T x y (translate the triangle by x horizontally and y vertically)

? R d (rotate the triangle about the origin by d degrees)

? O (output the current coordinates of the triangle)

? Q (quit the program)

- An example run might look like this:

Output will appear here

Q

Zip all source and header files and submit to the lab3 area on Moodle.

Summary of UNIX / Linux commands

ls list files and directories

rm file remove a file

mkdir name

rm –rf name

make a directory

remove a directory

cp source destination copy files between directories

cd directory change to named directory

cd ~ change to home-directory

cd .. change to parent directory (one level up )

pwd display the path of the current directory

CSCI291 Programming for Engineers UOW

GNU gcc compilation options

$ gcc options file.c

You may not specify any option. In this case an executable a.out will be produced. Your program will not

be checked for ANSI standard compliance, some specious operations will not be reported, the code is not

optimized.

options

-o name Produce an executable with the specified name

-ansi Verify if the source code is compliant with ANSI/ISO standard

-Wall Report all warnings

To see complete list of options see gcc manual pages: $ man gcc


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp