WAV read and play in a 16-bit (8kHz sampling rate) .wav file

Hi,
I got a problem on "WAV read and play in a 16-bit (8kHz sampling rate) .wav file".
The voice (sound of heart and lungs, for 14 seconds, 235KB size) wav file was record from a microphone device and could be play in Windows. When I try to play and plot the wav file in Matlab, the error message shows as below:
"??? Frequency must be a scalar
Error in ==> sound at 36 playsnd(y,fs,bits);"
----------------------------------------------------------------
Is anything wrong or missed on below source code:
----------------------------------------------------------------
clear all;close all;clc;
%=================================plot=====================================
fs = 8000;
y = wavread(C:\sound.wav);
[y,fs,16] = wavread(C:\sound.wav);
wavplay(1*y,fs,'sync');
plot(y);
title('Waveform')
%==========================================================================
Please someone helps on this problem, thanks in advance.

3 Comments

In this line
[y,fs,16] = wavread(C:\sound.wav);
The problem might be that 16 should be something wavread returns, not something you have to specify. Even though the error message does not seem to be related with that.It is just an idea,try
[y,fs,nbits] = wavread(C:\sound.wav);
instead of
[y,fs,16] = wavread(C:\sound.wav);
I still met the same problrm after modify the code, Carols... Even I copy the wav file to the same folder with the source code, the error message still the same.
And I have tried to use another wav file from my friend (he could use it in his code base), still see the error.
Thanks for all your kindly help... I will try to find some command to modify it later. Thanks!!
clear all;close all;clc;
% =================================plot=====================================
Fs = 8000;
y = wavread ('sound.wav');
[y,Fs,nbits] = wavread ('sound.wav');
wavplay(1*y,Fs,'sync');
plot(y);
title('Waveform')
%==========================================================================
??? Frequency must be a scalar
Error in ==> sound at 36 playsnd(y,fs,bits);
Which MATLAB version was being used?
What does size(y) and sie(Fs) report ?

Sign in to comment.

Answers (1)

Carlos is correct that you should not have not have an actual scalar value as the target of an assignment. It should be nbits or some similarly named output.
Actually I am very surprised that you did not get the error:
??? Error: An array for multiple LHS assignment cannot contain numeric value.
when you tried to execute that command.
Furthermore, did you leave the single quotes off C:\sound.wav? That also should have thrown an error.

Asked:

on 14 Mar 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!