Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Animation *.wav to *.avi spectrum animation generator.

Be the first to rate this file! 2 Downloads (last 30 days) File Size: 2.46 KB File ID: #38314 Version: 1.0
image thumbnail

Animation *.wav to *.avi spectrum animation generator.

by

Héctor Corte (view profile)

 

This script takes an audio file in *.wav and converts it into an *.avi animation using its spectrum.

| Watch this File

File Information
Description

This script takes an audio file in *.wav format and converts it into an *.avi animation using its spectrum.
It uses a STFT to generate the espectrum of the sound in current time and some seconds ago.
Ploting this spectrum and adding frames to a video object it manages to generate an *.avi with the sound ant an animation of its spectrum.
An example of the output:
http://www.youtube.com/watch?v=sbAdta_qu4A

Required Products Signal Processing Toolbox
MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
25 May 2016 Devid Bianco

It may be helpful for someone, this code now works for me in newer version of matlab

%%%Create spectrum movie from *.wav files
%%%It will take a while to make the video.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%wav2mov is a simple srcipt to turn a audio *.wav file into a video of
%evolving spectrum
%
%
%
% INPUTS:
% The script will ask for a *.wav file. For files of about 5 minutes
% it takes about 15 minutes in my computer.
%
%
%
% OUTPUTS:
% Once it is finished in the current folder you will find an *.avi file with the generated video already compresed to upload for ecample in youtube.
%
%
%
%This function was written by :
% Hctor Corte
% B.Sc. in physics 2010
% M.Sc. in physics of complex systems 2012
% Battery Research Laboratory
% University of Oviedo
% Department of Electrical, Computer, and Systems Engineering
% Campus de Viesques, Edificio Departamental 3 - Office 3.2.05
% PC: 33204, Gijn (Spain)
% Phone: (+34) 985 182 559
% Fax: (+34) 985 182 138
% Email: cortehector@uniovi.es
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%First load the wav
[name, path]=uigetfile('*.wav');
% name='mic-2_1minNoNoises.wav'; path='';
[signal fs]= audioread([path name]);
[a,b]=size(signal);
duration = a / fs; %Lenght in seconds.
nSec=duration;
% Initialization of movie object.
%Video
frameRate=10;
mmObject=VideoWriter([name,'.avi']);
% mmObject.AudioCompressor='GSM 6.10';
% mmObject.VideoCompressor='MJPEG Compressor';
%Audio
nFrames=nSec*frameRate;
audioFrames=buffer(signal(:,1),round(length(signal(:,1))/nFrames));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Now the iterations process to generate the movie.

%We precharge a number of elements to acelearte process.
numelelements=ceil(a/nFrames);
mygraph =figure('visible','off','position',[100,100,800,400]);
ini=1;
fin=(ini+ceil(a/nFrames)*50)*(ini+ceil(a/nFrames)*50<a)+a*(ini+ceil(a/nFrames)*50>=a);
%Each channel has it's own spectrum
[~,F,T,P] = spectrogram(signal(ini:fin,1),200,80,200,10);
surf(T,F(1:40,1),10*log10(P(1:40,:)),'edgecolor','none'); axis tight;
[S,F,T,P] = spectrogram(signal(ini:fin,2),200,80,200,10);
surf(T,F(1:40,1),10*log10(P(1:40,:)),'edgecolor','none'); axis tight;
%xlabel('Time (Seconds)'); ylabel('Hz');
view(145,65)
axis off
colormap hot
%To have better resolution, we print the current figure into a tiff
%image
print('-dtiff','-r90','temporal')
[X,map] = imread('temporal.tif');
F=im2frame(X,map);
open(mmObject);

for ind=1:nFrames

%This is the same as before, calculate de spectrum of the two channels
%and plot it.
[~,F,T,P] = spectrogram(signal(ini:fin,1),200,80,200,10);
surf(T,F(1:40,1),10*log10(P(1:40,:)),'edgecolor','none'); axis tight;
hold on
[S,F,T,P] = spectrogram(signal(ini:fin,2),200,80,200,10);
surf(T,-F(1:40,1),10*log10(P(1:40,:)),'edgecolor','none'); axis tight;
%Make some graphical changes
hold off
axis off
view(125,55)
%Save a temporal imagen and
print('-dtiff','-r70','temporal')
[X,map] = imread('temporal.tif');
F=im2frame(X,map);

%Add frames and audio to current video object.
writeVideo(mmObject,F.cdata);

%Prepare for next step.
ini=(ini+ceil(a/nFrames))*(ini+ceil(a/nFrames)<a)+a*(ini+ceil(a/nFrames)>=a);
fin=(ini+ceil(a/nFrames)*30)*(ini+ceil(a/nFrames)*30<a)+a*(ini+ceil(a/nFrames)*30>=a);

end
set(gcf,'visible','on');
close (gcf)
close (mmObject)

Comment only
27 Oct 2012 Chris Stockmann

Very neat project -- thanks for posting this.

For those of us who are using R2012b the signalblks feature has been removed. If anyone could help me learn how to initialize the movie object without this feature I would be greatly appreciative.

Many thanks,
Chris

Comment only

Contact us