RIGOL示波器编程使用
生活随笔
收集整理的這篇文章主要介紹了
RIGOL示波器编程使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
RIGOL編程使用
RIGOL示波器可由多種語言編程進行操作。
這里僅僅給出RIGOL編程手冊給出的MATLAB的例程,以及自己寫的程序。并提供讀取的波形數據的工作區(1000Hz,5V有效值),可在無示波器下進行測試。
RIGOL MATLAB 例程
編程手冊例程
源代碼
% clear; % 創建 VISA 對象。'ni'為銷售商參數,可以為 agilent、NI 或 tek, % 'USB0::0x1AB1::0x04B0::DS2A0000000000::INSTR'為設備的資源描述符。創建后需設置設備的屬性, % 本例中設置輸入緩存的長度為 2048 % MSO2000A = visa( 'ni','USB0::0x1AB1::0x04B0::DS2A0000000000::INSTR' ); MSO2000A = visa( 'ni','USB0::0x1AB1::0x04B0::DS2F210800048::INSTR' ); MSO2000A.InputBufferSize = 2048; N = MSO2000A.InputBufferSize; %打開已創建的 VISA 對象 fopen(MSO2000A); %讀取波形 fprintf(MSO2000A, ':wav:data?' ); %請求數據 [data,len]= fread(MSO2000A,N);% ------------------自加部分------------------% 獲取周期 fprintf(MSO2000A,':MEASure:PERiod? <CHANnel1>'); T = fscanf(MSO2000A); T = str2num(T); F = 1/T % 計算頻率% 獲取采樣頻率 fprintf(MSO2000A,':ACQuire:SRATe?'); Fs = fscanf(MSO2000A); Fs = str2num(Fs) % 計算采樣總時間 Tmax = N/Fs% ------------------自加部分------------------%關閉設備 fclose(MSO2000A); delete(MSO2000A); clear MSO2000A; % 數據處理。讀取的波形數據含有 TMC 頭,長度為 11 個字節,其中前 2 個字節分別為 TMC 頭標志符 % #和寬度描述符 9,接著的 9 個字節為數據長度,然后是波形數據,最后一個字節為結束符 0x0A。所 % 以,讀取的有效波形數據點為 12 到倒數第 2 個點。 wave = data(12:len-1); wave = wave'; subplot(211); plot(wave);運行結果
主要的語句命令格式及使用方法都在這個例程里了。詳細的描述見編程手冊。
資源在這,免費下載:https://download.csdn.net/download/qq_41683065/12100339
自寫帶GUI界面的MATLAB程序
源代碼
% GUI里不能帶clear,會清空GUI的工作變量 % 我的一個猜想,采樣點數為2048是固定的,但采樣得到的波形不一樣,即所測信號的頻率不一樣。 function varargout = gaopinGUI(varargin) % GAOPINGUI MATLAB code for gaopinGUI.fig % GAOPINGUI, by itself, creates a new GAOPINGUI or raises the existing % singleton*. % % H = GAOPINGUI returns the handle to a new GAOPINGUI or the handle to % the existing singleton*. % % GAOPINGUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GAOPINGUI.M with the given input arguments. % % GAOPINGUI('Property','Value',...) creates a new GAOPINGUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before gaopinGUI_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to gaopinGUI_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 gaopinGUI% Last Modified by GUIDE v2.5 10-Jan-2020 11:15:03% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @gaopinGUI_OpeningFcn, ...'gui_OutputFcn', @gaopinGUI_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{:}); elsegui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT% --- Executes just before gaopinGUI is made visible. function gaopinGUI_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 gaopinGUI (see VARARGIN)% Choose default command line output for gaopinGUI handles.output = hObject;% Update handles structure guidata(hObject, handles);% UIWAIT makes gaopinGUI wait for user response (see UIRESUME) % uiwait(handles.figure1);% --- Outputs from this function are returned to the command line. function varargout = gaopinGUI_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;% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% ------------------------------示波器操作--------------------------------- MSO2000A = visa( 'ni','USB0::0x1AB1::0x04B0::DS2F210800048::INSTR' ); MSO2000A.InputBufferSize = 2048; N = MSO2000A.InputBufferSize; %打開已創建的 VISA 對象 fopen(MSO2000A); %讀取波形 fprintf(MSO2000A, ':wav:data?' ); %請求數據 [data,len]= fread(MSO2000A,N);% 獲取周期 fprintf(MSO2000A,':MEASure:PERiod? <CHANnel1>'); T = fscanf(MSO2000A); T = str2num(T); Fread = 1/T % 計算頻率 str5 = num2str(Fread); set(handles.Fread,'string',str5);% 獲取采樣頻率 fprintf(MSO2000A,':ACQuire:SRATe?'); Fs = fscanf(MSO2000A); Fs = str2num(Fs) str6 = num2str(Fs); set(handles.Fs,'string',str6); % 計算采樣總時間 Tmax = N/Fs str4 = num2str(Tmax); set(handles.Tmax,'string',str4);%關閉設備 fclose(MSO2000A); delete(MSO2000A); clear MSO2000A; % 數據處理。讀取的波形數據含有 TMC 頭,長度為 11 個字節,其中前 2 個字節分別為 TMC 頭標志符 % #和寬度描述符 9,接著的 9 個字節為數據長度,然后是波形數據,最后一個字節為結束符 0x0A。所 % 以,讀取的有效波形數據點為 12 到倒數第 2 個點。 wave = data(12:len-1); wave = wave'; % ------------------------------示波器操作---------------------------------% load('RFdata.mat'); % N = 2048; F = 1:1:1025;% 獲取輸入量 IgnoredF=get(handles.IgnoredF, 'String'); IgnoredF=str2double(IgnoredF); rage_rate=get(handles.rage_rate, 'String'); rage_rate=str2double(rage_rate);% 去均值化 ave = mean(wave); wave = wave - ave; plot(handles.wave, wave) % 繪制波形圖像% fft fftSpec = fft(wave',2048); fftRms = abs( fftSpec'); % 取一半 fftRms = fftRms(1:N/2+1); fftRms(2:end-1) = 2*fftRms(2:end-1); % 取log fftLg = 20*log(fftRms); % 繪圖 plot(handles.fft1, F, fftLg)[fmax,~,fft_max,~] = Find_extremum_of_RowVector(fftLg', F);% plot them on a figure plot(handles.fft2,F,fftLg); hold(handles.fft2,'on') plot(handles.fft2, fmax, fft_max, 'r+'); xlabel(handles.fft1,'f/Hz'),ylabel(handles.fft1, 'V/mv') set(handles.fft2,'YLim',[0 250])[fmax,~,fft_max,~] = Find_extremum_of_RowVector(fftLg(:,IgnoredF:end-1)', F(:,IgnoredF:end-1));% 查找最大的諧波數 f1_pred=peak(fft_max,fmax,rage_rate,1); f2_pred=peak(fft_max,fmax,rage_rate,2);str2 = ['測得信號的最大的頻率分量為: ',num2str(f1_pred),' Hz']; str3 = ['測得信號的次大的頻率分量為: ',num2str(f2_pred),' Hz']; set(handles.string2,'string',str2); set(handles.string3,'string',str3);function string1_Callback(hObject, eventdata, handles) % hObject handle to string1 (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 string1 as text % str2double(get(hObject,'String')) returns contents of string1 as a double% --- Executes during object creation, after setting all properties. function string1_CreateFcn(hObject, eventdata, handles) % hObject handle to string1 (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 edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (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 edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double% --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (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 string2_Callback(hObject, eventdata, handles) % hObject handle to string2 (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 string2 as text % str2double(get(hObject,'String')) returns contents of string2 as a double% --- Executes during object creation, after setting all properties. function string2_CreateFcn(hObject, eventdata, handles) % hObject handle to string2 (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 string3_Callback(hObject, eventdata, handles) % hObject handle to string3 (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 string3 as text % str2double(get(hObject,'String')) returns contents of string3 as a double% --- Executes during object creation, after setting all properties. function string3_CreateFcn(hObject, eventdata, handles) % hObject handle to string3 (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 IgnoredF_Callback(hObject, eventdata, handles) % hObject handle to IgnoredF (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 IgnoredF as text % str2double(get(hObject,'String')) returns contents of IgnoredF as a double% --- Executes during object creation, after setting all properties. function IgnoredF_CreateFcn(hObject, eventdata, handles) % hObject handle to IgnoredF (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 rage_rate_Callback(hObject, eventdata, handles) % hObject handle to rage_rate (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 rage_rate as text % str2double(get(hObject,'String')) returns contents of rage_rate as a double% --- Executes during object creation, after setting all properties. function rage_rate_CreateFcn(hObject, eventdata, handles) % hObject handle to rage_rate (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 Tmax_Callback(hObject, eventdata, handles) % hObject handle to Tmax (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 Tmax as text % str2double(get(hObject,'String')) returns contents of Tmax as a double% --- Executes during object creation, after setting all properties. function Tmax_CreateFcn(hObject, eventdata, handles) % hObject handle to Tmax (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 Fread_Callback(hObject, eventdata, handles) % hObject handle to Fread (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 Fread as text % str2double(get(hObject,'String')) returns contents of Fread as a double% --- Executes during object creation, after setting all properties. function Fread_CreateFcn(hObject, eventdata, handles) % hObject handle to Fread (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 Fs_Callback(hObject, eventdata, handles) % hObject handle to Fs (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 Fs as text % str2double(get(hObject,'String')) returns contents of Fs as a double% --- Executes during object creation, after setting all properties. function Fs_CreateFcn(hObject, eventdata, handles) % hObject handle to Fs (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運行結果
僅僅有這個不能運行,還有相應的.fig文件才能運行。
這是自己寫的,就不免費了嗷:https://download.csdn.net/download/qq_41683065/12100350
總結
以上是生活随笔為你收集整理的RIGOL示波器编程使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: springboot+乡村图书管理系统
- 下一篇: Marvell校招新增数字后端工程师岗位