Doppler effect on non-periodic signals I would like to understand what's happening to a signal emitted from a moving source and arriving to a moving receptor. But, when I am looking on internet about Doppler effect, I can only find equations linking received frequency to emitted frequency. But what I want to do here is to simulate the Doppler effect on a random signal in Matlab.
Introduction
My idea was to see the Doppler effect as a consequence of the movement between source and receptor, I started by writing something like this :
$$S_r(\phi(t)) = S_e(t)$$
Where $S_e$ is the emitted signal, $S_r$ the received signal and $\phi(t)$ a function giving the arrival time of the signal emitted by the source at time $t$, I think the quantity $\phi(t) - t$ is called TDOA sometimes. Since I'm using classic physics here, I have $\phi(t) = t + \frac{d_t(t)}{c}$ where $d_t(t)$ is the absolute distance travelled by the signal emitted at time $t$ between the source and the receiver.
Application to a simple problem
Let's now consider a moving emitter and a immobile receiver. To simplify things, both start at the same point with $d_e(0) = d_r(0) = 0$. Taking an immobile receiver will simplify the formula of $d_t(t)$, because in this case  $d_t(t) = v_et$. Well I just have to apply my formula now, and I obtain 
$$S_r\left(t + \frac{v_et}{c}\right) = S_e(t) \implies S_r(t) = S_e\left(t - \frac{v_et}{c}\right)$$
Application to periodic wave
Well, I tried to apply this simple approach to a periodic wave of frequency $f_e$ in order to try to find the equation (which is a standard équation about Doppler effect):
$$f_{r}={\frac {c}{c-v_{e}}}\cdot f_{e}$$
So, I just took $S_e(t) = \cos\left(2\pi f_e t \right)$. And then :
$$S_r(t) = \cos\left(2\pi f_e \left(t - \frac{v_et}{c}\right)  \right) = \cos\left(2\pi f_e \frac{c - v_e}{c} t \right)$$
And I'm finally finding... $f_{r}=\frac {c-v_{e}}{c} \cdot f_{e}$.
So... the exact opposite of what I was supposed to find. And I don't understand why... (Same thing happens when I consider a moving receptor). So my first question would be to know where my mistake is... Because when I am simulating this approach with Matlab, I find the correct answer when using a periodic wave. So for me, this method seems to work...
Questions


*

*Where is my mistake when applying my approach to periodic signals ?

*Is my approach good enough to modelize Doppler effect on any kind of wave ? Can I generalize it even more ?

*How can I generalize to introduce Special relativity in my equation (in order to work with fast objects like satellites) ?


Matlab source code
    %% Configuration
    vE = 80; % Source speed (m/s)
    c = 122; % Celerity (m/s)

    d0 = 0; % Initial distance between source and receiver (m)

    nT = 1500; % Number of visible periods

    Fc = 20; % Carrier frequency
    Tc = 1/Fc; % Carrier period

    Fs = 1000; % Sampling frequency

    %% Script

    % Create signal
    At_t = 0:1/Fs:nT*Tc;
    At = cos(2*pi*Fc*At_t);

    % Apply Doppler

    dp = abs(d0 - vE .* At_t);
    dt = dp ./ c;

    % Interpolation/Resampling
    do_At_t_temp = At_t + dt;

    do_At_t = min(do_At_t_temp):1/Fs:max(do_At_t_temp);
    do_At = interp1(do_At_t_temp, At, do_At_t);

    % Plot
    figure;
    plot(At_t, At); hold on;
    plot(do_At_t, do_At);
    grid;
    legend('Without doppler', 'With Doppler');

    figure;
    [pxx,f] = pwelch(At,[],[],[],Fs);
    plot(f, pxx); hold on
    [pxx,f] = pwelch(do_At,[],[],[],Fs);
    plot(f, pxx);
    legend('Without doppler', 'With Doppler');
    xlim([0, 3*Fc])
    grid;

    fprintf('Theorical values : %d Hz and %d Hz\n', round(Fc * c / (c - vE), 2), round(Fc * c / (c + vE), 2));

