Matlab importing filter structure.

Discussion in 'Programmer's Corner' started by dtow1, Mar 8, 2011.

  1. dtow1

    Thread Starter New Member

    Apr 27, 2010
    24
    0
    Hello,

    I am writing a gui program using Guide. In one of the functions I am trying to allow the user to load in a filter created using the fdatool. Using this then be able to filter a signal through this. It is meant to not force them to modify the code any time they want to use a different filter.

    Code ( (Unknown Language)):
    1.  
    2.  
    3. % --- Executes on button press in pushbutton2.
    4. function pushbutton2_Callback(hObject, eventdata, handles)
    5. % hObject    handle to pushbutton2 (see GCBO)
    6. % eventdata  reserved - to be defined in a future version of MATLAB
    7. % handles    structure with handles and user data (see GUIDATA)
    8.  
    9.  
    10. [file,path]=uigetfile;    %Obtain file and path information
    11.  
    12. file=strrep(file,'.m','');   %remove .m from filter name
    13. Filter=file
    14. Signal = handles.Signal_Temp;  %load signal to be filtered
    15. Signal = typecast(Signal,'single'); %ensure signal is of type 'float' or 'single'
    16.  
    17. Filter1 = bpass697hz
    18.  
    19. Signal_Temp = filter(Filter1,Signal);  %Apply filter to signal
    20. guidata(hObject,handles);
    21.  
    22.  
    23.  

    When Filter is displayed it simply shows the name of the filter, where as Filter1 displays the structure for bpass697hz, I need to get Filter to do the same.

    Ive tried things like using load, uiimport, and some other approaches which escape me at the moment. Id greatly appreciate any help and will gladly clarify anything that seems unclear.
     
  2. dtow1

    Thread Starter New Member

    Apr 27, 2010
    24
    0
    So I have seen a lot of views but no responses so I'm posting output to try and clarify the issue in case I worded it poorly.

    Code ( (Unknown Language)):
    1.  
    2.  
    3. Filter =
    4.  
    5. 50khzlp
    6.  
    7.  
    8. Filter1 =
    9.  
    10.          FilterStructure: 'Direct-Form II, Second-Order Sections'
    11.               Arithmetic: 'double'                              
    12.                sosMatrix: [15x6 double]                          
    13.              ScaleValues: [16x1 double]                          
    14.      OptimizeScaleValues: true                                  
    15.         PersistentMemory: false    
    16.  
    17.  
    18.  
    As you can see Filter simply displays the name, it is only the string which is assigned not the data structure. Filter1 is actually assigned the filter structure so can be used to apply the filter to the signal. I need Filter to do this so that the user can browse and select a previously created filter and apply it to the data through the GUI. I hope this helps and maybe someone will have an idea to help me resolve this so far I have turned up nothing but dead ends.

    Thanks in advance!
     
  3. dtow1

    Thread Starter New Member

    Apr 27, 2010
    24
    0
    For anyone interested I found a way to solve my problem.

    Code ( (Unknown Language)):
    1.  
    2.  
    3. % --- APPLY FILTER TO DATA--- %
    4.  
    5. function pushbutton2_Callback(hObject, eventdata, handles)
    6. % hObject    handle to pushbutton2 (see GCBO)
    7. % eventdata  reserved - to be defined in a future version of MATLAB
    8. % handles    structure with handles and user data (see GUIDATA)
    9. [file,path]=uigetfile;
    10.  
    11. Filterstuff=load(file);
    12. Hd=Filterstuff.Hd
    13. %[b,a] = sos2tf(SOS,G)
    14.  
    15. Signal = handles.Signal_Temp;
    16.  
    17. handles.Signal_Temp;
    18. %Signal_Temp=filter(b,a,Signal);
    19. Signal_Temp=filter(Hd,Signal)
    20. handles.Signal_Temp=Signal_Temp;
    21. guidata(hObject,handles);
    22.  
    23.  

    Instead of doing it the way I was instead having the user save created filters as an object from the fdatool. It works!! In another function I run an FFT on the data and get the results you would expect. The commented sections are so that the user can save their filter as SOS coefficients and Gain but I have not worked on that completely yet. If anyone is interested I can explain in more detail. I hope this helps someone at some point.
     
Loading...