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

📄 my.asv

📁 DFT进行频谱分析时的三种现象 1、混叠:对连续信号采样
💻 ASV
字号:
function varargout = my(varargin)
% UNTITLED2 M-file for untitled2.fig
%      UNTITLED2, by itself, creates a new UNTITLED2 or raises the existing
%      singleton*.
%
%      H = UNTITLED2 returns the handle to a new UNTITLED2 or the handle to
%      the existing singleton*.
%
%      UNTITLED2('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED2.M with the given input arguments.
%
%      UNTITLED2('Property','Value',...) creates a new UNTITLED2 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled2_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled2_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

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help untitled2

% Last Modified by GUIDE v2.5 27-Apr-2006 20:29:40

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled2_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled2_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before untitled2 is made visible.
function untitled2_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 untitled2 (see VARARGIN)

% Choose default command line output for untitled2
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes untitled2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = untitled2_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)


%模拟信号求N点DFT的幅度谱和相位谱
N=64;                  %采样点数
n=0:63;                %采样矢量
t=0.01*n;              %抽样时间间隔,取得的值应该使Fs=1/t满足Nyquist采样定理才不产生混叠
q=n*2*pi/N;            %求出角频率做幅度谱和相位谱的X轴
x=cos(3*pi/20*t);      %原信号时域表达式
                       %生成信号序列
y=fft(x,N);            %对原始信号做N点的傅利叶变换
subplot(3,1,1);        %在三行一列的第一行图中画原始信号时域图
plot(t,x);             %绘制源曲线信号
title('source signal');%做标题
                       
subplot(3,1,2);        %在三行一列的第二行图中画原始信号幅度谱
plot(q,abs(y));        %绘制源曲线信号幅度谱图   
title('magnitude');    %做标题
subplot(3,1,3);        %在三行一列的第三行图中画原始信号相位谱
plot(q,angle(y));      %绘制源曲线信号相位谱图    
title('phase');        %做标题




% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


%产生混叠时求N点DFT的幅度谱和相位谱
N=64;                            %采样点数
n=0:63;                          %采样矢量
t=0.5*n;                         %抽样时间间隔,取得的值应该使Fs=1/t不满足Nyquist采样定理以产生混叠
q=n*2*pi/N;                      %求出角频率做幅度谱和相位谱的X轴
x=cos(3*pi/20*t);                %原信号时域表达式
                                 %生成信号序列
y=fft(x,N);                      %对原始信号做N点的傅利叶变换
subplot(3,1,1);                  %在三行一列的第一行图中画原始信号时域图
plot(t,x);                       %绘制源曲线信号
title('source signal');          %做标题
                                      
subplot(3,1,2);                  %在三行一列的第二行图中画原始信号幅度谱
plot(q,abs(y));                  %绘制源曲线信号幅度谱图            
title('magnitude');              %做标题
subplot(3,1,3);                  %在三行一列的第三行图中画原始信号相位谱
plot(q,angle(y));                %绘制源曲线信号相位谱图              
title('phase');                  %做标题




% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


%有频谱泄漏现象的信号求N点DFT的时域图和频域图
n=[0:1:99];                                   %采样点数即矩形窗长度
xn=cos(3*pi/20*n);                            %原信号时域表达式
                                              %生成信号序列
Xk=fft(xn);                                   %对加矩形窗后的信号做N点的傅利叶变换
kx=[0:1:length(Xk)-1];                        %求出频域图的X轴
subplot(2,1,1);                               %在两行一列的第一行图中画信号时域图
stem(n,xn);                                   %绘制源曲线信号时域图 
title('time domain signal');                  %做标题
                                              %绘制源曲线信号
subplot(2,1,2);                               %在两行一列的第二行图中画信号频域图    
stem(kx,abs(Xk));                             %绘制源曲线信号相位谱图      
title('frequence domain signal(n=100)');      %做标题





% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


%加长矩形长度改善频漏现象的信号求N点DFT的时域图和频域图
n=[0:1:149];                                     %采样点数即矩形窗长度(比上面的长)
xn=cos(3*pi/20*n);                               %原信号时域表达式                                      
                                                 %生成信号序列
Xk=fft(xn);                                      %对加矩形窗后的信号做N点的傅利叶变换
kx=[0:1:length(Xk)-1];                           %求出频域图的X轴
subplot(2,1,1);                                  %在两行一列的第一行图中画信号时域图
stem(n,xn);                                      %绘制源曲线信号时域图 
title('time domain signal');                     %做标题
                                                 %绘制源曲线信号
subplot(2,1,2);                                  %在两行一列的第二行图中画信号频域图 
stem(kx,abs(Xk));                                %绘制源曲线信号相位谱图           
title('frequence domain signal(n=150)');         %做标题





% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


%Kaiser函数改善频漏现象的信号求N点DFT的时域图和频域图
n=[0:1:99];                               %采样点数
xn=cos(3*pi/20*n);                        %原信号时域表达式
                                          %生成信号序列
wn=kaiser(length(xn),5.658);              %给定kaiser函数
hn=xn.*wn';                               %给信号加kaiser函数
Hk=fft(hn);                               %对信号加kaiser后做N点的傅利叶变换
kh=[0:1:length(Hk)-1];                    %求出频域图的X轴
subplot(2,1,1);                           %在两行一列的第一行图中画信号时域图
stem(n,xn);                               %绘制源曲线信号时域图 
title('time domain signal');              %做标题
subplot(2,1,2);                           %在两行一列的第二行图中画信号频域图 
stem(kh,abs(Hk));                         %绘制源曲线信号时域图 
title('kaiser window(n=100)');            %做标题





% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


%栅栏现象和信号末尾补零改善的信号求N点DFT图
n=[0:1:29]; %补零之前的采样矢量
xn=cos(3*pi/20*n); %原信号时域表达式
                                          %生成信号序列
gn=[xn,zeros(1,30)];%对信号进行末尾补零防止栅栏现象
N=length(n);%补零之前的采样点数
M=N+30; %补零之后的采样点数
m=[0:1:M-1];  %补零之后的采样矢量
Xk=fft(xn,30); %对补零前的信号做N点的傅利叶变换
Gk=fft(gn,60); %对补零后后的信号做N点的傅利叶变换
subplot(2,1,1);  %在两行一列的第二行图中画信号频域图 
stem(n,abs(Xk));  %绘制源曲线信号时域图 
title('frequence domain signal(n=30)');%做标题
axis([0,60,0,10]);
subplot(2,1,2);  %在两行一列的第二行图中画信号频域图 
stem(m,abs(Gk));  %绘制源曲线信号时域图 
title('frequence domain signal(n=60)');%做标题

⌨️ 快捷键说明

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