% Simple manipulation of sounds
% Assume that x is already recorded for 2 seconds at 11025 Hz sampling rate
% 8/22/97 - rms

% Original sound
specgram(x,256,11025);
pause
sound(x,11025)
wavwrite(x,11025,'orig.wav')
pause

% Downsampling ("speed up")
y = resample(x,1,2);
subplot(2,1,1),stem(x(1,1:101))
axis([0 100 -.015 .015])
xlabel('n');ylabel('x[n]');
subplot(2,1,2),stem(y(1,1:51))
axis([0 50 -.015 .015])
xlabel('n');ylabel('y[n]');
pause
subplot(1,1,1),specgram(y,256,11025);
pause
sound(y,11025)
wavwrite(y,11025,'downsamp.wav')
pause

% Upsampling ("slow down")
y = resample(x,2,1);
subplot(2,1,1),stem(x(1,1:101))
axis([0 100 -.015 .015])
xlabel('n');ylabel('x[n]');
subplot(2,1,2),stem(y(1,1:201))
axis([0 200 -.015 .015])
xlabel('n');ylabel('y[n]');
pause
subplot(1,1,1),specgram(y,256,11025);
pause
sound(y,11025)
wavwrite(y,11025,'upsamp.wav')
pause


% Original sound
specgram(x,256,11025);
pause
sound(x,11025)
pause


% Lowpass filtering
N = 4;Rp = 5;Rs = 40;
Wn = .15;

[B,A] = ELLIP(N,Rp,Rs,Wn);
y = filter(B,A,x);
subplot(2,1,1),stem(x(1,1:101))
xlabel('n');ylabel('x[n]');
subplot(2,1,2),stem(y(1,1:101))
xlabel('n');ylabel('y[n]');
pause
subplot(1,1,1),specgram(y,256,11025);
pause
sound(y,11025)
wavwrite(y,11025,'lpf.wav')
pause


% Highpass filtering
[B,A] = ELLIP(N,Rp,Rs,Wn,'high');
y = filter(B,A,x);
subplot(2,1,1),stem(x(1,1:101))
xlabel('n');ylabel('x[n]');
subplot(2,1,2),stem(y(1,1:101))
xlabel('n');ylabel('y[n]');
pause
subplot(1,1,1),specgram(y,256,11025);
pause
sound(y,11025)
wavwrite(y,11025,'hpf.wav')
pause

% 
