Solved

get a frequency

Posted on 2009-05-07
3
587 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mapShare challenge 13 90
wordappend challenge 8 149
wordmultiple challenge 12 119
Change to event 1 101
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

920 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

16 Experts available now in Live!

Get 1:1 Help Now