Solved

get a frequency

Posted on 2009-05-07
3
591 Views
Last Modified: 2013-11-25
hi,,,
i am working on a sound file called (hpn.wav), i have no problem getting into the file to analize it by getting its frequencies,  playing it, filtering it on the command window, but i have problem finding right codes for the same functionality on M-File which i have multiple buttons on a GUI (which i have already made), i know i have to use (collback) method and i recenlty managed to only play the sound file  by using this code {   'Callback', 'hpn=wavread(''hpn.wav'');wavplay(hpn);');   }  
can anyone please help me with code for getting frequencies, filtter, and plot the frequencies using callback method through a button on my GUI..

please find the codes i have used on my command window for the opreation, which those codes are the one i like them to be converted to a type of code to be recognized be the M-File using callback method
>> [hpn,fs]= wavread('hpn.wav');
>> size (hpn)                      %this is to read the size of the file
 
ans =
                    55125
 
 
>> [hpn,f] = wavread('hpn.wav')
>> wavplay (hpn,f)                 %this is to get the frequenciy
 
f = 
                       11025
 
 
 
 
>>subplot(2,1,1), plot (hpn) , title('Entire Waveform');
 
>> fNorm = 200 /  (fs/2);    %filtriing the sound file starts from here!
>> [b,a] = butter (10, fNorm, 'low');
>>hpnlow = filtfilt (b,a,hpn);
>> freqz(b,a,128,fs);
>> wavplay (hpnlow, fs);

Open in new window

0
Comment
Question by:ferman-k
  • 2
3 Comments
 
LVL 15

Expert Comment

by:yuk99
ID: 24327684
You made GUI as a function. I would advice you to use GUIDE instead? Much easier to draw a GUI, generate callbacks, etc.
See GUIDE docs as a starting point:
http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/bqz79mu.html

You can find there also how to create callback function programmatically.

If you will have problems and need help, please attach here all the files related to the project, so we can reproduce it.
0
 

Author Comment

by:ferman-k
ID: 24331358
because i got use to building the GUI from M-File window i cannot understand so much from GUIDE,,, here i would like to send you my entire code and i will be thankful if you just correct the errors or might be replace any code for right one to allow the programme function correctly....

thank you
%*********Area One
 
function Sound_Filter
%*********Area Two
%this area is is responsible for generating a plain GUI 
set(0, 'Units', 'normalized');
Ssize = get(0, 'Screensize');
 
H.gui = dialog('WindowStyle', 'normal', ...
                'Resize', 'on', ...
                'Name', 'Sound_Filter', ...
                'Units', 'normalized', ...
                'Position', [Ssize(3) / 4 Ssize(4) / 2 0.6 0.3]); 
            
 %**********Area Three
 
                DefOutPos = get(H.gui, 'OuterPosition');
set(H.gui, 'UserData', DefOutPos);
 
%Create top-level Menu
Hm = uimenu('Parent', H.gui, 'Label', 'Option');
uimenu('Parent', Hm, ...
        	 'Label', 'plot', ...
       	 'Callback', 'plot (axes, 2:5)');
 
 %****************Area Four 
 
  %user can use the button to execute what we want, or use 
   %option2 to do the same
Hbutton = uicontrol('Parent', H.gui, ...
                    'Style', 'pushbutton', ...
                    'Units', 'normalized', ...
                    'Position', [0.0 0.5 0.2 0.1], ...
                    'String', 'Play!', ...
                    'Callback', 'hpn=wavread(''hpn.wav'');wavplay(hpn);');%this line
                %code allow the button 'PLAY' to excute which means play
                %the sound file called 'deng'.
                %however, here that fact is proved that MATLAB can have GUI
                %with functional object tools to perform operation same as
                %other application such as C#, C++ or V.B 
                
                
 
 
     
%*******Area five
 
Hbutton = uicontrol('Parent', H.gui, ...
                    'Style', 'pushbutton', ...
                    'Units', 'normalized', ...
                    'Position', [0.0 0.3 0.2 0.1], ...
                    'String', 'Filter Sound!', ...
                    'Callback', 'subplot(2,1,1), plot (hpn) , title('Entire Waveform');');
                     [hpn,fs]= wavread('hpn.wav');
                      size (hpn)
                    [hpn,f] = wavread('hpn.wav')
                    wavplay (hpn,f)
 
                
%*******Area Six
 
Hbutton = uicontrol('Parent', H.gui, ...
                    'Style', 'pushbutton', ...
                    'Units', 'normalized', ...
                    'Position', [0.0 0.1 0.2 0.1], ...
                    'String', 'Get Frequency!', ...
                    'Callback', 'subplot(2,1,1), plot (hpn) , title(Entire Waveform)');
             
                
                
                
                
                

Open in new window

0
 
LVL 15

Accepted Solution

by:
yuk99 earned 500 total points
ID: 24332161
OK. Here is your code with errors corrected. Notice I didn't add any functionality.
%*********Area One
 
function Sound_Filter
%*********Area Two
%this area is is responsible for generating a plain GUI 
set(0, 'Units', 'normalized');
Ssize = get(0, 'Screensize');
 
H.gui = dialog('WindowStyle', 'normal', ...
                'Resize', 'on', ...
                'Name', 'Sound_Filter', ...
                'Units', 'normalized', ...
                'Position', [Ssize(3) / 4 Ssize(4) / 2 0.6 0.3]); 
            
 %**********Area Three
 
                DefOutPos = get(H.gui, 'OuterPosition');
set(H.gui, 'UserData', DefOutPos);
 
%Create top-level Menu
Hm = uimenu('Parent', H.gui, 'Label', 'Option');
uimenu('Parent', Hm, ...
                 'Label', 'plot', ...
         'Callback', 'plot (axes, 2:5)');
 
 %****************Area Four 
 
  %user can use the button to execute what we want, or use 
   %option2 to do the same
Hbutton1 = uicontrol('Parent', H.gui, ...
                    'Style', 'pushbutton', ...
                    'Units', 'normalized', ...
                    'Position', [0.0 0.5 0.2 0.1], ...
                    'String', 'Play!', ...
                    'Callback', 'hpn=wavread(''hpn.wav'');wavplay(hpn);');%this line
                %code allow the button 'PLAY' to excute which means play
                %the sound file called 'deng'.
                %however, here that fact is proved that MATLAB can have GUI
                %with functional object tools to perform operation same as
                %other application such as C#, C++ or V.B 
                
                
 
    
     
%*******Area five
 
Hbutton2 = uicontrol('Parent', H.gui, ...
                    'Style', 'pushbutton', ...
                    'Units', 'normalized', ...
                    'Position', [0.0 0.3 0.2 0.1], ...
                    'String', 'Filter Sound!', ...
                    'Callback', 'subplot(2,1,1), plot (hpn) , title(''Entire Waveform'');');
%                      [hpn,fs]= wavread('hpn.wav');
%                       size (hpn)
%                     [hpn,f] = wavread('hpn.wav')
%                     wavplay (hpn,fs)
 
                
%*******Area Six
 
Hbutton3 = uicontrol('Parent', H.gui, ...
                    'Style', 'pushbutton', ...
                    'Units', 'normalized', ...
                    'Position', [0.0 0.1 0.2 0.1], ...
                    'String', 'Get Frequency!', ...
                    'Callback', 'subplot(2,1,1), plot (hpn) , title(''Entire Waveform'');');

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
no14 challenge 14 74
abstract class with all non abstract mentods 6 84
upcasting down casting object remains same but refernece changes 8 67
troubleshoot a python script 8 77
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question