% Andre Lundkvist and Rikard Qvarnstrm
%
% Lab 1, Assignment 1
% Notch filter design
% Analysis
h = spectrum . periodogram ;
hpsd = psd (h ,x, ’Fs ’,fs);
figure ; % fig 1
plot( hpsd )
t i t l e (’Assignment 1 - Periodogram Power Spectral Density Estimate ’);
print - depsc - tiff - r300 Lab_1_Ass_1_PSD
fx = real ( ff t (x ,fs ));
freq = find (fx == max(fx )) ; % find the most dominating frequencys
freq (2) = fs - freq (2) ;
meanfreq = mean( freq ) ; % take the mean of the 2 detected peaks
%figure;
%plot(fx);
%axis([0 fs/2 min(fx) max(fx)]);
% Design
angle = 2* pi * meanfreq /fs ; % the angle for the zeroes placement
B = [1 -2* cos(angle ) cos(angle) ^2+ sin(angle ) ^2]; % polynomial coefficients
A = [1 0 0]; % two poles in the center of the unit circle
[hplot , fplot ]= freqz (B ,A,fs , fs);
figure ; % fig 2
zplane (B,A); % the pole and zeroes plot
t i t l e (’Assignment 1 - Pole / Zero plot ’);
print - depsc - tiff - r300 Lab_1_Ass_1_PZ
figure ;
% fig 3
freqzplot (hplot , fplot , ’Hz ’); % bode plot (frequency and phase)
t i t l e (’Assignment 1 - Bode plot ’);
print - depsc - tiff - r300 Lab_1_Ass_1_Bode
% Filter the input
xf = fil t e r (B , A , x);
% Play the music files
%sound(x, fs); % original file
%sound(xf, fs); % After filtering