matlab help , Digital signal processing

Thread Starter

dina

Joined Nov 12, 2006
19
hi...
i need to make some tests on audio signals for a school project using matlab, and i need a code to frame the signal... am a beginner in matlab, so i can't write the code myself..
i'd appreciate any help
Thank you
 

Dave

Joined Nov 17, 2003
6,970
Hi dina,

Can you remind us again of what you mean by "frame the signal"?

Can you also provide the signal (i.e. the matrix) with which you need to process?

Dave
 

Thread Starter

dina

Joined Nov 12, 2006
19
hi again...
signals i meant i need to sample are wav files(songs)..
i need this for my graduation project where am supposed to insert a watermark....but first i need to sample the song .....

thank you for your help
 

Dave

Joined Nov 17, 2003
6,970
Hi dina,

To understand your your wav-file data you will need the following Matlab functions:

wavinfo

wavread

Open Matlab and on the Menu bar select Help>Matlab Help

This will open the Matlab help window. Select the Matlab "Search" tab and type "wavinfo" and "wavread" this will give you the description and more importantly the syntax for reading the wav file into Matlab.

I recommend you type the following at the Matlab command prompt:

Rich (BB code):
[m d] = wavfinfo(filename);

[y,Fs,bits] = wavread(filename);
Where filename is the name of the wav-file. Remember to put the filename in inverted commas: i.e. => '<filename>'

This will return the contents of your file. What are the results?

From this we should have some infomation about your data.

Dave
 

Thread Starter

dina

Joined Nov 12, 2006
19
hi...
first i want to thank you for your attention....
but i have no problem reading a wav file ....
and actually i have another question, how can i process an mp3 file in matlab
how can it be read?
Thanks
 

Dave

Joined Nov 17, 2003
6,970
Hi dina,

To read and write mp3 files you can use the following functions from Columbia University:

Rich (BB code):
mp3read which is similar to wavread

mp3write which is similar to wavwrite
See http://labrosa.ee.columbia.edu/matlab/mp3read.html

You will need to download some mp3info binaries (also available from the above link) to manipulate mp3 files using Matlab under Windows.

Edit: The necessary files are available as a download over at Matlab File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=6152&objectType=file

You may also be interested in looking at the mmread function: http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=8028&objectType=file

Dave
 

Ron_7

Joined Dec 18, 2006
8
hey guys,

i too am doing a watermarking project for my graduation. however i am having trouble with the spectral analysis of the signal using the FFT function within matlab.

so far i have read in the .wav file like this:

[data,fs,nbits] = wavread("host.wav");

then i go onto FFT function

data_fft = fft(data);

is this correct? because when i plot data_fft it looks nothing like a wave.

Please can you help. thanks in advance

Ron
 

Dave

Joined Nov 17, 2003
6,970
hey guys,

i too am doing a watermarking project for my graduation. however i am having trouble with the spectral analysis of the signal using the FFT function within matlab.

so far i have read in the .wav file like this:

[data,fs,nbits] = wavread("host.wav");

then i go onto FFT function

data_fft = fft(data);

is this correct? because when i plot data_fft it looks nothing like a wave.

Please can you help. thanks in advance

Ron
Sadly I don't have Matlab to hand, but if I recall data from wavread is the sampled data sampled at fs frequnecy - correct? Then the fft function should compute your FFT for the data (both real and complex components).

As for what you are trying to achieve with spectral analysis, then that is a different thing. Typically you would need to compute the power:

Try the following code:

Rich (BB code):
[data,fs,nbits] = wavread("host.wav"); % Read wav file
data_fft = fft(data); % Perform FFT
P_data_fft = data_fft.* conj(data_fft) / size(data_fft,2); % Deduce Power Spectra
f = 1000*(0:(size(data_fft,2)))/size(data_fft,2); % Define frequency range over which to plot power spectra. This is half the size of the fft since there is merely a reflection around the dc point
plot(f,P_data_fft(1:(size(data_fft,2)+1))) % Plot
That should give you the power density from which you can perform your spectral analysis. You may need to debug the code slightly since I have written it in Octave and not had the chance to test it in Matlab.

Dave
 

Thread Starter

dina

Joined Nov 12, 2006
19
Hi
i have another question ...it's regarding the svd on an audio file..

first i used the wavelet transform on the audio file ,then i performed the svd function in matlab... i used one of the detailed coefficients as an input for the svd function but since it's a one dimentional matrix, i got an output of a single value... can anyone tell me how can i use the svd and and still have a matrix as an output....
thank you
 

Dave

Joined Nov 17, 2003
6,970
Although I tend to discourage the use of for-loops in Matlab, couldn't you declare an empty array and populate by iteration through the for-loop. For example:

Rich (BB code):
arr = zeros(x,y); % Multi-dimensional array of dimensions x-by-y
 
