0

I am about to present my work that I have created in MATLAB, but I am having trouble manipulating my data into a presentable form using the plot function.

My code looks like this:

[inputname, pathname] = uigetfile('*.wav', 'Select WAV-file');

thumb1 = inputname;               %# Get filename information
fprintf('\n%s is being turned into a 30s thumbnail...\n', thumb1);
fprintf('Please wait..!\n\n');
%# load the signal
[y, fs, nb] = wavread(thumb1);
y = mean(y,2);                               %# stereo, take avrg of 2 channels

%# Calculate frame energy
fWidth = round(fs*10e-3);                    %# 10ms
numFrames = floor(length(y)/fWidth);
energy = zeros(1,numFrames);
for f=1:numFrames
  energy(f) = sum( y((f-1)*fWidth+1:f*fWidth).^2 );
end

Basically I want to plot the energy of the track over time (in seconds).

plot(energy)

nearly does what I require, but I have an unusual amount of blank space at the end of the track which is not present in the .wav filealt text. This blank space is the main issue that I'm having. Ideally I would like the x axis to be displayed in seconds! Any help would be much appreciated.

edit1:

Using the first suggested method:

alt text

2 Answers 2

1

There's also

axis tight

which sets "tight" limits for the axis. See doc: http://www.mathworks.com/help/techdoc/ref/axis.html

Sign up to request clarification or add additional context in comments.

Comments

1

By default, Matlab uses some heuristic rules to choose the limits of graph scales. You can override them with the xlim and ylim functions (e.g. xlim([0 length(energy)])).

If you want to plot against actual time, you can do something like:

t = (0:length(energy)-1) / fs;  % Timebase in seconds
plot(t, energy);

3 Comments

That still isn't quite what i'm looking for i'm afraid. I've updated the original post with what it looks like using your suggestion.
@Mark: Did xlim not do what you want?
Sorry I totally glazed over that part. I apologise. @Edric's suggestion worked perfectly though, but thank you for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.