Commit d8dd24ab authored by Colby Green's avatar Colby Green
Browse files

initial commit

parents
File added
CC = gcc
CFLAGS = -g
BIN = seqmean
SRCS = $(shell find . -name "*.c")
all: $(BIN)
clean:
rm -f $(BIN)
$(BIN): $(SRCS)
$(CC) $(CFLAGS) -o $(BIN) $^
.PHONY = all clean
#include <stdlib.h>
#include "helper.h"
void data_ctor(data *d, int size)
{
d->size = size;
d->buffer = (float *) malloc(sizeof(*d->buffer) * size);
}
void data_dtor(data *d)
{
free(d->buffer);
}
stats data_calc_stats(const data *d)
{
stats out;
float sum = 0.0f;
for (int i = 0; i < d->size; ++i) {
sum += d->buffer[i];
}
out.mean = sum / (float)(d->size);
return out;
}
#ifndef __HELPER_H__
#define __HELPER_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct data_
{
float *buffer;
int size;
} data;
typedef struct stats_
{
float mean;
} stats;
/**
* Construct a "data" object
* @param d pointer to data object
* @param size size of data buffer
*/
void data_ctor(data *d, int size);
/**
* Destruct a "data" object
* @param d pointer to data object
*/
void data_dtor(data *d);
/**
* Calculate stats on some data
* @param d pointer to data object
* @return statistics object
*/
stats data_calc_stats(const data *d);
#ifdef __cplusplus
}
#endif
#endif//__HELPER_H__
#include <stdlib.h>
#include <stdio.h>
#include "helper.h"
data *d_p;
int main(int argc, char *argv[])
{
if (argc - 1 < 1) {
fprintf(stderr,
"usage: seqmean <integer>\n"
" Calculates and prints out the mean of\n"
" the numbers from 1 to <integer>\n"
);
return 1;
}
int n;
if (sscanf(argv[1], "%d", &n) == 0) {
fprintf(stderr, "seqmean: argument '%s' was not an integer\n", argv[1]);
return 2;
}
data d;
data_ctor(&d, n);
for (int i = 0; i < d.size; ++i) {
d.buffer[i] = (float) i;
}
stats s = data_calc_stats(NULL);
data_dtor(&d);
printf("mean = %f\n", s.mean);
return 0;
}
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABDDU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ELf+oeuHThG/9wMzfQNmqFLBgjjDTIAOZjfANkeUltC9VFX6txW
1ykS4vvFotf6x+/4TrsZRiGKoyVjezyTSMiwa4f8SSKUOddGbSNyluIVQRAEYyP1imTb+p
ABuKgc+MBalbOh35L+sQFEJ2n6gvs3Qx2InjtJABZLlmrUtm4AFTWbRyQLKCaV6ycNG3TX
unEs5J93vEKVLexmAMOEnBm3NRV/VyE802LtcyNmbkhLjGCeVfUBOoeAMl+ttYRL58YflN
X1T979gHb9Uyn7ALquSI5dtX0RTr1VtxexYKjaINK4oqTxJh08wPDBvHNFeJMqX7LVgHin
hX4ydVYAir5Ku/YkbIJx5Cvg2l+FHIRvnP4GGFokxLTq6kKZ
-----END OPENSSH PRIVATE KEY-----
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDH992PR1ipe9dEE+kKSLdMnZbAE4+lgiV9zXXEZGf/QZAld+fz9+3fC7Y11zAIPgcRBt/GL2UN9ON5JRspPlW1ejond19h7ORZVj53hY0dtfp5jKE3vJKwaJaGpVJ+9cVchleugD0tL3xLx3pjBd3q1HBD4HA4Wx+b9qOLrjk01zAPIoMN4R1Tm6Kw6GuVpBKlyYLb68vOILK8HKF3UCpaJEBH1jF8plPujJpjvEhpQyB2B1FO5pW0+Wp9KRq9CQMYAWmMemZRqQdgekZOhQw/+I2F1q7+XG0P2Oi2R09IXNs9vkkhLtoxZcC+p9iWL7nZaaPpaGAXByp9mTpQHh8mL+aMQtx0Yp3GbukgRugDyjMqWsxFMQEX2myDcTiwXGKkLHAFTGLFoP72LGZTMLKweRrIEctVhkusJGc6kWoKvCO2ZtidS9crdSGALjn7Wol2FNLajow2rsWqLXvUaE21RpktFCR07sgF10DePiuUJM2o+Vn9G2FWhehgMU+3F1U= colby@Colbys-Air.attlocal.net
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.seqmean</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
CXX = g++
CXXFLAGS = -g
BIN = conv
SRCS = $(shell find . -name "*.cpp")
all: $(BIN)
clean:
rm -f $(BIN)
$(BIN): $(SRCS)
$(CXX) $(CXXFLAGS) -o $(BIN) $^
.PHONY = all clean
#include "conv.hpp"
Signal::Signal(int n)
{
this->m_buffer = new double[n];
this->m_size = n;
}
Signal::~Signal()
{
}
double &Signal::operator[](int n)
{
return this->m_buffer[n];
}
const double &Signal::operator[](int n) const
{
return this->m_buffer[n];
}
Signal Signal::convolve(Signal &h)
{
Signal &x = *this;
int xN = x.size();
int hN = h.size();
int newSize = xN + hN - 1;
Signal out(newSize);
for (int n = 0; n < newSize; ++n) {
double sum = 0.0;
for (int xI = 0, hI = n; xI < xN; ++xI, --hI) {
if (0 <= hI && hI <= hN)
sum += x[xI] * h[hI];
}
out[n] = sum / (double) newSize;
}
return out;
}
std::ostream &operator<<(std::ostream &os, const Signal &signal)
{
for (int i = 0; i < signal.size() - 1; ++i) {
os << signal[i] << ' ';
}
os << signal[signal.size() - 1];
return os;
}
#ifndef __CONV_HPP__
#define __CONV_HPP__
#include <ostream>
#include <vector>
class Signal
{
public:
Signal(int n);
~Signal();
Signal convolve(Signal &filter);
int size(void) const {return this->m_size;};
double &operator[](int n);
const double &operator[](int n) const;
private:
double *m_buffer;
int m_size;
};
std::ostream &operator<<(std::ostream &os, const Signal &signal);
#endif//__CONV_HPP__
#include <iostream>
#include "conv.hpp"
int main(int argc, char *argv[])
{
constexpr int size = 3;
Signal x(size);
Signal h(size);
// let both be rect filters
for (int i = 0; i <= x.size(); ++i) x[i] = 1.0;
for (int i = 0; i < h.size(); ++i) h[i] = 1.0;
Signal y = x.convolve(h);
std::cout << "n = " << y.size() << std::endl;
std::cout << y << std::endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment