# Adding a signal to a time series

Discussion in 'Mac Programming' started by dukebound85, Feb 7, 2012.

1. Feb 7, 2012
Last edited: Feb 7, 2012

### dukebound85 macrumors P6

Joined:
Jul 17, 2005
Location:
5045 feet above sea level
#1
How would one go about adding a signal (such as a sin wave) to a time series?

For instance, I would like a period to occur every time step

Thanks

2. Feb 7, 2012
Last edited: Feb 7, 2012

### chown33 macrumors 604

Joined:
Aug 9, 2009
#2
If there's one period of the sine wave at every time step, then the contribution from the sine wave is constant. The value of the constant depends on the phase of the sine wave relative to your time sample.

If the above isn't clear, draw it on some graph paper. Assume each vertical line on the graph paper is a sample point. Draw a sine wave whose period is identical to the vertical lines of the graph paper (one cycle per space between vertical lines). What is the value of the sine wave at each vertical line?

If the vertical lines represent the samples of your time series, then what is the sine wave's value at each sample point?

If you change the phase of the sine wave with respect to the vertical lines (sample points), but keep the sine's period at 1 cycle per sample interval, what changes? For example, if the phase is 1/4-waveform (90 degrees), what changes at each sample point?

For reference, look up "Nyquist frequency" and "Shannon sampling theorem", and see what "aliasing" means as a DSP term.

If you want to add a sine wave whose period is less than your sampling frequency, then use the sin() function to calculate it based on the ratio of your sine frequency to your sampling frequency. Example: for a sine wave of 100 Hz, and a sampling frequency of 1 Khz, you have 10 sample points per sine period. Since sin() is circular, that means 2pi = 10 sine-wave samples.

The equations aren't that hard to work out if you apply basic algebra. I think it's worthwhile to know how to develop the equations, because it will give you a better sense of how signals are related to sampled data.

3. ### dukebound85 thread starter macrumors P6

Joined:
Jul 17, 2005
Location:
5045 feet above sea level
#3
Thanks I will attempt to answer these questions

This would be the value of the initial time series at whatever sampling frequency

If the frequency would shift, then the value of the series would be the inital time series plus the amplitude of the sine wave at that corresponding shift

Will do

So if my sampling period in my initial time series is 1 per day, but want to add in a sin wave that has a period that completes in say 3 days, the frequency would be (1/3)? I will be looking more into this but it has been a while.

I agree. Thanks for the pointers