【信號處理】頻譜分析儀含Matlab源碼
【信號處理】頻譜分析儀含Matlab源碼
1 簡介
1.在matlab中運行ch4.m文件可進入GUI界面
2.讀入WAV文件輸入方式需要將*.wav格式文件放置在 “...頻譜分析儀” 根目錄下,再在GUI界面文件名輸入欄中輸入 “XXX.wav”
再 “打開文件” 按鍵,即可打開wav文件。 對于多聲道文件,可選擇需要讀入的聲道,默認(rèn)為讀入1聲道。
3.在每次進行時域分析和頻域分析之前,請對分析點的數(shù)目進行核對,如果分析點數(shù)超過了采樣點數(shù),
可通過勾選 “分析所有點”選擇框 進行調(diào)整即可。
4.時程曲線下面的兩個滾軸,上面的滾軸為比例調(diào)整滾軸,可調(diào)整圖像顯示的比例;下面的滾軸為橫坐標(biāo)平移滾軸,可調(diào)整x軸的顯示范圍;
5.右下角的滾軸是五條譜曲線的比例調(diào)整滾軸。
6.界面退出請點擊右上角紅色關(guān)閉按鈕;
2 部分代碼
function varargout = ch4(varargin)
gui_Singleton =
1
;
gui_State = struct(
’gui_Name’
, mfilename, ...
’gui_Singleton’
, gui_Singleton, ...
’gui_OpeningFcn’
, @ch4_OpeningFcn, ...
’gui_OutputFcn’
, @ch4_OutputFcn, ...
’gui_LayoutFcn’
, [] , ...
’gui_Callback’
, []);
if
nargin && ischar(varargin{
1
})
gui_State.gui_Callback = str2func(varargin{
1
});
end
function channel_Callback(hObject, eventdata, handles)
% hObject handle to channel (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 channel as text
% str2double(get(hObject,
’String’
)) returns contents of channel as a double
% --- Executes during object creation, after setting all properties.
function channel_CreateFcn(hObject, eventdata, handles)
% hObject handle to channel (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
set(hObject,
’BackgroundColor’
,
’white’
);
else
set(hObject,
’BackgroundColor’
,get(
0
,
’defaultUicontrolBackgroundColor’
));
end
% --- Executes on selection change
in
wavetype.
function wavetype_Callback(hObject, eventdata, handles)
% hObject handle to wavetype (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 wavetype contents as cell array
% contents{get(hObject,
’Value’
)} returns selected item from wavetype
% --- Executes during object creation, after setting all properties.
function wavetype_CreateFcn(hObject, eventdata, handles)
% hObject handle to wavetype (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
% --- Executes during object deletion, before destroying properties.
function add_DeleteFcn(hObject, eventdata, handles)
% hObject handle to add (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
% --- Executes on slider movement.
function xmove_Callback(hObject, eventdata, handles)
% hObject handle to xmove (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,
’Value’
) returns position of slider
% get(hObject,
’Min’
)
and
get(hObject,
’Max’
) to determine range of slider
val=get(handles.scale,
’value’
);
val=
10
^(val*
5
+
1
);
x=get(hObject,
’Value’
)*str2double(get(handles.samplenum,
’String’
));
axis(handles.time,[x val+x min(handles.y) max(handles.y)]);
% --- Executes during object creation, after setting all properties.
function xmove_CreateFcn(hObject, eventdata, handles)
% hObject handle to xmove (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles empty - handles
not
created
until
after all CreateFcns called
%
Hint:
slider controls usually have a light gray background, change
%
’usewhitebg’
to
0
to use default. See ISPC
and
COMPUTER.
usewhitebg =
1
;
if
usewhitebg
set(hObject,
’BackgroundColor’
,[.
9
.
9
.
9
]);
else
set(hObject,
’BackgroundColor’
,get(
0
,
’defaultUicontrolBackgroundColor’
));
end
% --- Executes on button press
in
analyseall.
function analyseall_Callback(hObject, eventdata, handles)
% hObject handle to analyseall (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
if
get(hObject,
’Value’
)==
0
.
0
set(handles.pointfrom,
’Enable’
,
’on’
);
set(handles.pointto,
’Enable’
,
’on’
);
else
set(handles.pointfrom,
’String’
,
’1’
,
’Enable’
,
’off’
);
set(handles.pointto,
’String’
,get(handles.samplenum,
’String’
),
’Enable’
,
’off’
);
end
function outt_Callback(hObject, eventdata, handles)
% hObject handle to outt (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 outt as text
% str2double(get(hObject,
’String’
)) returns contents of outt as a double
% --- Executes during object creation, after setting all properties.
function outt_CreateFcn(hObject, eventdata, handles)
% hObject handle to outt (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
set(hObject,
’BackgroundColor’
,
’white’
);
else
set(hObject,
’BackgroundColor’
,get(
0
,
’defaultUicontrolBackgroundColor’
));
end
function foutt_Callback(hObject, eventdata, handles)
% hObject handle to foutt (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 foutt as text
% str2double(get(hObject,
’String’
)) returns contents of foutt as a double
% --- Executes during object creation, after setting all properties.
function foutt_CreateFcn(hObject, eventdata, handles)
% hObject handle to foutt (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
set(hObject,
’BackgroundColor’
,
’white’
);
else
set(hObject,
’BackgroundColor’
,get(
0
,
’defaultUicontrolBackgroundColor’
));
end
% --- Executes
when
selected object is changed
in
uipanel9.
function uipanel9_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object
in
uipanel9
% eventdata structure with the following fields (see UIBUTTONGROUP)
%
EventName:
string
’SelectionChanged’
(read only)
%
OldValue:
handle of the previously selected object
or
empty
if
none was selected
%
NewValue:
handle of the currently selected object
% handles structure with handles
and
user data (see GUIDATA)
switch get(hObject,
’Tag’
)
case
’soundcard’
set(findobj(
’Tag’
,
’recordtime’
),
’enable’
,
’on’
);
h=findobj(
’Tag’
,
’filename’
);
set(h,
’enable’
,
’off’
);
h=findobj(
’Tag’
,
’freq’
);
set(h,
’enable’
,
’off’
);
h=findobj(
’Tag’
,
’amp’
);
set(h,
’enable’
,
’off’
);
h=findobj(
’Tag’
,
’phase’
);
set(h,
’enable’
,
’off’
);
set(handles.channel,
’enable’
,
’off’
);
set(handles.fileopen,
’enable’
,
’off’
);
set(handles.gensig,
’enable’
,
’off’
);
set(handles.wavetype,
’enable’
,
’off’
);
set(handles.add,
’enable’
,
’off’
);
set(handles.startrecord,
’enable’
,
’on’
);
case
’WAVfile’
h=findobj(
’Tag’
,
’filename’
);
set(h,
’enable’
,
’on’
);
h=findobj(
’Tag’
,
’freq’
);
set(h,
’enable’
,
’off’
);
h=findobj(
’Tag’
,
’amp’
);
set(h,
’enable’
,
’off’
);
h=findobj(
’Tag’
,
’phase’
);
set(h,
’enable’
,
’off’
);
set(findobj(
’Tag’
,
’recordtime’
),
’enable’
,
’off’
);
set(handles.channel,
’enable’
,
’on’
);
set(handles.fileopen,
’enable’
,
’on’
);
set(handles.gensig,
’enable’
,
’off’
);
set(handles.wavetype,
’enable’
,
’off’
);
set(handles.add,
’enable’
,
’off’
);
set(handles.startrecord,
’enable’
,
’off’
);
case
’generator’
h=findobj(
’Tag’
,
’filename’
);
set(h,
’enable’
,
’off’
);
h=findobj(
’Tag’
,
’freq’
);
set(h,
’enable’
,
’on’
);
h=findobj(
’Tag’
,
’amp’
);
set(h,
’enable’
,
’on’
);
h=findobj(
’Tag’
,
’phase’
);
set(h,
’enable’
,
’on’
);
set(findobj(
’Tag’
,
’recordtime’
),
’enable’
,
’off’
);
set(handles.channel,
’enable’
,
’off’
);
set(handles.fileopen,
’enable’
,
’off’
);
set(handles.gensig,
’enable’
,
’on’
);
set(handles.wavetype,
’enable’
,
’on’
);
set(handles.add,
’enable’
,
’on’
);
set(handles.startrecord,
’enable’
,
’off’
);
end
function edit27_Callback(hObject, eventdata, handles)
% hObject handle to filename (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 filename as text
% str2double(get(hObject,
’String’
)) returns contents of filename as a double
% --- Executes during object creation, after setting all properties.
function edit27_CreateFcn(hObject, eventdata, handles)
% hObject handle to filename (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
function edit28_Callback(hObject, eventdata, handles)
% hObject handle to freq (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 freq as text
% str2double(get(hObject,
’String’
)) returns contents of freq as a double
% --- Executes during object creation, after setting all properties.
function edit28_CreateFcn(hObject, eventdata, handles)
% hObject handle to freq (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
function edit29_Callback(hObject, eventdata, handles)
% hObject handle to amp (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 amp as text
% str2double(get(hObject,
’String’
)) returns contents of amp as a double
% --- Executes during object creation, after setting all properties.
function edit29_CreateFcn(hObject, eventdata, handles)
% hObject handle to amp (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
function edit30_Callback(hObject, eventdata, handles)
% hObject handle to phase (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 phase as text
% str2double(get(hObject,
’String’
)) returns contents of phase as a double
% --- Executes during object creation, after setting all properties.
function edit30_CreateFcn(hObject, eventdata, handles)
% hObject handle to phase (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
function edit31_Callback(hObject, eventdata, handles)
% hObject handle to recordtime (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 recordtime as text
% str2double(get(hObject,
’String’
)) returns contents of recordtime as a double
% --- Executes during object creation, after setting all properties.
function edit31_CreateFcn(hObject, eventdata, handles)
% hObject handle to recordtime (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 button press
in
startrecord.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to startrecord (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
% --- Executes on button press
in
fileopen.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to fileopen (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
% --- Executes on button press
in
gensig.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to gensig (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
function edit32_Callback(hObject, eventdata, handles)
% hObject handle to channel (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 channel as text
% str2double(get(hObject,
’String’
)) returns contents of channel as a double
% --- Executes during object creation, after setting all properties.
function edit32_CreateFcn(hObject, eventdata, handles)
% hObject handle to channel (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
wavetype.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to wavetype (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
%
Hints:
contents = cellstr(get(hObject,
’String’
)) returns wavetype contents as cell array
% contents{get(hObject,
’Value’
)} returns selected item from wavetype
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to wavetype (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
add.
function checkbox3_Callback(hObject, eventdata, handles)
% hObject handle to add (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
%
Hint:
get(hObject,
’Value’
) returns toggle state of add
% --- Executes on button press
in
add.
function add_Callback(hObject, eventdata, handles)
% hObject handle to add (see GCBO)
% eventdata reserved - to be
defined
in
a future version of MATLAB
% handles structure with handles
and
user data (see GUIDATA)
%
Hint:
get(hObject,
’Value’
) returns toggle state of add
3 仿真結(jié)果
4 參考文獻
[1]陳華麗. "基于LabVIEW和MATLAB的頻譜分析儀設(shè)計." 計量與測試技術(shù) 34.9(2007):2.
博主簡介:擅長智能優(yōu)化算法、神經(jīng)網(wǎng)絡(luò)預(yù)測、信號處理、元胞自動機、圖像處理、路徑規(guī)劃、無人機等多種領(lǐng)域的Matlab仿真,相關(guān)matlab代碼問題可私信交流。
部分理論引用網(wǎng)絡(luò)文獻,若有侵權(quán)聯(lián)系博主刪除。
-
2023年各省最新電價一覽!8省中午執(zhí)行谷段電價! 2023-01-03
-
PPT導(dǎo)出高分辨率圖片的四種方法 2022-09-22
-
2023年最新!國家電網(wǎng)27家省級電力公司負(fù)責(zé)人大盤點 2023-03-14
-
全國消防救援總隊主官及簡歷(2023.2) 2023-02-10
-
盤點 l 中國石油大慶油田現(xiàn)任領(lǐng)導(dǎo)班子 2023-02-28
-
我們的前輩!歷屆全國工程勘察設(shè)計大師完整名單! 2022-11-18
-
關(guān)于某送變電公司“4·22”人身死亡事故的快報 2022-04-26
