File Exchange

image thumbnail

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

version 1.0 (2.46 KB) by

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



View License

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:

Comments and Ratings (2)

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
% The script will ask for a *.wav file. For files of about 5 minutes
% it takes about 15 minutes in my computer.
% 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:

%First load the wav
[name, path]=uigetfile('*.wav');
% name='mic-2_1minNoNoises.wav'; path='';
[signal fs]= audioread([path name]);
duration = a / fs; %Lenght in seconds.
% Initialization of movie object.
% mmObject.AudioCompressor='GSM 6.10';
% mmObject.VideoCompressor='MJPEG Compressor';
%Now the iterations process to generate the movie.

%We precharge a number of elements to acelearte process.
mygraph =figure('visible','off','position',[100,100,800,400]);
%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');
axis off
colormap hot
%To have better resolution, we print the current figure into a tiff
[X,map] = imread('temporal.tif');

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
    %Save a temporal imagen and
    [X,map] = imread('temporal.tif');
    %Add frames and audio to current video object.
    %Prepare for next step.
close (gcf)
close (mmObject)

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,

MATLAB Release
MATLAB 7.10 (R2010a)

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

» Watch video