Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

. addnormplot.m: function pdfax = add_normplot(PeerAx, xrange, mu, sigma2) % pdf

ID: 3562076 • Letter: #

Question

.

addnormplot.m:

function pdfax = add_normplot(PeerAx, xrange, mu, sigma2)
% pdfax = add_normplot(PeerAx, xrange, mu, sigma2)
% Given an axis, an xrange [min, max] over which to plot
% it, add a second axis and plot a normal distribution over
% the xrange.
% mu and sigma2 are the means and variances which must be either
% scalars or row vectors. For row vectors, multiple distributions
% are plotted.
%
% Returns a handle to the new axis object


% We will get fancy and overlay a second axis on our first one
% This is somewhat complex Matlab code (not beginner stuff), but
% will produce a nice overlay of the distribution on our noise
% histogram.

% Find the parent of the peer axis so that we may put the new axis
% in the same container.
parent = get(PeerAx, 'Parent');


% Position a second axis on top of our current one.
% Make it transparent so that we can see what's underneath
% turn on the tick marks on the X axis and set up an alternative
% Y axis in another color on the right side.
pdfax = axes('Position', get(PeerAx, 'Position'), ... % put over
'Color', 'none', ... % don't fill it in
'YAxisLocation', 'right', ... % Y label/axis location
'XTick', [], ... % No labels on x axis
'YColor', 'b', ... % blue
'Parent', parent);

X = linspace(xrange(1), xrange(2), 100)'; % N points across xrange
% Preallocate fx assuming one column per pdf
sigma = sqrt(sigma2); % standard deviation
fx = zeros(length(X), length(mu));
for idx = 1:length(mu)
fx(:,idx) = normpdf(X, mu(idx), sigma(idx));
end

if length(mu) > 1
% Replicate Xs for each row so that we have one set of Xs for
% each one to plot.
X = repmat(X, [1, length(mu)]);
end
% hold is used to prevent an axis from being reset the next time
% that we plot something
hold(pdfax, 'on');
plot(pdfax, X, fx);

speech_silence_demo.m

ms_per_s = 1000; % milliseconds per second

% Read in the audio
[x, Fs] = wavread('talking.wav');
% x contains one column for each channel we recorded
% Let's assume we only have a single channel
if size(x, 2) > 1 % size(matrix, d) --> # elements along dim d
error('Single channel recordings only')
end
samples_N = size(x, 1);


% Create a time axis
t = (0:samples_N-1)/Fs;
figure('Name', 'time domain waveform');
plot(t, x);
xlabel 'Time (s)';
ylabel 'Amplitude (counts)';

% Determine intensity every N ms with no overlap
framelength_ms = 10;
intensity_dB = pcmToFramedIntensity(Fs, framelength_ms, framelength_ms, x);


% plot the intensity
figure('Name', 'Intensity')
framelength_s = framelength_ms / 1000; % framelength in seconds
t2 = (0:length(intensity_dB)-1)* framelength_s; % time axis for intensity
plot(t2, intensity_dB);
xlabel('Time (s)')
% relative as our microphone is not calibrated
ylabel('dB rel.')

figure('Name', 'Intensity Histogram')
hist(intensity_dB, 50) % hist(data, N) --> histrogram with N bins
intensityax = gca; % Save current axis for later
xlabel('dB rel.')
ylabel('Counts');

% Noise estimate
% taken from silent section at the beginning
silencestop_s = 1.3; % start to this time
silencestop_N = floor(silencestop_s / framelength_s);
silence_train = intensity_dB(1:silencestop_N);
figure('Name', 'Silence intensity estimate histogram')
hist(silence_train, 50);
silenceax = gca; % Save axis of silence distribution
xlabel('dB rel.')
ylabel('Counts');

% Make the noise intensity histogram have the same scale as the
% noise and speech intensity histogram
xrange = get(intensityax, 'XLim');
yrange = get(intensityax, 'YLim');
set(silenceax, 'XLim', xrange);
set(silenceax, 'YLim', yrange);

mu_noise = mean(silence_train);
var_noise = var(silence_train);
fprintf('Silence estimate: mean %f variance %f ', mu_noise, var_noise);

% A Normal "bell curve" probability density function (pdf)
% is defined by its mean and variance.
% Let's see how well it fits our noise histogram
noiselikelihoodax = add_normplot(silenceax, xrange, mu_noise, var_noise);

% --------------------------------------------------------------------
% Complete according to assignment instructions...

% Speech estimate
% taken fromt time 1.3 to 2.8 s
speechstart_s = 1.3; % start time
speechstop_s = 2.8; % stop time

codebook2 = [5,5,3;4,4,8]

codebook3 = [5,9,3;6,4,5;1,1,9]

feature2 = [2,2,7,8,1;3,0,1,7,8]

feature3 = [0,2,6,6,6;6,4,6,7,5;3,4,5,6,9]

Explanation / Answer

close all; n = 100; m = 10; doc=rand(n,m); figure; % obtain the handle h to the dotted lines h = normplot(doc); % define colormap g = colormap('gray'); for i = 1:m %set(h([1 11 21]),'color','r') % to set color to red %set(h([1 11 21]),'marker','o') % to change marker % mapping into greyscale color map (g has size 64x3) set(h([i i+m i+2*m]),'color',g(round(i * size(g,1)/m),:)); end