%% Lezione del 25 novembre 2009
%
%  Soluzione
%%

clear all

%%%%%%%%%% Simulation parameters

Fs = 44100;           % sampling frequency

n = [0:Fs-1];      % discrete-time domain (1s)

D = [0:Fs-1];          % frequency domain (Fs Hz)

%%%%%%%%%% Filter specs

h = [.64693 .17654 .64693];  % filter coefficients

%%%%%%%%%% Input

x = randn(1,Fs);         % 1s gaussian noise

%%%%%%%%%% Signal processing

y = zeros(1,Fs);       % malloc

y = conv(h,x(1:Fs-2)); % y ha lunghezza Fs-2 + size(h)

%%%%%%%%%% Frequency responses

X = fft(x,Fs);
H = fft(h,Fs);
Y = fft(y,Fs);

figure(1)
semilogx(0:Fs/2-1, 20*log10(abs(H(1:Fs/2))))

figure(2)
plot(0:Fs/2-1, phase(H(1:Fs/2)))

figure(3)
semilogx(0:Fs/2-1, 20*log10(abs(X(1:Fs/2))), 0:Fs/2-1, 20*log10(abs(Y(1:Fs/2))))

%%%%%%%%%% Write wav files

wavwrite(x/max(abs(x)*1.01),Fs,'x.wav');
wavwrite(y/max(abs(y)*1.01),Fs,'y.wav');
