Int n = signal size; const double pi = 14159265358979323846


Download 9.07 Kb.
Sana31.01.2024
Hajmi9.07 Kb.
#1829056
Bog'liq
4-variant



#include
#include
#include

std::vector cosinus(std::vector signal) {


int N = signal.size();
const double PI = 3.14159265358979323846;
std::vector C;

for (int u = 0; u < N; u++) {


double sum = 0;
for (int x = 0; x < N; x++) {
sum += signal[x] * cos(((2 * x + 1) * u * PI) / (2 * N));
}
double Au = sum;
if (u == 0) {
Au /= sqrt(N);
} else {
Au *= sqrt(2 / static_cast(N));
}
C.push_back(Au);
}
return C;
}

int main() {


std::vector A = {2, 2.5, -6, 1, -2, 4.1, -5, -2, 0, 2.6, -1};
std::vector Javob = cosinus(A);

// Displaying the results


for (double value : Javob) {
std::cout << value << " ";
}
std::cout << std::endl;

return 0;


} #include
#include
#include

std::vector> cosinus(std::vector> &matrix) {


int a = matrix.size();
int b = matrix[0].size();
const double PI = 3.141592653589793;

std::vector> Javob;

for (int u = 0; u < a; u++) {
std::vector cu;
for (int v = 0; v < b; v++) {
double sum = 0;
for (int x = 0; x < a; x++) {
for (int y = 0; y < b; y++) {
sum += matrix[x][y] *
cos(((2 * x + 1) * u * PI) / (2 * a)) *
cos(((2 * y + 1) * v * PI) / (2 * b));
}
}
double term = sqrt(2.0 / a) * sqrt(2.0 / b) *
(u == 0 ? 1 / sqrt(2.0) : 1) *
(v == 0 ? 1 / sqrt(2.0) : 1) *
sum;
cu.push_back(term);
}
Javob.push_back(cu);
}
return Javob;
}

int main() {


std::vector> signal = {
{1, 2},
{3, 4}
};

std::vector> transformedSignal = cosinus(signal);

for (const auto &row : transformedSignal) {
for (double val : row) {
std::cout << val << " ";
}
std::cout << std::endl;
}

return 0;


}

Download 9.07 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling