Solved

get a frequency

Posted on 2009-05-07
3
592 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This video teaches viewers about errors in exception handling.
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.

734 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