This code can do this
%Voiceprint raise lower freq phase conjugate signal
tic
clear all, clc,clf,tic
%% Sound /beep calculation complete
filerawbeepStr='calculations_complete.wav';
filerawbeeppathStr='/home/rat/Documents/octave/raw/';
filevoiceprepathStr='/home/rat/Documents/octave/eq_research/main/transform/voice/';
filewavpathStr='/home/rat/Documents/octave/eq_research/main/transform/wav/';
[ybeep, Fsbeep, nbitsbeep] = wavread(strcat(filerawbeeppathStr,filerawbeepStr));
%addpath(”/home/rat/Documents/octave/eq_research/main/transform/”); %add path to location of functions
%1a voice print import
[vp_sig_orig, fs_rate, nbitsraw] = wavread(strcat(filevoiceprepathStr,'voice8000fs.wav'));
%vp_sig_orig=vp_sig_orig’;
vp_sig_len=length(vp_sig_orig);
%2a create frequency domain
ya_fft = fft(vp_sig_orig);
vp_sig_phase_orig = unwrap(angle(ya_fft));
%get Magnitude
ya_fft_mag = abs(ya_fft);
%3a frequency back to time domain
ya_ifft=real(ifft(ya_fft));
%Back to Time domain
vp_sig_new=real(ifft(ya_fft_mag.*exp(i*vp_sig_phase_orig)));
subplot(3,1,1), plot(vp_sig_orig),title('1 original time domain')
subplot(3,1,2), plot(ya_ifft),title('2 rebuild time domain')
subplot(3,1,3), plot(vp_sig_new),title('3 adjusted time')
FFT usually requires power-of-2-sized windows, so let's say just DFT (alternatively use $1024$ samples).
A sine wave with a frequency of $6\:\mathrm{Hz}$ is not orthogonal to any of the $0\:\mathrm{Hz}$, $10\:\mathrm{Hz}$, ... waves with respect to the $L^2$ scalar product over an interval of $100\:\mathrm{ms}$, so it would in fact appear in all of the bins. That's the problem with a rectangular window function: unless you happen to start with a perfect superposition of only the quantized frequency values, you will end up with a horrible smear across the whole frequency range. To avoid having to introduce a nontrivial window function here, let's talk about compactly supported signals, like wavelets, centered in our DFT window. As you certainly know, such functions always have an intrinsic frequency indeterminacy, which essentially means that the (infinite) Fourier transform consists not of sharply defined (dirac) peaks but of Gaussian-like bell peaks. If the time confinedness was $100\: \mathrm{ms}$, the frequency indeterminacy will be more than $\frac1{100\:\mathrm{ms}}=10\:\mathrm{Hz}$. So as you see, the width of the DFT bins is not just a technical issue with the specific Fourier transform algorithm, it represents the general inability to define the frequency of a "correctly processable" signal more precisely than the bin width.
You probably know this already. Anyway, let's have a look now at a wavelet with a frequency centered about $60\:\mathrm{Hz}$, like you would get when window-functioning mains hum. Assuming the freq indeterminacy gets no bigger than necessary, this will give you a pretty sharp peak in the $55$ to $65\:\mathrm{Hz}$ bin, with only small values in the neighbouring bins - so we can approximate the total energy, that is, the $L^2$ norm of our signal, by just the square of the value in this bin (that's due to Bessel's equality). Likewise, if you were interested in the energy between $45$ and $105\:\mathrm{Hz}$, you would just sum up the squared values of those bins and get, correctly, the total energy of the wavelet. Where it gets interesting is when you want to know about the energy in the range $61$ to $63\:\mathrm{Hz}$. According to your proposal, this should be calculated as $\tfrac15$ of the squared value in the $55$ to $65\:\mathrm{Hz}$ bin, that is, $\tfrac15$th of the total energy of our wavelet. And that's pretty good actually, because as we said the energy of this wavelet is actually smeared over an interval of $10\:\mathrm{Hz}$ about $60\:\mathrm{Hz}$, so it's quite a reasonable approximation to say $\tfrac15$th of it is in the range $61$ to $63\:\mathrm{Hz}$!
What about a wavelet centered about $65\:\mathrm{Hz}$? If we DFT this, it will appear in both the $55$ to $65\:\mathrm{Hz}$ and $65$ to $75\:\mathrm{Hz}$ bins, with each values of $\sqrt{\tfrac12}$ of the total amplitude. If you now calculate the energy between $45$ and $105\:\mathrm{Hz}$, you will get
$$
0 + \sqrt{\tfrac12}^2E + \sqrt{\tfrac12}^2E + 0 + 0 = E
$$
so that's again the total energy, correctly. If you want the energy between $55$ and $65\:\mathrm{Hz}$, you get
$$
\sqrt{\tfrac12}^2E = \frac{E}2
$$
which is pretty reasonable, because in fact only about half of the signal energy lies in this band.
But where you start getting weird results is when you calculate the energy between $55$ to $56\:\mathrm{Hz}$, which results in
$$
\frac1{10}\sqrt{\tfrac12}^2E = \frac{E}{20}
$$
and compare it with the energy between $65$ to $66\:\mathrm{Hz}$, for which you would obviously get the same result. But then, the actual wavelet does not really have any notable frequency component at $55$ to $56\:\mathrm{Hz}$ at all, while $65$ to $66\:\mathrm{Hz}$ is where it is strongest!
In conclusion: it does make sense to do this interpolation, but it should be handled with care.
As I just notice, what you do is in fact not a linear interpolation, but just a $0$th order domain extension. A linear or higher-order interpolation would suffer less from the problem I just explained.
Best Answer
Two (maybe three) things are going on.
First, atan2() will only ever return angles in the interval $(-\pi, \pi]$. It can't possibly know how many times you've wrapped around by $2\pi$ radians. You should notice that
$$-2.558724 \space \mathrm{rad} + 2\pi(5) \space \mathrm{rad} + \pi \space \mathrm{rad}= 32 \space \mathrm{rad}$$
which shows $5$ full rotations that atan2() couldn't possibly know about. But you also seem to have an error of $\pi$ radians, so where is that coming from?
Seconds, let's look at the Fourier Transform of
$$y = A \cos(2\pi f_ct+\phi_0)$$ $$\begin{align*}\mathscr{F}\{y\} &= \int_{-\infty}^{\infty} A \cos(2\pi f_ct+\phi_0) e^{-2\pi i s t} \mathrm{d}t \\ &= \dfrac{A}{2}\left[\int_{-\infty}^{\infty} e^{i(2\pi f_ct+\phi_0)} e^{-2\pi i s t} \mathrm{d}t + \int_{-\infty}^{\infty} e^{-i(2\pi f_ct+\phi_0)} e^{-2\pi i s t} \mathrm{d}t\right]\\ &= \dfrac{A}{2}\left[e^{i\phi_0}\int_{-\infty}^{\infty} e^{-2\pi i (s-f_c) t} \mathrm{d}t + e^{-i\phi_0}\int_{-\infty}^{\infty} e^{-2\pi i (s+f_c) t} \mathrm{d}t\right]\\ &= \dfrac{A}{2}\left[e^{i\phi_0}\delta(s-f_c) + e^{-i\phi_0}\delta(s+f_c)\right]\\ \end{align*}$$
Note how the phase term of the delta function sitting at the negative frequency, $\delta(s+f_c)$, has a negative phase, $e^{i(-\phi_0)}$. That could be a problem if you've selected that peak, but I doubt it in this case.
Third, two nuances of the DFT that most people don't immediately realize is that the phase is relative to the first element of the time series data ($t=0$ is the time of the first time series data point), and that the time series data is cyclic as far as the DFT math is concerned (the second half of your time series data can be used for the negative time values with the time index of the last element of the time series being just less than $t=0$).
Your cosine wave is shifted to the right in time, as far as the DFT is concerned. This will result in a modulation by a frequency dependent complex exponential in the frequency domain, and will impart a frequency dependent phase rotation on the peak you are examining.
This property of the DFT is likely giving you the additional phase shift of $\pi$ in your code. Fix your cosine time series data so that the first element corresponds to $t=0$, to get rid of this problem.