for i = 1:size(arr,2)
for n = 1:size(arr,1)
 
arr(n,i) = svd(input); 
% Use the svd function to compute your single value, use the for-loop iterations, n and i, to place the computed value in the multidimensional array
 
end
end
So long as either arr isn't to big, or time is not a major consideration then this is the approach I would take.

Dave
 

Thread Starter

dina

Joined Nov 12, 2006
19
hi dave
first thank you...
i tried what u suggested but i got out an array of the same value(that not what i want).. but i had another idea that is to build a matrix (where each row represent a frame of the signal) then perform the svd...

am still not sure if that'll work, but am working on it.

actually i need a function to convert the frames to an audio file ...
so if anyone can provide such a tool ... i'll be thankful
 

Dave

Joined Nov 17, 2003
6,970
hi dave
first thank you...
i tried what u suggested but i got out an array of the same value(that not what i want).. but i had another idea that is to build a matrix (where each row represent a frame of the signal) then perform the svd...

am still not sure if that'll work, but am working on it.
That is correct if you supply the same input for each iteration of the for-loops. Essentially you should provide one input per loop iteration (i.e. one value from your one-dimensional matrix input) to obtain the results, hence:

Rich (BB code):
arr(n,i) = svd(input(n,i));
Is a more accurate statement of the code you need.

actually i need a function to convert the frames to an audio file ...
so if anyone can provide such a tool ... i'll be thankful
I will have a look around to see what I can find.

Dave
 

Thread Starter

dina

Joined Nov 12, 2006
19
hi
am gonna fully explain what am doing...

my project is Digital Audio Watermarking
i inserted a wav file ...performed wavelet transform .... took the 3-level detailed coefficient and framed it (i have a function ,where the output is a matrix ,in which each row represents a frame) then i inserted my watermark
and i need to reconstruct the modified 3-level detailed coefficient to reconstrut the watermarked audio file

what i tried to do is the following
d=[];
for k=1:fr
d=[d ; [framedfd3(k,1:Samples)]'];
end
where d is the modified 3-level detailed coefficient
framedfd3 is the matrix of frames
samples =no. of samples per frame
fr = no. of frames
 

Dave

Joined Nov 17, 2003
6,970
I'm sorry but I'm out of my depth with 3-level detailed coefficients, so I cannot offer any advice. Essentially once you have derived the modified 3-level detailed coefficient you need to look at converting the modified 3-level detailed coefficient matrix, d, into the data values for each channel (this may not be a consideration if you only have one channel) and then writing your wav-file (I am assuming you are going back to a wav file) using the wavwrite function.

You may find the following discussion (including Matlab code) of use: http://www.owlnet.rice.edu/~rwagner/steg.html#intro - although this is focused around image rather than audio watermarking.

Dave
 

Ron_7

Joined Dec 18, 2006
8
Sadly I don't have Matlab to hand, but if I recall data from wavread is the sampled data sampled at fs frequnecy - correct? Then the fft function should compute your FFT for the data (both real and complex components).

As for what you are trying to achieve with spectral analysis, then that is a different thing. Typically you would need to compute the power:

Try the following code:

Rich (BB code):
[data,fs,nbits] = wavread("host.wav"); % Read wav file
data_fft = fft(data); % Perform FFT
P_data_fft = data_fft.* conj(data_fft) / size(data_fft,2); % Deduce Power Spectra
f = 1000*(0:(size(data_fft,2)))/size(data_fft,2); % Define frequency range over which to plot power spectra. This is half the size of the fft since there is merely a reflection around the dc point
plot(f,P_data_fft(1:(size(data_fft,2)+1))) % Plot
That should give you the power density from which you can perform your spectral analysis. You may need to debug the code slightly since I have written it in Octave and not had the chance to test it in Matlab.

Dave
Thankyou very much Dave, this was a great help. i had to adjust some of the code to work correctly with the rest of my code in matlab but it works like a dream.

Ps: sorry for late reply as i've been away on a training course
 

Ron_7

Joined Dec 18, 2006
8
sorry guys, just another quick question. i'm now currently coding the basilar membrane spreading function:

B(z) = 15.91 + 7.5(z+0.474)-17.5sqrt(1+(z+0.474)^2)

where z is the normalised bark scale.

the question is how do i normalize the bark scale? at the moment i've translated the frequency into the bark scale using te formula

z=13*atan(0.76*f/1000)+3.5*atan((f/7500)^2);

do i have to put it into powers of 10? if so how?

Thanks in advance.
 

Thread Starter

dina

Joined Nov 12, 2006
19
hi ....

how r you all....

am working now on a scheme to embedd a binary image in an audio file
and i wanted to ask if anyone can provide for me a matlab function that can return the no. of row pixels and column pixels for a certain image....

thank you very much in advance....
 
Top