clear clc pause on % Read in the sound data [d,rate] = audioread('Lead Voc Stem.wav'); [d2,rate2] = audioread('Rihanna Umbrella.wav'); d = d(:,1); d2 = d2(:,1); % rate = the sampling rate % d = the data %trim the sound data d = d(1000000:2000000); % d2 = d2(1000000:2000000); %Pass sound data through a bandpass filter %filter bounds determined by looking at instantaneous frequency plot df = bandpass(d,[100 3000],rate); % df2 = bandpass(d2,[100 3000],rate); %calculate instantanous frequency of the filtered signal with time [instf,t] = instfreq(df,rate); % [instf2,t2] = instfreq(df2,rate2); %Normalize the filtered instantanous frequency intensity = (instf-min(instf))/(max(instf)-min(instf)); % Take a listen sound(d,rate); %% color setting elements = size(intensity); r = zeros(elements); g = zeros(elements); b = zeros(elements); for i = 1:elements(1) if (0<=intensity(i) && intensity(i)<0.33) r(i) = 255*(1 - 3*intensity(i)); g(i) = 255*3*intensity(i); b(i) = 0; elseif (0.33<=intensity(i) && intensity(i)<0.66) r(i) = 0; g(i) = 255*(1 - 3*(intensity(i) - 0.33)); b(i) = 255*3*(intensity(i) - 0.33); elseif (0.66<=intensity(i) && intensity(i)<=1) r(i) = 123*3*(intensity(i) - 0.66); g(i) = 0; b(i) = 255 - 122*3*(intensity(i) - 0.66); end end rgb(1,:) = fix(r(:)); rgb(2,:) = fix(g(:)); rgb(3,:) = fix(b(:));