soundPlot - %reads in the sound file and gets the data and...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function soundPlot(fn) %Given the name of a sound (.WAV) file as a string, write a function %soundPlot, that produces two plots: % %1). a time domain plot - amplitude data vs. time (1/fs should be the % first time value) %2). a frequency domain plot - normalized magnitude vs. frequency % and finds the principal frequency of the sound file. % The plots should adhere to the following specifications: %-They should both be in the same 1x2 figure with the time domain plot % in the first position and the frequency domain plot in the second % condition %-Both plots should be plotted with blue lines %-The principal frequency should be plotted on the frequency plot with a % red x %-For the time domain plot the title should be "Time Domain Plot", the % x-axis should be labeled "time (sec)", and the y-axis should be labeled % "amplitude". %-For the frequency domain plot the title should be "Frequency Domain % Plot", the x-axis should be labeled "frequency (Hz)", and the y-axis % should be labeled "normalized magnitude". [snd fs] = wavread(fn);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %reads in the sound file and gets the data and the sampling frequency subplot(1,2,1); %first position in the subplot dt = 1./fs; duration = length(snd)./fs; %finds the duration of the sound file timevec = linspace(dt,duration,duration.*fs); %creates a time vector to plot the data against plot(timevec,snd); %plots the data title('Time Domain Plot'); xlabel('time (sec)'); ylabel('amplitude'); %labels the title and axes of the plot % subplot(1,2,2); %second position in the subplot y = 2.*abs(fft(snd))./length(snd); y = y(1:round(end/2)); %Fast-Fourier Transform equations f_nyquist = fs./2; %gets the Nyquist value freqs = linspace(0,f_nyquist,length(y)); %gets the vector for the frequency values [mx ind] = max(y); princfreq = freqs(ind); %above two lines find the maximum frequency plot(freqs,y,'b',princfreq,mx,'rx'); %plots the data title('Frequency Domain Plot'); xlabel('frequency (Hz)'); ylabel('normalized magnitude'); %labels the title and axes of the plot end...
View Full Document

This note was uploaded on 10/21/2010 for the course CS 1371 taught by Professor Stallworth during the Spring '08 term at Georgia Institute of Technology.

Ask a homework question - tutors are online