% PhaseVocodeDemo.m
%
% written 9/27/20 - rms

% Simple scrtip to illustrate simple points of phase vocoder representation



% Read in audio and pass through LP filter method

w = hamming(320);  %assumes 16 kHz sampling, fs -= 16000
omegak = 2*pi*500; % 500 Hz ,,,, we can change as needed

[x,fs] = audioread('welcome16k.wav');
N = length(x);
n = (0:N-1)/16000;
compex = exp(-j*omegak.*n);

filtin = x.*compex';
Xnk = conv(filtin,w);

subplot(4,1,1),plot(x,'linewidth',2.5)
title('Outputs of 500-Hz channel','fontsize',14)
ylabel('x_k[n]','fontsize',12,'FontWeight','bold')
subplot(4,1,2),plot(abs(Xnk),'linewidth',2.5)
ylabel('|X[n,k]|','fontsize',12,'fontweight','bold')
subplot(4,1,3),plot(unwrap(angle(Xnk)),'linewidth',2.5)
ylabel('\angle(X[n,k])','fontsize',12,'fontweight','bold')
subplot(4,1,4),plot(angle(Xnk)/pi,'linewidth',2.5)
xlabel('n','fontsize',14,'fontweight','bold')
ylabel('\angle(X[n,k])','fontsize',12,'fontweight','bold')

return

% Now compare angles with their derivatives
angX = angle(Xnk);
angXd = conv(angX,[1,-1]);

angXuw = unwrap(angX);
angXduw = conv(angXuw,[1,-1]);


subplot(4,1,1),plot(angXuw,'linewidth',2)
subplot(4,1,2),plot(angXduw,'linewidth',2)
subplot(4,1,3),plot(angX,'linewidth',2)
subplot(4,1,4),plot(angXd,'linewidth',2)
 































































































