[753] | 1 | % 'signal_band_filter': example of pass-band filter (using the signal toolbox fct fdesign)
|
---|
| 2 | % frequency and bandwidth need to be modified in the function
|
---|
| 3 | %
|
---|
| 4 | % OUTPUT:
|
---|
| 5 | % DataOut: Matlab structure representing the output (filtered) field
|
---|
| 6 | %
|
---|
| 7 | %INPUT:
|
---|
| 8 | % DataIn: Matlab structure representing the output field
|
---|
[810] | 9 |
|
---|
| 10 | %=======================================================================
|
---|
[1061] | 11 | % Copyright 2008-2019, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[810] | 12 | % http://www.legi.grenoble-inp.fr
|
---|
| 13 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
[753] | 14 | %
|
---|
[810] | 15 | % This file is part of the toolbox UVMAT.
|
---|
| 16 | %
|
---|
| 17 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 18 | % it under the terms of the GNU General Public License as published
|
---|
| 19 | % by the Free Software Foundation; either version 2 of the license,
|
---|
| 20 | % or (at your option) any later version.
|
---|
| 21 | %
|
---|
| 22 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 25 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
| 26 | %=======================================================================
|
---|
[753] | 27 |
|
---|
[881] | 28 | function DataOut=signal_bandpass_filter(DataIn,Param)
|
---|
| 29 |
|
---|
| 30 | %% request input parameters
|
---|
| 31 | if isfield(DataIn,'Action') && isfield(DataIn.Action,'RUN') && isequal(DataIn.Action.RUN,0)
|
---|
| 32 | VarNbDim=cellfun('length',DataIn.VarDimName);
|
---|
| 33 | [tild,rank]=sort(VarNbDim,2,'descend');% sort the list of input variables, putting the ones with higher dimensionality first
|
---|
| 34 | ListVarName=DataIn.ListVarName(rank);
|
---|
| 35 | VarDimName=DataIn.VarDimName(rank);
|
---|
| 36 | InitialValue=1;%default choice
|
---|
| 37 | if isfield(Param,'TransformInput') && isfield(Param.TransformInput,'VariableName')
|
---|
| 38 | val=find(strcmp(Param.TransformInput.VariableName,ListVarName));
|
---|
| 39 | if ~isempty(val);
|
---|
| 40 | InitialValue=val;
|
---|
| 41 | end
|
---|
| 42 | end
|
---|
| 43 | [s,OK] = listdlg('PromptString','Select the variable to process:',...
|
---|
| 44 | 'SelectionMode','single','InitialValue',InitialValue,...
|
---|
| 45 | 'ListString',ListVarName);
|
---|
| 46 | if OK==1
|
---|
| 47 | VarName=ListVarName{s};
|
---|
| 48 | DataOut.TransformInput.VariableName=VarName;
|
---|
| 49 | dlg_title = [mfilename ' filter signal along first dim ' VarDimName{s}{1}];% title of the input dialog fig
|
---|
| 50 | prompt = {'central filtering frequency';'bandwith (relative to the central frequency) '};% titles of the edit boxes
|
---|
| 51 | %default input:
|
---|
| 52 | def={'';'0.1'};% filtering frequency and relative bandwidth
|
---|
| 53 |
|
---|
| 54 | if isfield(Param,'TransformInput')% if parameters have been memorised
|
---|
| 55 | if isfield(Param.TransformInput,'CentralFrequency')
|
---|
| 56 | def{1}=num2str(Param.TransformInput.CentralFrequency);
|
---|
| 57 | end
|
---|
| 58 | if isfield(Param.TransformInput,'BandWidth')
|
---|
| 59 | def{2}=num2str(Param.TransformInput.BandWidth);
|
---|
| 60 | end
|
---|
| 61 | end
|
---|
| 62 | num_lines= 1;%numel(prompt);
|
---|
| 63 | % open the dialog fig
|
---|
| 64 | answer = inputdlg(prompt,dlg_title,num_lines,def);
|
---|
| 65 | DataOut.TransformInput.CentralFrequency=str2num(answer{1});
|
---|
| 66 | DataOut.TransformInput.BandWidth=str2num(answer{2});
|
---|
| 67 | end
|
---|
| 68 | return
|
---|
| 69 | end
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 |
|
---|
[753] | 73 | %% set GUI config
|
---|
| 74 | DataOut=[];
|
---|
| 75 | if strcmp(DataIn,'*')
|
---|
| 76 | DataOut.InputFieldType='1D';
|
---|
| 77 | return
|
---|
| 78 | end
|
---|
| 79 | %%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
[881] | 80 | frequency=Param.TransformInput.CentralFrequency;% frequency at which the signal needs to be filetered
|
---|
| 81 | Bw=Param.TransformInput.BandWidth;
|
---|
| 82 | DataOut=DataIn;
|
---|
[753] | 83 | %d=fdesign.bandpass(0.8*frequency, 0.95*frequency, 1.05*frequency, 1.2*frequency, 60, 1, 60);
|
---|
[881] | 84 | d=fdesign.bandpass((1-2*Bw)*frequency, (1-Bw)*frequency, (1+Bw)*frequency, (1+2*Bw)*frequency, 60, 1, 60);
|
---|
[753] | 85 | Hd=design(d);% command fvtool(Hd) to visualize the filter frequency response
|
---|
[881] | 86 |
|
---|
[753] | 87 | if isfield(DataIn,'U')
|
---|
| 88 | DataOut.U = filter(Hd,DataIn.U);
|
---|
| 89 | end
|
---|
| 90 | if isfield(DataIn,'V')
|
---|
| 91 | DataOut.V = filter(Hd,DataIn.V);
|
---|
| 92 | end
|
---|
| 93 |
|
---|