⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 homework3.m

📁 对输入的一有理Z变换表达式(输入分子和分母系数序列)
💻 M
📖 第 1 页 / 共 2 页
字号:
axes(handles.SeqAxes);
stem(t,y);
title(title_str, 'FontWeight', 'bold');
xlabel('n');
ylabel('x[n]');


% --- Executes on button press in DTFTButton.function DTFTButton_Callback(hObject, eventdata, handles)% hObject    handle to DTFTButton (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)
% Compute DTFT and plot the result 
global Num Den z p k outputFlag
numFeqPoints = str2double(get(handles.NumFreqEditor, 'String'));
if numFeqPoints <= 0
    ErrorDlg('Please input a positive integer as the number of frequency points!');
end
w = 0:pi/numFeqPoints:pi;  % where I select 256 as the number of frequency points. It is similar to DFT. 
% But its meaning is different to that of DFT. The plot function use these 256 points to  
h = freqz(Num, Den, w);
axes(handles.MagAxes);
plot(w/pi, abs(h));
title('Magnitude Spectrum', 'FontWeight', 'demi');
xlabel('ω/π');
ylabel('Magnitude');
if (outputFlag)
    disp('Magnitude Spectrum:'); disp(abs(h));
end

axes(handles.PhaseAxes);
plot(w/pi, unwrap(angle(h)));
title('Phase Spectrum', 'FontWeight', 'demi');
xlabel('ω/π');
ylabel('Phase,radians');
if (outputFlag)
    disp('Phase Sectrum:'); disp(unwrap(angle(h)));
end
% --- Executes on button press in InputOKButton.function InputOKButton_Callback(hObject, eventdata, handles)% hObject    handle to InputOKButton (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global Num Den z p k Modified
Num = str2num(get(handles.NumEditor, 'String'));
Den = str2num(get(handles.DenEditor, 'String'));

if length(Den) == 0
    ErrorDlg('Denominator cannot be empty!');
end

if Den(1) == 0
    ErrorDlg('Denominator must have non-zero leading coefficient!');
end

[Num Den] = EQTFLENGTH(Num, Den);  % forces NUM and DEN to be of the same length by appending zeros
set(handles.NumEditor, 'String', num2str(Num));
set(handles.DenEditor, 'String', num2str(Den));

% output the transform function on the interface
set(handles.NumText, 'String', poly2str(Num, 'z'));set(handles.DenText, 'String', poly2str(Den, 'z'));
set(handles.ZPButton, 'Enable', 'on');

% clear the plots
if Modified == 1
axes(handles.ZpplaneAxes);
cla;
axes(handles.MagAxes);
cla;
axes(handles.PhaseAxes);
cla;
axes(handles.SeqAxes);
cla;
Modified = 0;
end


% --- Executes during object creation, after setting all properties.function TFstr_CreateFcn(hObject, eventdata, handles)% hObject    handle to TFstr (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'));endfunction TFstr_Callback(hObject, eventdata, handles)% hObject    handle to TFstr (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 TFstr as text%        str2double(get(hObject,'String')) returns contents of TFstr as a double% --- Executes on button press in ZPButton.function ZPButton_Callback(hObject, eventdata, handles)% hObject    handle to ZPButton (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)
global Num Den z p k absp DiffPoleNum outputFlag

[z,p,k] = tf2zp(Num, Den);
if (outputFlag)
    disp('Zero points:'); disp(z);
    disp('Pole points:'); disp(p);
    disp('K;'); disp(k);
end

axes(handles.ZpplaneAxes);
% zplane(Num, Den);
zplane(z, p);
title('Pole-zero Plot', 'FontWeight', 'demi');
set(handles.ROCList, 'Enable', 'on');

absp = abs(p);

if isempty(p)
    str = 'ROC is whole space';
else
    % Use "insert" method to sort the pole points by their magnitude; 
    len = length(absp);

    si = 1;

    for idx = 2:len
        dupFlag = '0';
        pos = si;
        current = absp(idx);
        while pos >= 1   
            diff = current - absp(pos);
            if abs(diff) <= 5e-15 
                dupFlag = '1';
            end
            if diff >= -5e-15
                break;
            end
            pos = pos-1; 
        end

        if dupFlag == '1'
            dupFlag = '0';
            continue;
        end
        pos = pos+1;
    
        i = si;
        while i >= pos
            absp(i+1) = absp(i);
            i = i-1;
        end
        
        absp(pos) = current;
        si = si + 1;
    end  % end of for

    DiffPoleNum = si;

    % set the 'String' property of ROCList
    idx = 1;
    str = strcat('|z| <', num2str(absp(idx)));

    if (DiffPoleNum >= 2)
        idx = 2;
        while idx <= DiffPoleNum
            tmpstr = strcat(num2str(absp(idx-1)) , '< |z| < ',num2str(absp(idx)));
            str = strvcat(str, tmpstr);
            idx = idx+1;
        end
    end
    tmpstr = strcat(num2str(absp(DiffPoleNum)) , '< |z| ');
    str = strvcat(str, tmpstr);
end  % end of else

set(handles.ROCList, 'String', str);
value = get(handles.ROCList, 'Value');
set(handles.ZPButton, 'Enable', 'off');
judge_InterfaceControl(value, handles);
   
% --- Executes on button press in OutputRadiobutton.function OutputRadiobutton_Callback(hObject, eventdata, handles)% hObject    handle to OutputRadiobutton (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 OutputRadiobuttonglobal outputFlag
outputFlag = get(hObject, 'Value');% --- Executes during object creation, after setting all properties.function NumFreqEditor_CreateFcn(hObject, eventdata, handles)% hObject    handle to NumFreqEditor (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'));endfunction NumFreqEditor_Callback(hObject, eventdata, handles)% hObject    handle to NumFreqEditor (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 NumFreqEditor as text%        str2double(get(hObject,'String')) returns contents of NumFreqEditor as a double% --- Executes during object creation, after setting all properties.function SeqNumEditor_CreateFcn(hObject, eventdata, handles)% hObject    handle to SeqNumEditor (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'));endfunction SeqNumEditor_Callback(hObject, eventdata, handles)% hObject    handle to SeqNumEditor (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 SeqNumEditor as text%        str2double(get(hObject,'String')) returns contents of SeqNumEditor as a double% --- Executes on button press in SetLengthCheckbox.function SetLengthCheckbox_Callback(hObject, eventdata, handles)% hObject    handle to SetLengthCheckbox (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 SetLengthCheckboxvalue = get(hObject, 'Value')
if value == 1
    set(handles.SeqNumEditor, 'Enable', 'on');
else
    set(handles.SeqNumEditor, 'Enable', 'off');
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -