Chương trình xử lý tín hiệu rung và vẽ giao diện

Một phần của tài liệu (LUẬN VĂN THẠC SĨ) Ứng dụng Sensor gia tốc Mems trong việc đo góc nghiêng và đo độ rung Luận văn ThS Kỹ thuật vô tuyến điện tử và thông tin liên lạc 2 07 00 (Trang 106 - 113)

function varargout = adxl(varargin)

% ADXL Application M-file for adxl.fig

% ADXL, by itself, creates a new ADXL or raises the existing

% singleton*.

%

% H = ADXL returns the handle to a new ADXL or the handle to

% the existing singleton*.

%

% ADXL('CALLBACK',hObject,eventData,handles,...) calls the local

% function named CALLBACK in ADXL.M with the given input arguments.

%

% ADXL('Property','Value',...) creates a new ADXL or raises the

% existing singleton*. Starting from the left, property value pairs are

% applied to the GUI before adxl_OpeningFunction gets called. An

% unrecognized property name or invalid value makes property application

% stop. All inputs are passed to adxl_OpeningFcn via varargin.

%

% *See GUI Options - GUI allows only one instance to run (singleton).

%

% See also: GUIDE, GUIDATA, GUIHANDLES

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

% Last Modified by GUIDE v2.5 29-Aug-2005 11:41:55

% Begin initialization code - DO NOT EDIT gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @adxl_OpeningFcn, ...

'gui_OutputFcn', @adxl_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

95

% --- Executes just before adxl is made visible.

function adxl_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 adxl (see VARARGIN)

% Choose default command line output for adxl handles.output = hObject;

% Update handles structure guidata(hObject, handles);

% UIWAIT makes adxl wait for user response (see UIRESUME)

% uiwait(handles.figure1);

axes(handles.pic_axes);

a=imread('C:\GUI\adxl.bmp');

image(a);

axis equal;

axis tight;

axis off;

axes(handles.a_axes);

a1=imread('C:\GUI\adxl1.bmp');

image(a1);

axis equal;

axis tight;

axis off;

axes(handles.v_axes);

a2=imread('C:\GUI\adxl2.bmp');

image(a2);

axis equal;

axis tight;

axis off;

axes(handles.x_axes);

a3=imread('C:\GUI\adxl3.bmp');

image(a3);

axis equal;

axis tight;

axis off;

% --- Outputs from this function are returned to the command line.

(LUAN.VAN.THAC.SI).Ung.dung.Sensor.gia.toc.Mems.trong.viec.do.goc.nghieng.va.do.do.rung.Luan.van.ThS.Ky.thuat.vo.tuyen.dien.tu.va.thong.tin.lien.lac.2.07.00(LUAN.VAN.THAC.SI).Ung.dung.Sensor.gia.toc.Mems.trong.viec.do.goc.nghieng.va.do.do.rung.Luan.van.ThS.Ky.thuat.vo.tuyen.dien.tu.va.thong.tin.lien.lac.2.07.00(LUAN.VAN.THAC.SI).Ung.dung.Sensor.gia.toc.Mems.trong.viec.do.goc.nghieng.va.do.do.rung.Luan.van.ThS.Ky.thuat.vo.tuyen.dien.tu.va.thong.tin.lien.lac.2.07.00(LUAN.VAN.THAC.SI).Ung.dung.Sensor.gia.toc.Mems.trong.viec.do.goc.nghieng.va.do.do.rung.Luan.van.ThS.Ky.thuat.vo.tuyen.dien.tu.va.thong.tin.lien.lac.2.07.00

function varargout = adxl_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 structure varargout{1} = handles.output;

% ---

function varargout = plot_button_Callback(h, eventdata, handles, varargin)

% hObject handle to plot_button (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Get user input from GUI

%f1 = str2double(get(handles.f1_input,'String'));

%f2 = str2double(get(handles.f2_input,'String'));

%t = eval(get(handles.t_input,'String'));

% Calculate data

%x = sin(2*pi*f1*t) + sin(2*pi*f2*t);

%y = fft(x,512);

%m = y.*conj(y)/512;

%f = 1000*(0:256)/512;;

switch handles.current_data case 'test128Hz'

load thu128.mat

case 'test150Hz' load thu150.mat case 'test400Hz' load thu400.mat case 'test50Hz' load thu50.mat case 'test70Hz' load thu70.mat case 'test95Hz' load thu95.mat end

x=x(100:5100);

%load THU128.DAT;

97

%x=THU128;

%plot(x);

%axis([1 200 -0.5 5]);title('tin hieu goc');

xfft=fft(x);

xfft(1)=0;

N=length(xfft);

f=linspace(0,1200,N);

%figure(2);

%plot(abs(xfft));

%figure(3);

%subplot(311);

xx=real(ifft(xfft));

%plot(xx,'k');

%axis([1 100 -2 2]);title('tin hieu sau khi loai nhieu');

tichphan1=tanint(xx);

%subplot(312);

%plot(tichphan1,'k:');

%axis([1 100 -2 2]);title('tin hieu sau khi tich phan lan 1: van toc ');

tichphan1fft=fft(tichphan1);

tichphan1fft(1:100)=0;

tichphan1fft(length(tichphan1fft)-99:length(tichphan1fft))=0;

tichphan1ifft=real(ifft(tichphan1fft));

tichphan2=tanint(tichphan1ifft);

tichphan2fft=fft(tichphan2);

tichphan2fft(1:200)=0;

tichphan2fft(length(tichphan2fft)-199:length(tichphan2fft))=0;

tichphan2ifft=real(ifft(tichphan1fft));

%subplot(313);

%plot(tichphan2ifft,'k-.');

%axis([1 100 -2.5 2]);title('tin hieu sau khi tich phan lan 2: dich chuyen ');

% Create gia toc plot axes(handles.a_axes) plot(xx,'k');

axis([1 100 -2 2]);title('tin hieu sau khi loai nhieu');

set(handles.a_axes,'XMinorTick','on') grid on

% Create van toc plot axes(handles.v_axes) plot(tichphan1,'k:');

axis([1 100 -2 2]);title('tin hieu sau khi tich phan lan 1: van toc ');

(LUAN.VAN.THAC.SI).Ung.dung.Sensor.gia.toc.Mems.trong.viec.do.goc.nghieng.va.do.do.rung.Luan.van.ThS.Ky.thuat.vo.tuyen.dien.tu.va.thong.tin.lien.lac.2.07.00(LUAN.VAN.THAC.SI).Ung.dung.Sensor.gia.toc.Mems.trong.viec.do.goc.nghieng.va.do.do.rung.Luan.van.ThS.Ky.thuat.vo.tuyen.dien.tu.va.thong.tin.lien.lac.2.07.00(LUAN.VAN.THAC.SI).Ung.dung.Sensor.gia.toc.Mems.trong.viec.do.goc.nghieng.va.do.do.rung.Luan.van.ThS.Ky.thuat.vo.tuyen.dien.tu.va.thong.tin.lien.lac.2.07.00(LUAN.VAN.THAC.SI).Ung.dung.Sensor.gia.toc.Mems.trong.viec.do.goc.nghieng.va.do.do.rung.Luan.van.ThS.Ky.thuat.vo.tuyen.dien.tu.va.thong.tin.lien.lac.2.07.00

set(handles.v_axes,'XMinorTick','on') grid on

% Create dich chuyen plot axes(handles.x_axes) plot(tichphan2ifft,'k-.');

axis([1 100 -2.5 2]);title('tin hieu sau khi tich phan lan 2: dich chuyen ');

set(handles.x_axes,'XMinorTick','on') grid on

% Create fft plot axes(handles.fft_axes)

plot(f(1:round(N/2)),abs(xfft(1:round(N/2))));

set(handles.fft_axes,'XMinorTick','on') grid on

% --- function Load_Callback(hObject, eventdata, handles)

% hObject handle to Load (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% --- function Exit_Callback(hObject, eventdata, handles)

% hObject handle to Exit (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA) delete(gcbf);

% --- function About_Callback(hObject, eventdata, handles)

% hObject handle to About (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA) eval('about');

% --- function Trogiup_Callback(hObject, eventdata, handles)

% hObject handle to Trogiup (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA) HelpPath = which('adxl.htm');

web(HelpPath);

% ---

99

function File_Callback(hObject, eventdata, handles)

% hObject handle to File (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% --- function Help_Callback(hObject, eventdata, handles)

% hObject handle to Help (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% --- Executes on selection change in store.

function store_Callback(hObject, eventdata, handles)

% hObject handle to store (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA) val = get(hObject,'Value');

str = get(hObject, 'String');

handles.current_data =str{val};

% Update handles structure handles.output = hObject;

% Update handles structure guidata(hObject, handles);

% Hints: contents = get(hObject,'String') returns store contents as cell array

% contents{get(hObject,'Value')} returns selected item from store

% --- Executes during object creation, after setting all properties.

function store_CreateFcn(hObject, eventdata, handles)

% hObject handle to store (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

set(hObject,'BackgroundColor','white');

else

set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));

end

(LUAN.VAN.THAC.SI).Ung.dung.Sensor.gia.toc.Mems.trong.viec.do.goc.nghieng.va.do.do.rung.Luan.van.ThS.Ky.thuat.vo.tuyen.dien.tu.va.thong.tin.lien.lac.2.07.00(LUAN.VAN.THAC.SI).Ung.dung.Sensor.gia.toc.Mems.trong.viec.do.goc.nghieng.va.do.do.rung.Luan.van.ThS.Ky.thuat.vo.tuyen.dien.tu.va.thong.tin.lien.lac.2.07.00(LUAN.VAN.THAC.SI).Ung.dung.Sensor.gia.toc.Mems.trong.viec.do.goc.nghieng.va.do.do.rung.Luan.van.ThS.Ky.thuat.vo.tuyen.dien.tu.va.thong.tin.lien.lac.2.07.00(LUAN.VAN.THAC.SI).Ung.dung.Sensor.gia.toc.Mems.trong.viec.do.goc.nghieng.va.do.do.rung.Luan.van.ThS.Ky.thuat.vo.tuyen.dien.tu.va.thong.tin.lien.lac.2.07.00

% --- Executes on button press in go.

function go_Callback(hObject, eventdata, handles)

% hObject handle to go (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA) s = serial('COM1');

s.InputBufferSize = 10000;

s.BaudRate = 38400;

fopen(s);

x = fread(s,s.BytesAvailable,'uint8');

fclose(s) delete(s) clear s;

xfft=fft(x);

xfft(1)=0;

N=length(xfft);

f=linspace(0,1200,N);

xx=real(ifft(xfft));

tichphan1=tanint(xx);

tichphan1fft=fft(tichphan1);

tichphan1fft(1:100)=0;

tichphan1fft(length(tichphan1fft)-99:length(tichphan1fft))=0;

tichphan1ifft=real(ifft(tichphan1fft));

tichphan2=tanint(tichphan1ifft);

tichphan2fft=fft(tichphan2);

tichphan2fft(1:200)=0;

tichphan2fft(length(tichphan2fft)-199:length(tichphan2fft))=0;

tichphan2ifft=real(ifft(tichphan1fft));

% Create gia toc plot axes(handles.a_axes) plot(xx,'k');

axis([1 100 -2 2]);title('tin hieu sau khi loai nhieu');

set(handles.a_axes,'XMinorTick','on') grid on

% Create van toc plot axes(handles.v_axes) plot(tichphan1,'k:');

axis([1 100 -2 2]);title('tin hieu sau khi tich phan lan 1: van toc ');

set(handles.v_axes,'XMinorTick','on') grid on

% Create dich chuyen plot axes(handles.x_axes) plot(tichphan2ifft,'k-.');

101

Một phần của tài liệu (LUẬN VĂN THẠC SĨ) Ứng dụng Sensor gia tốc Mems trong việc đo góc nghiêng và đo độ rung Luận văn ThS Kỹ thuật vô tuyến điện tử và thông tin liên lạc 2 07 00 (Trang 106 - 113)

Tải bản đầy đủ (PDF)

(113 trang)