📄 fftingui.m
字号:
function varargout = FFTinGUI(varargin)% FFTINGUI M-file for FFTinGUI.fig% FFTINGUI, by itself, creates a new FFTINGUI or raises the existing% singleton*.%% H = FFTINGUI returns the handle to a new FFTINGUI or the handle to% the existing singleton*.%% FFTINGUI('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in FFTINGUI.M with the given input arguments.%% FFTINGUI('Property','Value',...) creates a new FFTINGUI or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before FFTinGUI_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to FFTinGUI_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 FFTinGUI% Last Modified by GUIDE v2.5 10-Oct-2008 18:47:31% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @FFTinGUI_OpeningFcn, ... 'gui_OutputFcn', @FFTinGUI_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif 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 FFTinGUI is made visible.function FFTinGUI_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to FFTinGUI (see VARARGIN)load mtlb;N=1024;N_short_FFT=128;Fs=7418;set(handles.fft_order,'string',num2str(N));set(handles.short_fourier_interval,'string',num2str(N_short_FFT));str=get(handles.Fs_units,'string');val=get(handles.Fs_units,'value');switch(str{val}) case 'Hz' set(handles.sampling_frequency,'string',num2str(Fs)); case 'kHz' set(handles.sampling_frequency,'string',num2str(Fs/1e3)); case 'MHz' set(handles.sampling_frequency,'string',num2str(Fs/1e6));endaxes(handles.time_axes);plot([0:length(mtlb)-1],mtlb);ylabel('Amplitude');xlabel('Time [samples]');title('Signal in the time domain');axes(handles.fft_frequency_axes);MyFFT(mtlb,N,Fs);title('Signal in the frequency domain');axes(handles.spectrogram_axes);spectrogram(mtlb,N_short_FFT,32,N,Fs);title('Short Fourier Transform of the signal');% Choose default command line output for FFTinGUIhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes FFTinGUI wait for user response (see UIRESUME)% uiwait(handles.figure1);function MyFFT(x,N,Fs)Y=fft(x,N).*conj(fft(x,N));if(Fs>N) f=[0:Fs/N:Fs/2-1];else f=(Fs/N)*[0:N/2];end;if(Fs/2<10e3) semilogy(f,Y(1:N/2)/N); xlabel('Frequency [Hz]'); ylabel('Magnitude [dB]');end;if(Fs/2>1e3 && Fs/2<1e6) semilogy(f/1e3,Y(1:N/2)/N); xlabel('Frequency [kHz]'); ylabel('Magnitude [dB]');end;if(Fs/2>1e6) semilogy(f/1e6,Y(1:N/2)/N); xlabel('Frequency [MHz]'); ylabel('Magnitudine [dB]');end;% --- Outputs from this function are returned to the command line.function varargout = FFTinGUI_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{1} = handles.output;% --- Executes on button press in load_data.function load_data_Callback(hObject, eventdata, handles)% hObject handle to load_data (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)str=get(handles.select_data,'string');val=get(handles.select_data,'value');global file_name;switch(str{val}) case '.dat' file_name=uigetfile('*.dat', 'Alege un fisier .dat'); file_name=importdata(file_name); case '.mat' file_name=uigetfile('*.mat', 'Alege un fisier .mat'); file_name=load(file_name); file_name=file_name.data; case '.wav' file_name=uigetfile('*.wav', 'Alege un fisier .wav'); file_name=wavread(file_name); file_name=file_name(:,1);endfunction fft_order_Callback(hObject, eventdata, handles)% hObject handle to fft_order (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of fft_order as text% str2double(get(hObject,'String')) returns contents of fft_order as a double% --- Executes during object creation, after setting all properties.function fft_order_CreateFcn(hObject, eventdata, handles)% hObject handle to fft_order (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction sampling_frequency_Callback(hObject, eventdata, handles)% hObject handle to sampling_frequency (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of sampling_frequency as text% str2double(get(hObject,'String')) returns contents of sampling_frequency as a double% --- Executes during object creation, after setting all properties.function sampling_frequency_CreateFcn(hObject, eventdata, handles)% hObject handle to sampling_frequency (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction short_fourier_interval_Callback(hObject, eventdata, handles)% hObject handle to short_fourier_interval (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of short_fourier_interval as text% str2double(get(hObject,'String')) returns contents of short_fourier_interval as a double% --- Executes during object creation, after setting all properties.function short_fourier_interval_CreateFcn(hObject, eventdata, handles)% hObject handle to short_fourier_interval (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end% --- Executes on selection change in Fs_units.function Fs_units_Callback(hObject, eventdata, handles)% hObject handle to Fs_units (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns Fs_units contents as cell array% contents{get(hObject,'Value')} returns selected item from Fs_unitsguidata(hObject,handles);% --- Executes during object creation, after setting all properties.function Fs_units_CreateFcn(hObject, eventdata, handles)% hObject handle to Fs_units (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end% --- Executes on button press in plot_data.function plot_data_Callback(hObject, eventdata, handles)% hObject handle to plot_data (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global file_name;str=get(handles.Fs_units,'string');val=get(handles.Fs_units,'value');Fs=str2double(get(handles.sampling_frequency,'string'));switch(str{val}) case 'kHz' Fs=1e3*Fs; case 'MHz' Fs=1e6*Fs;endN=str2double(get(handles.fft_order,'string'));N_short_FFT=str2double(get(handles.short_fourier_interval,'string'));if(length(file_name)>1e5) file_name=file_name(2e4:4.4e5,1);endaxes(handles.time_axes);plot([0:length(file_name)-1],file_name);ylabel('Amplitude');xlabel('Time [samples]');title('Signal in the time domain');axes(handles.fft_frequency_axes);MyFFT(file_name,N,Fs);axes(handles.spectrogram_axes);spectrogram(file_name,N_short_FFT,32,N,Fs);title('Short Fourier Transform of the signal');% --- Executes on selection change in select_data.function select_data_Callback(hObject, eventdata, handles)% hObject handle to select_data (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns select_data contents as cell array% contents{get(hObject,'Value')} returns selected item from select_data% --- Executes during object creation, after setting all properties.function select_data_CreateFcn(hObject, eventdata, handles)% hObject handle to select_data (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -