Solved

get a frequency

Posted on 2009-05-07
3
586 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
Comment Utility
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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How do you update a local branch with the local master in git 3 28
fix34  challenge 9 96
Problem to event 3 49
recursion example 16 68
This article will show, step by step, how to integrate R code into a R Sweave document
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 implement Singleton Design Pattern in Java.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now