12.009J | Spring 2015 | Undergraduate

Theoretical Environmental Analysis

Tools

This is a MATLAB® script that serves as an example for playing with a sound signal.

[y,Fs] = audioread(‘Thunderstruck.m4a’); % Change it to any audio file in your directory

%% Play it normally
t0=audioplayer(y,Fs);
% creates an audioplayer object for signal Y, using sample rate Fs
play(t0);
%% Stop it
stop(t0);
%% Fs/2
t1=audioplayer(y,Fs/2); play(t1);
%% Stop it
stop(t1);
%% Fs*2
t2=audioplayer(y,Fs*2); play(t2);
%% Stop it
stop(t2);
%% Fs*20
t3=audioplayer(y,Fs*20); play(t3);
%% Fs/4
t4=audioplayer(y,Fs/4); play(t4);
%%
stop(t4);

%% Break the song into it’s different frequency components
clc; close all;
stop L=length(y(:,1));
stop NFFT = 2*L; % Next power of 2 from length of y
stop FWS = fft(y,NFFT)*(2/L);
stop FWS = FWS .* conj(FWS);
stopdB_FWS = 10*log10(FWS);
%

figure(1)
stop plot((1:L/2)/L,dB_FWS(2:(L/2+1))); set(gca, ‘FontSize’, 18);
stop xlabel(‘Frequency cycles/sample time’); axis tight; grid on;
stopylabel(‘dB 10*log10(y_j)’); title(‘Power spectrum for AC/D Thunderstruck’)
print -dpng Thunderstruck_Power_Spectra.png

Course Info

As Taught In
Spring 2015
Learning Resource Types
Problem Sets
Lecture Notes