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

📄 guide.m

📁 matlab程序
💻 M
📖 第 1 页 / 共 4 页
字号:
             window =hamming(n2+1);              b = fir1(n2,wn);                      case 2                                    %hamming窗             window =hanning(n2+1);              b = fir1(n2,wn,window);         case 3                                    %kaiser窗            beta = str2double(get(handles.edit15, 'String'));            window = kaiser(n2+1,beta);             b = fir1(n2,wn,window);         case 4                                     %chebwin窗             r = str2double(get(handles.edit15, 'String'));             window =chebwin(n2+1,r);              b = fir1(n2,wn,window);         end        case 4                                            %滤波器选中fir中的bs,以下为4种fir方式         wn = [(2*wp1/freq_sampling+2*ws1/freq_sampling)/2 (2*wp2/freq_sampling+2*ws2/freq_sampling)/2];         n2 = str2double(get(handles.edit17, 'String'));         filtertype = 'stop';         fir_type =get(handles.popupmenu4,'value');         switch fir_type         case 1                                     %hamming窗             window =hamming(n2+1);             b = fir1(n2,wn,filtertype);         case 2                                    %hamming窗             window =hanning(n2+1);             b = fir1(n2,wn,filtertype,window);         case 3                                    %kaiser窗            beta = str2double(get(handles.edit15, 'String'));            window = kaiser(n2+1,beta);            b = fir1(n2,wn,filtertype,window);         case 4                                     %chebwin窗             r = str2double(get(handles.edit15, 'String'));             window =chebwin(n2+1,r);              b = fir1(n2,wn,filtertype,window);         end              endset(handles.edit18,'string',n2);a = 1;axes(handles.axes2);cla;filtered_signal = filter(b,a,all);plot(n/N,filtered_signal);hold on;xlabel('t/s')ylabel('filtered_signal');title( 'filtered signal');end                                                                              % case fir        function edit18_Callback(hObject, eventdata, handles)% hObject    handle to edit18 (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 edit18 as text%        str2double(get(hObject,'String')) returns contents of edit18 as a double% --- Executes during object creation, after setting all properties.function edit18_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit18 (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 edit19_Callback(hObject, eventdata, handles)% hObject    handle to edit19 (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 edit19 as text%        str2double(get(hObject,'String')) returns contents of edit19 as a double% --- Executes during object creation, after setting all properties.function edit19_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit19 (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 edit20_Callback(hObject, eventdata, handles)% hObject    handle to edit17 (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 edit17 as text%        str2double(get(hObject,'String')) returns contents of edit17 as a double% --- Executes during object creation, after setting all properties.function edit20_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit17 (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 edit28_Callback(hObject, eventdata, handles)% hObject    handle to edit17 (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 edit17 as text%        str2double(get(hObject,'String')) returns contents of edit17 as a double% --- Executes during object creation, after setting all properties.function edit28_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit17 (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 edit29_Callback(hObject, eventdata, handles)% hObject    handle to edit19 (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 edit19 as text%        str2double(get(hObject,'String')) returns contents of edit19 as a double% --- Executes during object creation, after setting all properties.function edit29_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit19 (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 pushbutton9.function pushbutton9_Callback(hObject, eventdata, handles)global a;global b;[h,w] = freqz(b,a,512);axes(handles.axes2);cla;plot(w,20*log10(abs(h)));xlabel('Frequency(f)');ylabel('H(f)');grid on;% hObject    handle to pushbutton9 (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 pushbutton10.function pushbutton10_Callback(hObject, eventdata, handles)global a;global b;axes(handles.axes3);cla;zplane(b,a);% hObject    handle to pushbutton10 (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 pushbutton11.function pushbutton11_Callback(hObject, eventdata, handles)global a;global b;[H1,T]=impz(b,a); axes(handles.axes2);cla;plot(T,H1);xlabel('Time(t)');ylabel('H(t)');grid on;% hObject    handle to pushbutton11 (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 pushbutton12.function pushbutton12_Callback(hObject, eventdata, handles)global filtered_signal;global freq_sampling;N=freq_sampling;            %设定采样点数             X=fft(filtered_signal);                        % 计算x的快速傅立叶变换XF=X(1:N/2+1);                   % F(k)=X(k)(k=1:N/2+1)f=N*(0:N/2)/N;                  % 使频率轴f从零开始axes(handles.axes2);cla;plot(f,abs(F))            % 绘制振幅-频率图xlabel('Frequency');ylabel('|F(k)|')title('fft');% hObject    handle to pushbutton12 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% --- Executes during object creation, after setting all properties.function pushbutton10_CreateFcn(hObject, eventdata, handles)% hObject    handle to pushbutton10 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% --- Executes during object creation, after setting all properties.function pushbutton9_CreateFcn(hObject, eventdata, handles)% hObject    handle to pushbutton9 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% --- Executes on button press in pushbutton13.function pushbutton13_Callback(hObject, eventdata, handles)global all;global freq_main;global abs_main;global freq_noise1;global abs_noise1;global freq_noise2;global abs_noise2;global freq_sampling;global main_signal;global noise1_signal;global noise2_signal;freq_main = str2double(get(handles.edit1, 'String')); %读主信号频率值abs_main  = str2double(get(handles.edit2, 'String')); %读主信号幅值freq_noise1 = str2double(get(handles.edit3, 'String')); %读噪声1信号频率值abs_noise1  = str2double(get(handles.edit4, 'String')); %读噪声1信号幅值freq_noise2 = str2double(get(handles.edit5, 'String')); %读噪声2信号频率值abs_noise2  = str2double(get(handles.edit6, 'String')); %读噪声2信号幅值freq_sampling = str2double(get(handles.edit7, 'String')); %读采样频率N=freq_sampling;            %设定采样点数n=0:N-1;                main_signal=abs_main*cos(2*pi*freq_main*n/N);   %表主信号幅度值noise1_signal =abs_noise1*cos(2*pi*freq_noise1*n/N);   %表noise1信号幅度值noise2_signal =abs_noise2*cos(2*pi*freq_noise2*n/N);   %表noise1信号幅度值all=main_signal+noise1_signal+noise2_signal;X=fft(all);                        % 计算x的快速傅立叶变换XF=X(1:N/2+1);                   % F(k)=X(k)(k=1:N/2+1)f=N*(0:N/2)/N;                  % 使频率轴f从零开始axes(handles.axes1);cla;plot(f,abs(F))            % 绘制振幅-频率图xlabel('Frequency');ylabel('|F(k)|')title('fft');% hObject    handle to pushbutton13 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)

⌨️ 快捷键说明

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