⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guifourierseries.m

📁 非常好的数字处理教程
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = guiFourierSeries(varargin)
% This code is by Jim Squire <SquireJC@vmi.edu>
%	It needs to be recoded to SSUM format.
% 
% GUIFOURIERSERIES M-file for guiFourierSeries.fig
%      GUIFOURIERSERIES, by itself, creates a new GUIFOURIERSERIES or raises the existing
%      singleton*.
%
%      H = GUIFOURIERSERIES returns the handle to a new GUIFOURIERSERIES or the handle to
%      the existing singleton*.
%
%      GUIFOURIERSERIES('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUIFOURIERSERIES.M with the given input arguments.
%
%      GUIFOURIERSERIES('Property','Value',...) creates a new GUIFOURIERSERIES or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before guiFourierSeries_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to guiFourierSeries_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help guiFourierSeries

% Last Modified by GUIDE v2.5 31-Mar-2005 18:04:20
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @guiFourierSeries_OpeningFcn, ...
    'gui_OutputFcn',  @guiFourierSeries_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before guiFourierSeries is made visible.
function guiFourierSeries_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
t=load('guiFourierSeries.mat');
% Fig1
axes(handles.uiaxFig1);
image(t.strGraphic.Fig1);
set(handles.uiaxFig1,'Visible','Off')
colormap([0 0 0;236 233 216]/255)
% Fig2
axes(handles.uiaxFig2)
image(t.strGraphic.Fig2)
set(handles.uiaxFig2,'Visible','Off')
% Fig3
axes(handles.uiaxFig3)
image(t.strGraphic.Fig3)
set(handles.uiaxFig3,'Visible','Off')
% Calculate and fill the plots
CalculateAndUpdate(handles)

function varargout = guiFourierSeries_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;


%%%%%%%%%%%%%%%%%%%%%%%% Input function: wave type %%%%%%%%%%%%%%%%%%%%%%%%%%%
function uirbWaveTypeSin_Callback(hObject, eventdata, handles)
set(handles.uirbWaveTypeSin, 'Value', 1);
set([handles.uirbWaveTypeSquare handles.uirbWaveTypeTriangle], 'Value', 0);
CalculateAndUpdate(handles)

function uirbWaveTypeSquare_Callback(hObject, eventdata, handles)
set(handles.uirbWaveTypeSquare, 'Value', 1);
set([handles.uirbWaveTypeSin handles.uirbWaveTypeTriangle], 'Value', 0);
CalculateAndUpdate(handles)

function uirbWaveTypeTriangle_Callback(hObject, eventdata, handles)
set(handles.uirbWaveTypeTriangle, 'Value', 1);
set([handles.uirbWaveTypeSin handles.uirbWaveTypeSquare], 'Value', 0);
CalculateAndUpdate(handles)

%%%%%%%%%%%%%%%%%%%%%%% Slider data %%%%%%%%%%%%%%%%%%%%%%%%%
function uislFrequency_Callback(hObject, eventdata, handles)
CalculateAndUpdate(handles)

function uislAmplitude_Callback(hObject, eventdata, handles)
CalculateAndUpdate(handles)

function uislSymmetry_Callback(hObject, eventdata, handles)
CalculateAndUpdate(handles)

function uislYOffset_Callback(hObject, eventdata, handles)
CalculateAndUpdate(handles)

function uislTDelay_Callback(hObject, eventdata, handles)
CalculateAndUpdate(handles)

%%%%%%%%%%%%%%%%%%%%%%% Fourier series form %%%%%%%%%%%%%%%%%%%%%%%%%
function uirbFig1_Callback(hObject, eventdata, handles)
set(handles.uirbFig1, 'Value', 1)
set([handles.uirbFig2 handles.uirbFig3], 'Value', 0);
set(handles.uirbPlotComponent1,'String','ai')
set(handles.uirbPlotComponent2,'String','bi')
set([handles.uirbPlotComponent3 handles.uirbPlotComponent4],'Enable','off')
if get(handles.uirbPlotComponent3,'Value') ||get(handles.uirbPlotComponent4,'Value') 
    set([handles.uirbPlotComponent3 handles.uirbPlotComponent4],'Value',0)
    set(handles.uirbPlotComponent1,'Value',1)
end
CalculateAndUpdate(handles)

function uirbFig2_Callback(hObject, eventdata, handles)
set(handles.uirbFig2, 'Value', 1);
set([handles.uirbFig1 handles.uirbFig3], 'Value', 0);
set(handles.uirbPlotComponent1,'String','Ai')
set(handles.uirbPlotComponent2,'String','Thetai')
set([handles.uirbPlotComponent3 handles.uirbPlotComponent4],'Enable','off')
if get(handles.uirbPlotComponent3,'Value') ||get(handles.uirbPlotComponent4,'Value') 
    set([handles.uirbPlotComponent3 handles.uirbPlotComponent4],'Value',0)
    set(handles.uirbPlotComponent1,'Value',1)
end
CalculateAndUpdate(handles)

function uirbFig3_Callback(hObject, eventdata, handles)
set(handles.uirbFig3, 'Value', 1);
set([handles.uirbFig1 handles.uirbFig2], 'Value', 0);
set(handles.uirbPlotComponent1,'String','real{ci}')
set(handles.uirbPlotComponent2,'String','imag{ci}')
set([handles.uirbPlotComponent3 handles.uirbPlotComponent4],'Enable','on')
CalculateAndUpdate(handles)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Fourier Series: NumTerms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function uislNumTerms_Callback(hObject, eventdata, handles)
switch round(get(handles.uislNumTerms,'Value'))
    case 0, N = 0;
    case 1, N = 1;
    case 2, N = 2;
    case 3, N = 3;
    case 4, N = 4;
    case 5, N = 5;
    case 6, N = 6;
    case 7, N = 7;
    case 8, N = 8;
    case 9, N = 9;
    case 10, N = 10;
    case 11, N = 20;
    case 12, N = 30;
    case 13, N = 40;
    case 14, N = 50;
    case 15, N = 100;
end
set(handles.uitxNumTerms,'String',sprintf('N terms = %g',N))
CalculateAndUpdate(handles)

%%%%%%%%%%%%%%%%%%%%%%%%%% Fourier Series: plot components %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function uirbPlotComponent1_Callback(hObject, eventdata, handles)
set(handles.uirbPlotComponent1, 'Value', 1);
set([handles.uirbPlotComponent2 handles.uirbPlotComponent3 handles.uirbPlotComponent4], 'Value', 0);
CalculateAndUpdate(handles)

function uirbPlotComponent2_Callback(hObject, eventdata, handles)
set(handles.uirbPlotComponent2, 'Value', 1);
set([handles.uirbPlotComponent1 handles.uirbPlotComponent3 handles.uirbPlotComponent4], 'Value', 0);
CalculateAndUpdate(handles)

function uirbPlotComponent3_Callback(hObject, eventdata, handles)
set(handles.uirbPlotComponent3, 'Value', 1);
set([handles.uirbPlotComponent1 handles.uirbPlotComponent2 handles.uirbPlotComponent4], 'Value', 0);
CalculateAndUpdate(handles)

function uirbPlotComponent4_Callback(hObject, eventdata, handles)
set(handles.uirbPlotComponent4, 'Value', 1);
set([handles.uirbPlotComponent1 handles.uirbPlotComponent2 handles.uirbPlotComponent3], 'Value', 0);
CalculateAndUpdate(handles)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CalculateAndUpdate %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function CalculateAndUpdate(handles)
strGui = GetGUIValues(handles);  % get all the scaled date from the GUI

% calculate strData.y0Time, .xTime, y1Time, xFreq, yFreq
strData = CaculateSeries(strGui);

% Display time
axes(handles.uiaxTime)
plot(strData.xTime,strData.y0Time,'r-',strData.xTime,strData.y1Time,'b-')
xlabel('Time (s)')
legend('Orignal','Reconstructed')
v=axis;
if v(4)-v(3)<1e-4
    v(4)=v(4)+0.5;
    v(3)=v(3)-0.5;
end
axis(v)
% Display freq
axes(handles.uiaxFreq)
stem('v6',strData.xFreq,strData.yFreq)
xlabel('Freq (Hz)')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GetGUIValues %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function strGui = GetGUIValues(handles)
% Wave type
t = get(handles.uirbWaveTypeSin,'Value') + 2*get(handles.uirbWaveTypeSquare,'Value') + 4*get(handles.uirbWaveTypeTriangle,'Value');
switch t
    case 1, strGui.waveType = 'Sin';
    case 2, strGui.waveType = 'Square';
    case 4, strGui.waveType = 'Triangle';
    otherwise, error(sprintf('Unknown wave type: ',t));
end
% Wave parameters
strGui.w = ScaleIt(get(handles.uislFrequency,'Value'),0,4,8,0,2*pi,6*pi);                  % frequency in rads/s
if ~strGui.w, strGui.w=1e-6; end
T = 2*pi/strGui.w;
strGui.A = ScaleIt(get(handles.uislAmplitude,'Value'),0,4,8,0,1,4);                        % amplitude
strGui.sym = ScaleIt(round(get(handles.uislSymmetry,'Value')),0,4,8,1e-6,0.5-1e-6,1-1e-6); % symmetry
strGui.yOff = ScaleIt(get(handles.uislYOffset,'Value'),0,4,8,-2,0,2);                      % yOffset

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -