Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Number 2(a-f) using C coding language Write a function to generate samples of th

ID: 3935109 • Letter: N

Question

Number 2(a-f) using C coding language Write a function to generate samples of the ramp function. Write an analytic expression for.y. Suppose we want to create a plot of the ramp function from t = 0 to t = 2 using a step size of 0.1. Write the numbers that need to be created and stored for the t-samples and the y-samples. Write a compact expression for the ith component of the x samples Write a compact expression for the ith component of the y samples Write a program to compute and store the x and y samples. Write the samples to a file in a 2-column format.

Explanation / Answer

#include <iostream>

#include <cmath>

#include <iomanip>

using namespace std;

void createFilter(double gKernel[][5])

{

    // set standard deviation to 1.0

    double sigma = 1.0;

    double r, s = 2.0 * sigma * sigma;

    // sum is for normalization

    double sum = 0.0;

    // generate 5x5 kernel

    for (int x = -2; x <= 2; x++)

    {

        for(int y = -2; y <= 2; y++)

        {

            r = sqrt(x*x + y*y);

            gKernel[x + 2][y + 2] = (exp(-(r*r)/s))/(M_PI * s);

            sum += gKernel[x + 2][y + 2];

        }

    }

    // normalize the Kernel

    for(int i = 0; i < 5; ++i)

        for(int j = 0; j < 5; ++j)

            gKernel[i][j] /= sum;

}

int main()

{

    double gKernel[5][5];

    createFilter(gKernel);

    for(int i = 0; i < 5; ++i)

    {

        for (int j = 0; j < 5; ++j)

            cout<<gKernel[i][j]<<" ";

        cout<<endl;

    }

}