how to plot wav file in matlab

Status
Not open for further replies.

moonnightingale

Full Member level 6
Joined
Sep 17, 2009
Messages
362
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,298
Activity points
3,832
I am having a wave audio file of 5 seconds length.
I want to plot it in matlab in both time and frequency domain.
Plz tell me how can i do this
 

Hi,

Use the followings for your wave audio file:


>>[wave,fs]=wavread('your_file_name.wav'); /* read file into memory */

>>sound(wave,fs); /* see what it sounds like */

>>t=0:1/fslength(wave)-1)/fs; /* and get sampling frequency */

>>plot(t,wave); /* graph it – try zooming while its up…not much visible until you do*/

To plot in frequency domain add the followings:

>>n=length(wave)-1;

>>f=0:fs/n:fs;

>>wavefft=abs(fft(wave)); /* perform Fourier Transform */

>>plot(f,wavefft); /* plot Fourier Transform */
 
Thanks a lot Antonio, i got the time domian plot before ur reply but i was stuck with FFT and u solved my issue. great help
Ok now i want to downsample the signal with lets suppose M= 5. So first i have to use Low pass filter of 6 KHz
I know this can be done with upsample and downsample command of matlab but is there any a way i can do downsampling without built in command of matlab
thanks
 

But how do we define the location of the file that we want to read? Where will the program search for the file? Do we need to define the variables wave and fs before the below given code?

i am getting error while running the program at the line where we put "wavread" command. Please suggest a solution for this.

 

According to my understanding I think you are supposed to give absolute path or relative path and the filename in the italicized place of this code - wavread('your_file_name.wav')

- - - Updated - - -

Also in matlab it is not necessary to declare the variables. It happens on the fly.
 

you can downsample by using following MATLAB function.
function y = decimator(x,M) % x=input signal, M=Decimation factor

%% LPF Design
order = 100; % order of the filter
Wn = 1/M; % normalized cutoff frequency
b = fir1(order,Wn); % FIR LPF

y_filtered = filter(b,1,x);

%% Down Sampling
y = y_filtered(1:M:length(y_filtered)); % y=Decimated output

end % end of function

Hope this helps. If any confusion then would like to discuss it further.

- - - Updated - - -

i am getting error while running the program at the line where we put "wavread" command. Please suggest a solution for this.
The .wav file you want to read must be in MATLAB directory or else you have to give the complete path of .wav file. e.g. .wav file is located in D:/ then
[wave fs]=wavread('D:/your_file_name.wav')

Hope this helps

- - - Updated - - -

Where will the program search for the file? Do we need to define the variables wave and fs before the below given code?

The program search for the file in MATLAB directory if it is not there then you have to provide complete path of file.
No you don't have to define the variables wave and fs.

Hope this helps.
 
how to increase signal amplitude of a specific frequency for those procedures ???????????
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…