Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

get a frequency

Posted on 2009-05-07
3
Medium Priority
?
597 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 1500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
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.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

963 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