Signal SignalSpace::inner_product(const Signal& a, const Signal& b, double t_s, double t_e, double dt, int cnt) { assert(t_e > t_s); double t = 0.0, sum = 0.0; int i = 0, len = 0; Signal c(1 / dt, t_e - t_s); len = c.get_len(); for (t = t_s, i = 0; t < t_e; t += dt, ++i) { if (cnt && i % cnt == 0) sum = 0.0; sum += a.at_t(t) * b.at_t(t) * dt; if (i < len) c[i] = sum; } return c; }
Signal Signal::operator+(const Signal& obj) const { unsigned length = 0; double sfreq = 0.0, dura = 0.0; assert(type != SIG_COS && obj.type != SIG_COS); if (type == SIG_SAMP && obj.type == SIG_SAMP) assert(samp_freq == obj.samp_freq && len == obj.len); if (type == SIG_SAMP && obj.type == SIG_SAMP) { length = len; sfreq = samp_freq; dura = duration; } else if (type == SIG_SAMP) { length = len; sfreq = samp_freq; dura = duration; } else { length = obj.len; sfreq = obj.samp_freq; dura = obj.duration; } Signal c(sfreq, dura); for (unsigned i = 0; i < length; ++i) { if (type == SIG_SAMP && obj.type == SIG_SAMP) c.sample[i] = sample[i] + obj.sample[i]; else if (type == SIG_SAMP) c.sample[i] = sample[i] + obj.at_t(i / obj.samp_freq); else c.sample[i] = at_t(i / samp_freq) + obj.sample[i]; } return c; }