This script seems to give the correct frequency shift (from 20Hz to 12.08 Hz)

 A: Let's consider a more general version of the problem first. Suppose the distance between the emitter and receiver is $d(t)$; we'll allow this to be an arbitrary function of time. We'll also suppose that the amplitude of the signal emitted as a function of time is $S(t)$, again allowing it to be an arbitrary function of time. Suppose the signal has a speed $c$, which is constant regardless of frequency. The signal emitted at time $t$ will be received at time $t+d(t)/c$, since the signal has to cross the distance $d(t)$ to get to the receiver. So we can write:
$$S(t)=S_r(t+d(t)/c)\equiv S_r(f(t))$$
where $f(t)=t+d(t)/c$. As long as $f(t)$ is invertible, we can then solve for the signal at the receiver by finding the inverse function for $f(t)$:
$$S_r(t)=S(f^{-1}(t))$$
So let's apply this to a stationary receiver at the origin, and an emitter moving with a constant velocity $v$ in a straight line directly toward or away from the receiver. Then $d(t)=|x_0+vt|$ for some initial position $x_0$, which means that 
$$f(t)=t+\frac{1}{c}|x_0+vt|$$
This gives us two separate piecewise functions: one when $t>-\frac{x_0}{v}$ and one when $t<-\frac{x_0}{v}$. Let's label these 
$$f_1(t)=t+\frac{x_0}{c}+\frac{v}{c}t=\frac{x_0}{c}+\left(1+\frac{v}{c}\right)t$$ and 
$$f_2(t)=t-\frac{x_0}{c}-\frac{v}{c}t=-\frac{x_0}{c}+\left(1-\frac{v}{c}\right)t$$
Inverting each, we have:
$$f_1^{-1}(t)=\frac{t-x_0/c}{1+v/c}$$
and
$$f_2^{-1}(t)=\frac{t+x_0/c}{1-v/c}$$
which means that 
$$S_r(t)=\begin{cases}S\left(\frac{t-x_0/c}{1+v/c}\right)&\text{for }t>-\frac{x_0}{v}\\S\left(\frac{t+x_0/c}{1-v/c}\right)&\text{for }t<-\frac{x_0}{v}\end{cases}$$
So this is the formula for a general, non-periodic signal $S$ emitted by an observer moving directly toward or away from you at speed $v$, starting from $x_0$. If we plug in a periodic function, say, $S(t)=A\cos(\omega t)$, then we have:
$$S_r(t)=\begin{cases}A\cos\left(\frac{\omega}{1+v/c}t-\frac{\omega x_0/c}{1+v/c}\right)&\text{for }t>-\frac{x_0}{v}\\A\cos\left(\frac{\omega}{1-v/c}t+\frac{\omega x_0/c}{1-v/c}\right)&\text{for }t<-\frac{x_0}{v}\end{cases}$$
When the emitter is receding from the observer, then we either have $x_0>0$ and $v>0$ or $x_0<0$ and $v<0$. This means $\frac{x_0}{v}$ is always positive, which in turn means that, for all positive $t$, we have that $t>0>-\frac{x_0}{v}$. So for a receding emitter, we use the top equation, meaning that the frequency heard from a receding emitter is
$$f_r=\frac{f}{1+v/c}$$
which is lower than the emitted frequency, as expected.
In turn, for an approaching emitter, we either have $x_0>0$ and $v<0$ or $x_0<0$ and $v>0$ (and it will only approach for a finite amount of time before passing the receiver and beginning to recede). This means that $\frac{x_0}{v}$ is negative, meaning that there is a certain time window when it is possible that $0<t<-\frac{x_0}{v}$. In that time window (i.e. the window of time when the emitter is approaching), the frequency heard at the receiver is, as you can see,
$$f_r=\frac{f}{1-v/c}$$
which is higher than the emitted frequency, again as expected.
