help me one thing matlab plot
조회 수: 2 (최근 30일)
이전 댓글 표시
function hh
N=800;
M=600;
A = 0; F = 0; S = 0; Fi=0;
Fs=100;
Ts=1/Fs;
t=[-6:Ts:6];
handles.fig=figure();
mpos=get(handles.fig,'position');
set(handles.fig,'units','pixel');
set(handles.fig,'position',[mpos(3)-120 mpos(4)-250 N M]);
handles.axes1=axes();
set(handles.axes1,'units','pixel');
handles.axes1=subplot(3,1,1);
handles.axes2=axes();
set(handles.axes2,'units','pixel');
handles.axes2=subplot(3,1,2);
handles.axes3=axes();
set(handles.axes3,'units','pixel');
handles.axes3=subplot(3,1,3);
handles.filter1=uicontrol('style','radiobutton');
set(handles.filter1,'string','low pass');
set(handles.filter1,'position',[100 200 80 20]);
handles.filter2=uicontrol('style','radiobutton');
set(handles.filter2,'string','highpass');
set(handles.filter2,'position',[100 180 80 20]);
handles.filter3=uicontrol('style','radiobutton');
set(handles.filter3,'string','band pass');
set(handles.filter3,'position',[100 160 80 20]);
handles.edit1=uicontrol('style','edit');
set(handles.edit1,'position',[N-360 0 120 20]);
set(handles.edit1,'string','A');
set(handles.edit1,'horizontalalignment','center');
set(handles.filter1,'callback',{@mycallback, handles, 1});
set(handles.filter2,'callback',{@mycallback, handles, 2});
set(handles.filter3,'callback',{@mycallback, handles, 3});
handles.edit1 = uicontrol('style','edit');
set(handles.edit1,'position',[N-360 0 120 20]);
set(handles.edit1,'string','A');
set(handles.edit1,'horizontalalignment','center');
handles.edit2 = uicontrol('style','edit');
set(handles.edit2,'position',[N-240 0 120 20]);
set(handles.edit2,'string','F');
set(handles.edit2,'horizontalalignment','center');
set(handles.edit1, 'callback', @edit_callback1);
set(handles.edit2, 'callback', @edit_callback2);
function edit_callback1(src, event_data)
A = str2double( get(src, 'String') );
end
function edit_callback2(src, event_data)
F = str2double( get(src, 'String') );
S=A*cos(2*pi*F*t);
plot(handles.axes1, t, S);
end
function mycallback(gcf, event_data, handles, filter_num)
switch filter_num
case 1
set(handles.filter1,'value',1);
set(handles.filter2,'value',0);
set(handles.filter3,'value',0);
Fi=rectpuls(t/4);
plot(handles.axes2,t,Fi);
axis(handles.axes2, [-6 6 0.01 2]);
xlabel(handles.axes2,'frequency(hz)');
ylabel(handles.axes2,'Filter');
title(handles.axes2,'Low Pass Filter impulse');
plot(handles.axes3, t, (Fi*S));
case 2
set(handles.filter1,'value',0);
set(handles.filter2,'value',1);
set(handles.filter3,'value',0);
Fi=1*(t>3)+1*(t<(-3));
plot(handles.axes2,t,Fi);
axis(handles.axes2, [-6 6 0.01 2]);
xlabel(handles.axes2,'frequency(hz)');
ylabel(handles.axes2,'Filter');
title(handles.axes2,'High Pass Filter impulse');
plot(handles.axes3, t,(Fi*S));
case 3
set(handles.filter1,'value',0);
set(handles.filter2,'value',0);
set(handles.filter3,'value',1);
Fi=1*(t>2&t<4)+1*(t<(-2)&t>-4);
plot(handles.axes2,t,Fi);
axis(handles.axes2, [-6 6 0.01 2]);
xlabel(handles.axes2, 'frequency(hz)');
ylabel(handles.axes2,'Filter');
title(handles.axes2, 'Band Pass Filter frequency');
plot(handles.axes3, t, (Fi*S));
end
end
end
please one thing
why not work
plot(handles.axes3, t, (Fi*S));
댓글 수: 0
채택된 답변
Walter Roberson
2015년 12월 4일
Change F*S to F.*S
While you are at it, stop naming a callback parameter "gcf". name it "src" or "hObject".
Note: you create handles.edit1 twice.
Note: You are using nested functions. You do not need to pass handles in to mycallback and if you do pass it in then you are not going to get the handles structure that you think you are going to get.
댓글 수: 0
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!