Matlab importing filter structure.

Thread Starter

dtow1

Joined Apr 27, 2010
24
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.

Rich (BB code):
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


[file,path]=uigetfile;    %Obtain file and path information

file=strrep(file,'.m','');   %remove .m from filter name
Filter=file
Signal = handles.Signal_Temp;  %load signal to be filtered
Signal = typecast(Signal,'single'); %ensure signal is of type 'float' or 'single'

Filter1 = bpass697hz

Signal_Temp = filter(Filter1,Signal);  %Apply filter to signal
guidata(hObject,handles);

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.
 

Thread Starter

dtow1

Joined Apr 27, 2010
24
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.

Rich (BB code):
Filter =

50khzlp

 
Filter1 =
 
         FilterStructure: 'Direct-Form II, Second-Order Sections'
              Arithmetic: 'double'                               
               sosMatrix: [15x6 double]                          
             ScaleValues: [16x1 double]                          
     OptimizeScaleValues: true                                   
        PersistentMemory: false
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!
 

Thread Starter

dtow1

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

Rich (BB code):
% --- APPLY FILTER TO DATA--- %

function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[file,path]=uigetfile;

Filterstuff=load(file);
Hd=Filterstuff.Hd
%[b,a] = sos2tf(SOS,G)

Signal = handles.Signal_Temp;

handles.Signal_Temp;
%Signal_Temp=filter(b,a,Signal);
Signal_Temp=filter(Hd,Signal)
handles.Signal_Temp=Signal_Temp;
guidata(hObject,handles);

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.
 
Top