computer science HW

profilefaisal0z
lab_10.rtf

Name: Omar Alzaid, Adel alkanhal(partner)

Course: ECE 206

Exercise #10: C++ Programming - Finite Impulse Response Filter (using Array)

Date: 4/29/2016

Problem Statement:

A given optimal equiripple FIR filter has the following specification: Sample rate: 10 kHz (0.1 ms/sample); Passband: 0 – 2.5 kHz (lowpass), 0.5 dB maximum ripple. Stopband: 3.0 – 5 kHz, 50dB minimum attenuation

Using the Parks-Mcclellan program, we obtain the following impulse response values (scaled by 215; ie. to get actual value, divide by 215). h(0) = h(34) = 361.922 h(9) = h(25) = 812.822 h(1) = h(33) = 589.000 h(10) = h(24) = -934.419 h(2) = h(32) = 52.556 h(11) = h(23) = -1082.725 h(3) = h(31) = -538.095 h(12) = h(22) = 1547.666 h(4) = h(30) = -58.657 h(13) = h(21) = 1083.109 h(5) = h(29) = 499.472 h(14) = h(20) = -3229.928 h(6) = h(28) = -251.531 h(15) = h(19) = -1275.738 h(7) = h(27) = -785.168 h(16) = h(18) = 10268.660 h(8) = h(26) = 381.999 h(17) = h(17) = 17571.900

1. Create three arrays x[600], h[600], and y[600]

2. Fill the x array with the 600 sample values of x(t) = 100 sin (4000 π t ) for 0t < 0.06 with rate of t = 0.0001 3. Compute y[n] for 0n < 600 4. Store the 600 sample values of x[n] in file filex and store the 600 sample values of y[n] in file filey. 5. Graph x[n] and y[n] on the same graph using Excel. Compare the amplitude of the two sinewaves x[n] and y[n].

Copy of Program:

#include <iostream>

#include <fstream>

#include <cmath>

#include <iomanip>

using namespace std;

int main()

{

int count, N;

double long i[600], j[600];

double long t = 0, sum = 0;

double pi = 3.1415;

ofstream outputfilex, outputfiley;

outputfilex.open("i.txt");

outputfiley.open("j.txt");

double h[35] = {

361.922, 589.0001, 52.556, -538.095, -58.657, 499.472, -251.531,

-785.16, 381.999, 812.822, -934.41, -1082.725, 1547.66, 1083.109,

-3229.92, -1275.73, 10268.660, 17571.90, 10268.660, -1275.73, -3229.92,

1083.109, 1547.66, -1082.725, -934.41, 812.822, 381.999, -785.16,

-251.531, 499.472, -58.657, -538.095, 52.556, 589.0001, 361.922 };

for (count = 0; count < 100; count++)

{

i[count] = 100 * sin(4000 * pi * t);

t += .0001;

cout << "t = " << t << " i= " << i[count] << endl;

outputfilex << i[count] << endl;

}

for (count = 0; count < 100; count++)

{

for (N = 0; N< 35; k++)// Setting the N <35

{

sum += x[count - N] * h[k] / 32768;

}

if ((count - N) >= 0)

j[count] = sum;

else j[count] = 0;

outputfiley << j[count] << endl;

sum = 0;

}

outputfilex.close();

outputfiley.close();

system("Pause");

return 0;

}

Problems encountered : The program had error in running because the it was hard at coding the function. But then we found our errors and fixed them. Another thing we have encountered, sorting the data in text file.

Comments:

Before starting writing the code, we should always make sure that we the exact instructions.

Xl data and graphs

0

0

95.0859

0

58.8816

0

-58.6238

0

-95.1841

0

-0.31853

0

94.9868

0

59.1387

0

-58.3654

0

-95.2813

0

-0.63706

0

94.8868

0

59.3953

0

-58.1065

0

-95.3775

0

-0.95558

0

94.7857

0

59.6512

0

-57.847

0

-95.4727

0

-1.27409

0

94.6837

0

59.9066

0

-57.5869

0

-95.567

0

-1.59259

0

94.5808

0

60.1613

0

-57.3261

0

-95.6603

0

-1.91107

0

94.4769

0

60.4155

0

-57.0649

0

-95.7526

0

-2.22953

-56.2556

94.372

-92.8462

60.669

-1.23904

-56.803

92.079

-95.844

58.2585

-2.54797

-56.0026

94.2662

-92.9379

60.9219

-1.54877

-56.5406

91.9788

-95.9344

58.5063

-2.86638

-55.7491

94.1594

-93.0287

61.1742

-1.85849

-56.2775

91.8778

-96.0238

58.7534

-3.18477

-55.495

94.0516

-93.1184

61.4258

-2.1682

-56.014

91.7758

-96.1122

59

-3.50312

-55.2403

93.9429

-93.2073

61.6769

-2.47787

-55.7498

91.6729

-96.1997

59.2459

-3.82144

-54.9851

93.8333

-93.2952

61.9273

-2.78753

-55.4851

91.569

-96.2862

59.4913

-4.13972

-54.7293

93.7227

-93.3822

62.1771

-3.09715

-55.2198

91.4643

-96.3717

59.736

-4.45795

-54.473

93.6111

-93.4682

62.4262

-3.40675

-54.954

91.3585

-96.4562

59.9801

-4.77614

-54.2161

93.4986

-93.5532

62.6748

-3.71631

-54.6876

91.2519

-96.5398

60.2237

-5.09429

-53.9587

93.3852

-93.6373

62.9226

-4.02583

-54.4206

91.1444

-96.6224

60.4666

-5.41238

-53.7007

93.2708

-93.7205

63.1699

-4.33531

-54.1531

91.0359

-96.704

60.7089

-5.73041

-53.4422

93.1554

-93.8027

63.4165

-4.64475

-53.885

90.9265

-96.7846

60.9506

-6.04839

-53.1831

93.0391

-93.884

63.6625

-4.95414

-53.6164

90.8161

-96.8642

61.1916