1、matlab dtft dft等代码实验报告Laboratory Report of Digital Signal ProcessingLab II. Fourier analysis in MATLABName: 廖艺灵 No.: 5100309716 Date: 2013/4/6 SHANGHAI JIAOTONG UNIVERSITYDepartment of Instrument Science & EngineeringContent1 Introduction 12 Exercises 1Ex. 1 Create a Triangle Signal 1Ex. 2 CTFT And
2、CTFS 1Ex. 3 DTFT 1Ex. 4 DFT 13 Results and Discussion 2Ex. 1 Create a Triangle Signal 2Ex. 2 CTFT And CTFS 2Ex. 3 DTFT 4Ex. 4 DFT 54 Summary 75 Reference 76 Appendix 8Ex. 1 Create a Triangle Signal 8Ex. 3 DTFT 9Ex. 4 DFT 101 IntroductionThis lab concentrates mainly on the Fourier analysis in MATLAB.
3、 For each kind of signals, e.g. discrete or continuous time signals and periodic or non-periodic signals, the corresponding Fourier analysis may be Continuous-Time Fourier Series (CTFS), Discrete-Time Fourier Series (DTFS), Continuous-Time Fourier Transform (CTFT), Discrete-Time Fourier Transform (D
4、TFT) and Discrete Fourier Transform (DFT). Refer to the example which uses square signal as the input signal, we will use a triangle wave to achieve same goals, that is find its CTFS, DTFS, CTFT, DTFT and DFT to compare the differences between them. The Matlab codes for these Fourier analysis calcul
5、ations are provided in script files as follows.2 ExercisesEx. 1 Create a Triangle Signal1.1 Refer to mySquare.m, develop a sub-function myTriangle.m for a periodic isosceles triangle (see Fig. 1 as demonstration) with proper inputs and outputs. Provide the whole codes in the report appendix.1.2 Run
6、myTriangle.m to create a continuous periodic triangle with the height H = 1.5, length L = 2 and period T = 5. Show the result with at least 3 cycles.Fig. 1 Triangle WaveEx. 2 CTFT And CTFS2.1 Run CTFS.m for this periodic triangle and CTFT.m for only one triangle signal. Calculate and show the Fourie
7、r coefficients (including at least 99% average power) and spectrum (including at least 99% of energy), respectively.2.2 Explain the relationship between the CTFT and CTFS.Ex. 3 DTFT3.1 Refer to CTFT.m, develop DTFT.m for discrete-time Fourier transform. A discrete-time triangle signal obtained from
8、myTriangle is chosen as an example signal in DTFT. Provide the whole codes in the report appendix.3.2 Run DTFT.m of the sampled one triangle of Ex.1 with a sampling frequency of fs = 10. Show and compare the DTFT results with those from CTFT of the corresponding CT triangle. 3.3 Explain the relation
9、ship between the DTFT and CTFT.Ex. 4 DFT4.1 Refer to CTFT.m, develop a sub-function of myDFT.m for discrete Fourier transform with proper inputs and outputs. Provide the whole codes in the report appendix.4.2 Run DFT.m of the sampled one triangle of Ex.1 with a sampling frequency of fs = 10. Show an
10、d compare the DFT results with those from DTFT. 4.3 Explain the relationship between the DFT and DTFT.3 Results and DiscussionEx. 1 Create a Triangle SignalThe function codes are put in the appendix. Following is the output figure of the function.Fig. 2 The Triangle SignalEx. 2 CTFT And CTFS CTFTCTF
11、STime DomainContinuousAperiodicContinuousPeriodicFrequency DomainContinuousAperiodicDiscreteAperiodicBetween the CTFS and CTFT, we prefer to have the CTFT because it has all theinformation contained in the CTFS on the assumption that the CTFS consists ofthe samples of CTFT . Besides, the CTFS is not
12、 so practical because it is hard to find the period.Fig.3 Fourier Coefficients Fig.4 The Reconstructed Triangle Wave with 10-order Harmonics.Fig.5 Fourier Transform of a Continuous Triangle Signal.Ex. 3 DTFTCTFTDTFTTime DomainContinuousAperiodicDiscreteAperiodicFrequency DomainContinuousAperiodicCon
13、tinuousPeriodicthe DTFT of xn = x(nT ) is qualitatively the periodic extension of the CTFT of x(t) (with period 2/T in analog frequency or 2 in digital frequency ), the sum of infinitely many shifted version of CTFT. This explains how the DTFT strays from the CTFT because of frequency-aliasing Discr
14、ete-Time Fourier AnalysisFig.6 DTFT of a Triangle SignalEx. 4 DFTDTFTDFTTime DomainDiscreteAperiodicDiscreteAperiodicFrequency DomainContinuousPeriodicDiscretePeriodicDTFT after transformation frequency of a graphic is generally sequential, and interval sampling, such as DFT is DTFT is discrete poin
15、ts. From the said, you can see that its function is expressed as X (k), and DTFT function is expressed as the X (exp (jw). (here gives prominence to the sampling interval, such as DFT is DTFT DTFT frequency response is generally straight after the change, after DFT transform of frequency response is
16、 discrete).DTFT is 2 PI for the cycle. And sequence of DFT X(k) is limited.Fig.7 Comparison of DFT and DTFT of a Triangle Signal.4 SummaryWe could make a table to show the major feature of these Fourier transforms.CTFTCTFSDTFTDTFSDFTTime DomainContinuousAperiodicContinuousPeriodicDiscreteAperiodicDi
17、scretePeriodicDiscreteAperiodicFrequency DomainContinuousAperiodicDiscreteAperiodicContinuousPeriodicDiscretePeriodicDiscretePeriodicWhen analyze any signal, we should use proper Fourier transform to help us find the exact answer.5 Reference1 MATLAB Getting Started Guide COPYRIGHT 1984-2010 by The M
18、athWorks, Inc2 A.V. Oppenheim, A.S. Willsky and S.H. Nawab, Signals and Systems (Second Edition), Publishing House of Electrics Industry6 AppendixEx. 1 Create a Triangle Signal%=% MYTRIANGLE used to create a triangle wave with n cylces.% by Tramps, 30/03/2013 %=%function x,t = myTriangle(para)% inpu
19、t parametersparaDef = struct(H,1.5,T,5,L,2,n,3,fs,100);bDef = 0; % plot the signal? 0: no, 1: yes% no input parameterif nargin 1, para = paraDef; bDef = 1;end% get the parameters for the square signalif isstruct(para) H = para.H; T = para.T; L = para.L; n = para.n; fs = para.fs;else para = paraDef;
20、bDef = 1;end% create one period of the signaldt = 1/fs;tp = (-T/2+dt) : dt : T/2;xp = zeros(1,length(tp)lp = -L/2 : dt : L/2;for ii = 1:(length(lp)-1) xp(fs*(T-L)/2+ii) = H*(fs*L-ii)/fs; xp(fs*(T+L)/2-ii) = H*(fs*L-ii)/fs;end%plot(tp,xp);%return % Create all-time signal by replicating one cycle thro
21、ugh convolutionta = (-n*T/2+dt) : dt : n*T/2;xa = zeros(1,length(ta);for ii = 0:n-1 tmp = ii*fs*T; xa(tmp+1):(tmp+T*fs) = xp;end %plot(ta,xa);%return% output resultst = ta;x = xa; if(bDef) plot(t,x) set(gca,YLim,-H*0.1,H*1.1) title(Default Triangle Signal)end endEx. 3 DTFT%=% 1)Calculate the Discret
22、e-Time Fourier Transform(DTFT) of a triangle signal.% 2)Check the Parsevals relation for Fourier transform.% by Tramps, 30/03/2013 %=%clc,clear,close all% Create a triangle wave with just one cycle%(1) set parametersH = 1; % heightT = 5; % cycle timeL = 2; % lengthn = 1; % number of cycles(1.2.3.)fs
23、 = 10; % sampling frequency%(2) create the trianglepara = struct(H,H,T,T,L,L,n,n,fs,fs);xp,tp = myTriangle(para);%stem(tp,xp);% FTN = fs * T;k = -N:N;FT_w = -3*pi : 0.1 : 3*pi;DTFT_FT = 0;for ii = 1:N DTFT_FTtmp = xp(ii)*exp(-1j*FT_w*k(ii); DTFT_FT = DTFT_FT+DTFT_FTtmp;end % show resultsfigure;%subp
24、lot(211); % time domain stem(tp,xp,r);xlabel(t (s);ylabel(Amplitude);title(Discrete-Time Triangle Signal);grid on;%subplot(212); % frequency domainplot(FT_w/(2*pi),abs(DTFT_FT),r);xlabel(f);ylabel(|X(jomega)|);title(Spectrum(DTFT);grid on;% endEx. 4 DFT%=% DTFT vs DFT by triangle signal% by Tramps,
25、30/03/2013%=%clc,clear,close all% create a triangle signal%(1) set parametersH = 1; % heightT = 5; % cycle timeL = 2; % lengthn = 1; % number of cycles(1.2.3.)fs = 10; % sampling frequency%(2) create the signalspara = struct(H,H,T,T,L,L,n,1,fs,fs);x_D,t_D = myTriangle(para); %DTFT%stem(t_D,x_D);% DT
26、FTN = fs * T;k = -N:N;DTFT_w=-3*pi:0.1:3*pi;DTFT_FT = 0;for ii = 1:N DTFT_FTtmp = x_D(ii)*exp(-1j*DTFT_w*k(ii); DTFT_FT = DTFT_FT+DTFT_FTtmp;end%plot(DTFT_w/(2*pi),abs(DTFT_FT),r);% DFTN_DFT = 64;X_DFT,w,f = myDFT(x_D,N_DFT,100);%stem(w/(2*pi),abs(X_DFT),r);% show resultsfigure;%subplot(311);stem(t_
27、D,x_D,r); %DTFT time domainxlabel(t (s);ylabel(Amplitude);title(Discrete-Time Triangle Signal);grid on;%subplot(312);plot(DTFT_w/(2*pi),abs(DTFT_FT),r); %DTFT frequency domainxlabel(f);ylabel(|X(jomega)|);title(Spectrum(DTFT);grid on;%subplot(313);stem(w/(2*pi),abs(X_DFT),r); %DFT frequency domainxlabel(f);ylabel(|X(jomega)|);title(DFT);grid on; % end
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2