• matlabdft

2015-06-05 16:14:11
1．掌握DFT函数的用法。 2. 利用DFT进行信号检测及谱分析。 3．了解信号截取长度对谱分析的影响。
• MATLABDFT

2012-10-18 11:35:34
The DFT of a vector x of length n is another vector y of length n: where ω is a complex nthroot of unity: This notation uses i for the imaginary unit,and p and j for indices thatrun from ...
The DFT of a vector x of length n is another vector
y of length n:

where ω is a complex nthroot of unity:

This notation uses i for the imaginary unit,and
p and j for indices thatrun from 0 to n–1. The indices
p+1and j+1 run from 1 to n, correspondingto ranges associated with MATLAB vectors.
Data in the vector x are assumed to be separatedby a constant interval in time or space,
dt = 1/fs or ds =1/fs,where
fs is the samplingfrequency. The DFT y is complex-valued.The absolute value of
y at index p+1 measures the amount of the frequency f =
p(fs / n) present in the data.

The first element of y, corresponding tozero frequency, is the sum of the data in
x. This DCcomponent is often removed from y sothat it does not obscure the positive frequency content of the data.

展开全文
• MATLABDFT定义源程序代码 保存为M文件后，直接调用即可
• 讲解：DFTMatlabMatlab、FFTSQL|MatlabIntroductionThis lab is a revision of the Discrete Fourier Transform (DFT), and theFast Fourier Transform (FFT), and an introduction to the Short-Time Fourier ...
讲解：DFT、Matlab、Matlab、FFTSQL|MatlabIntroductionThis lab is a revision of the Discrete Fourier Transform (DFT), and theFast Fourier Transform (FFT), and an introduction to the Short-Time Fourier Transform (STFT) and thespectrogram.The outcomes from the lab are to be handed in as a “folder” of results, showing thatyou have completed the steps of the lab successfully. A box in the right-handmargin indicates where an outcome is expected – like this:The Matlab programs you write will be short: you can print them out if you wish, buthand-written listings are OK too. Sketch graphs are also OK.1. Getting StartedIn your home directory, create the subdirectories “EBU6018” and “EBU6018/lab1”.Start Matlab. Use “cd ” to get into the directory “lab1” you have justcreated.2. Discrete Fourier TransformIn Matlab, type “edit” to start the Matlab editor.Create a Matlab function in the file “dft.m” to calculate the Discrete FourierTransform of a signal. Recall that the DFT is given by [Qian, eqn (2.34)][NB: The “j” is missing in Qian’s definition of WN on p33.]Hints:• Start your function with function sw = dft(st)so “st” is the time waveform vector, and “sw” is the frequency waveform vector• Matlab vectors (e.g. st and sw) start from 1, not zero, so use “n-1” and “m-1” torefer to the appropriate element• Assume that N=M, and use the “length(st)” to find the value to use for these.An example outline for your Matlab function is provided below.EBU6018 Advanced Transform MethodsLab 1: DFT, FFT and STFTDepartment of Electronic Engineering and Computer ScienceExample DFT function outline in MatlabGenerate some waveforms to test your function. Test your dft on at least thefollowing signals:• Uniform function: “s=ones(1,64);”• Delta function: “s = ((1:64)= =1);”[NB: “1:64” generates the vector (1 2 … 64) ].• Sine wave: “s = sin(((1:64)-1)*2*pi*w/100)” for various values of w.Why do we need to use “(1:64)-1”?What values of w give the cleanest dft?What happens if we use “cos”?• Symmetrical rectangular pulse: “s = [0:31 32:-1:1](NB: Why doesn’t this “look” symmetrical? Remember that the DFT repeats, sothe time interval 32 .. 63 is “the same as” the interval -31 .. -1).The following function may be useful to display your results:If you want zero frequency (or time) to appear in the middle of your plot, use“fftshift”, e.g. “stem4(fftshift(dft(s)));”Explain your results in terms of what you know about the Fourier Transform.function stem4(s)% STEM4 - View complex signal as real, imag, abs and anglesubplot(4,1,1); stem(real(s)); title(Real);subplot(4,1,2); stem(imag(s)); title(Imag);subplot(4,1,3); stem(abs(s)); title(Abs);subplot(4,1,4); stem(angle(s)); title(Angle);endfunction sw = dft(st)% DFT - Discrete Fourier TransformM = length(st);N = M;WN = exp(2*pi*j/N);% Main loopfor n=0:N-1 temp = 0; for m=0:M-1 [** Do something useful here **] end sw(n+1) = temp;end 3. Comparison with Matlab’s FFT functionMatlab has a built-in Fast Fourier Transform, “fft”.Compare the results of your dft against the built-in fft. Are the results the same? Ifso, why: if not, why not?Find out the complexity of your dft and the built-in fft, i.e. how long they take toperform their calculation for various lengths of s. Use “tic” and “toc” to measure thetime taken to perform the operation, so e.g. tic; dft(ones(1,4)); toc % No “;” for final expressionwill report how long a 4-point DFT took to calculate.Hint: You may find your dft is too fast for tic/toc to measure any useful difference. Ifso, run it several times, e.g.tic; for (i=1:1e4) dft(ones(1,4)); end; toc(Of course, remember to divide your measure by the number of times round the loop!)Make a log-log plot (using “loglog”) showing the time increase with the size n of s.On your plot, show that the DFT takes O(n2) time, while the FFT takes O(n log n).Hint: Use “hold on” if you want to add a second “loglog” plot to an existing plot.Explain what this tells you about the DFT compared to the FFT in real applications,i.e. as n gets larger.*[OMIT]3.1 DIY-FFT [Optional, but highly recommended] [OMIT]Write a Matlab function (called e.g. “my_fft”) to calculate the FFT of a signal. Ifyou like, you could write this as a recursive function (one that calls itself) – see theoutline below.Plot and compare its speed to the DFT, showing that your “my_fft” function takesO(n log n) time rather than O(n2) timeDerivation of the FFT:odd the of FFT point- the is and the is where samples, even the ofFFT point:get weodd for and even for usingeven oddNotes:(1) The above only works if N is a power of 2 (64, 128, 1024, etc), so your programmay not work if you use other lengths of s (you could check this, if you like!)(2) Note that a 1-point FFT of a signal is the signal itself, so the 1-point FFT is easy(to be sure of this, check the DFT formula with N=1).(3) Remember that Matlab vectors start at 1 (not zero), so go from 1...N not 0…N-1Example outline of Matlab function to calculate FFT:function sw = my_fft(st);% Recursive Implementation of Fast Fourer TransformN = length(st);% check length of N is 2^kif (rem(log(N),log(2))) disp(slow_fft: N must be an exact power of 2) returnendWN = exp(2*pi*j/N);% split st into even and odd samplesst_even = st(1:2:end-1);st_odd = st(2:2:end);% implement recursion here...if (N==2) g = st_even; % = st(0+1) h = st_odd; % = st(2) gg = [g g]; hh = [h -h];else g = [** Something useful here **]; h = [** Something useful here **]; gg = [g g]; hh = WN.^(-[0:N-1]).*[h h];endsw = gg+hh; 4. Single Windowed Fourier TransformSave one of the audio files on the course details page athttps://www.student.elec.qmul.ac.uk/courseinfo/EBU6018/into your “lab1” directory.Read into Matlab, using “s = wavread(file.wav)”.Where ‘file.wav’ could be ‘dbarrett2.wav’Plot the magnitude (“abs”) of the FFT of the waveform. (“plot” is probably betterthan “stem” for these longer signals). Explain what this tells you about the waveform.We will now construct a function that will allow you to “zoom in” on a short sectionof the signal. To smooth out end effects, we will use a “Hanning” window to multiplythe segment that we select. You can show the Hanning window of length 256 inMatlab using “plot(hanning(256))”.Construct a Matlab function in the file “wft.m” that will select a section from a fileand window it. The function “wft” is to be called as follows: y = wft(s, t, n);where s is the signal, t is the time in the middle of the window, and n is a windowlength. You might use the following steps:1) Select the desired section from the signal, for example usings(floor(t-n/2)+(1:n)); (if you don’t see how this works, try “help colon”).2) Multiply elementwise with a Hanning window of length n, using “.*”3) Use the built-in Matlab fft function to calculate the DFT.Plot the magnitude of this single windowed Fourier transform of your signal forvarious values of t and n (note that values of t near the beginning and end of s maycause an error, depending on how clever you were at step (1)). Try also plotting with alog y-scale. Explain the difference between these results*[OMIT][Optional]: Make a matlab m-file that loops through different values for t in steps ofe.g. 50, using “pause” between each step.5. STFT and SpectrogramNow we will construct a “spectrogram” to visualize the time-frequency information ina signal on one image.Read the Matlab documentation for the Matlab “specgram” function (try “helpspecgram” for information).Using specgram, investigate the audio files on the course details page athttps://www.student.elec.qmul.ac.uk/courseinfo/EBU6018/Try different window sizes (“NFFT”) to see the effect. For fastest results on longfiles, use powers of 2 (Why?). Record what values of window size give bestvisualization results for different files, and suggest why. 5.1 Analysis of Piccolo soundFrom the course webpage download ‘piccolo.wav’ and load it into Matlab using:[x fs] = wavread(‘piccolo.wav’); % fs = sampling frequencyRecord the sampling frequency, fs.If you have headphones, try listening to the signal, usingsoundsc(x,fs); %fs is the sampling frequency of xPlot a spectrogram of x, using the ‘specgram’ function.From the spectram plot, estimate the fundamental frequencies (f0) of the 3 notes inthe sample, giving your answers in Hz.Repeat your estimates for different window sizes.Notes: You will need to use your window size, (NFFT) and the value for the samplingfrequency (fs) in your calculation. Figure 1 is given as a guide to help you.Make your calculation in 2 ways:(1) by calculating the frequency range displayed by specgram, and(2) by supplying specgram with the correct value fs when you call it.Check that both of these methods agree.Figure 1: Angular frequency representation for f0 estimationExplain what happens to the accuracy of your f0 values as you vary the window size.For further experimentation, try visualizing other “wav” files available on the internetusing your spectrogram. *[OMIT]5.1 DIY STFT and Spectrogram [Optional, but highlyrecommended]Construct a Matlab function “sg(s,N)” in a file called “sg.m” to compute aspectrogram of a waveform s with window size N (NFFT in Matlab’s specgram).To do this, your function shouldi) divide the signal “s” into sections of length N,ii) multiply s by a Hanning windowiii) perform an FFT of each section, andiv) construct a matrix where each column is the absolute value of one FFTHints:• You can select the k-th segment of length N using “s( ((1:N)+(k-1)*N) )”• You can get a Hanning window of length N by using the Matlab function“W=hanning(N)”. Multiply by a segment s1 using “s1.*W” (dot-star).• Since the signal is real, you know the FFT result will be Hermitian symmetric, soyou can discard one half of the vector of results.• You can set the n-th column of a matrix to be a 1xN vector y by usingM(:,n) = yPlot usingimagesc(log10(abs(B))); axis xy;where B is the spectrogram (“axis xy” restores the origin to the bottom).How should you call “specgram” to get the most similar results to your function “sg”?Modify your function “sg” so that it overlaps its windows in the same way as thedefault operation of “specgram”.6. Handing InCompile the answers to the exercises, including the answers to specific questions,program listings (including comments), and plots from experiments, into a “folder” ofresults showing that you have completed the lab, and submit electronically. You donot need to write a formal report.IMPORTANT: Plagiarism (copying from other students, or copying the work ofothers without proper referencing) is cheating, and will not be tolerated.IF TWO “FOLDERS” ARE FOUND TO CONTAIN IDENTICAL MATERIAL,BOTH WILL BE GIVEN A MARK OF ZERO.Updated by MPD, MEPDModified ARW for EBU6018.转自：http://www.daixie0.com/contents/12/4346.html
展开全文
• 而在Matlab中的绘图操作，是通过将一些离散的点连接而成。求连续信号的频谱，应用的是离散傅立叶变换(DFT)。下面这段程序是绘制简单的Sa函数时域和频域图像。Sa(t)=sin(200t)/200t对于这个函数我们要说明一点。由傅...
所谓信号的谱分析，就是时频域转换，变成数学知识，就是对信号进行傅立叶变换(FT)，连续信号与系统的傅立叶变换不便于用计算机进行计算。而在Matlab中的绘图操作，是通过将一些离散的点连接而成。求连续信号的频谱，应用的是离散傅立叶变换(DFT)。下面这段程序是绘制简单的Sa函数时域和频域图像。Sa(t)=sin(200t)/200t对于这个函数我们要说明一点。由傅立叶变换理论知道，若信号持续时间有限长，则其频谱无限宽；若信号频谱有限宽，则其持续时间无限长。因此要对其进行谱分析就必须在时域采样无穷多个点，这又显然不满足DFT变换的要求。从工程实际角度来看，滤除幅度很小的高频成分和截去幅度很小的部分时间信号是允许的，因此这里我们截取(-5≤t≤5)时间段的Sa(t)。下面是程序代码：Sa。mCleart0=10;%定义时间长度10s，即(-5≤t≤5)ts=0。001;fs=1/ts;%定义采样周期、采样频率df=0。5;%定义频谱分辨率(见说明1)。t=[-t0/2:ts:t0/2];%定义时间序列--------------------------------------------------------------------------------------------------%定义函数Sa(t):x=sin(200*t);m=x。/(200*t);w=t0/(2*ts)+1;%由于sin(t)/t在t=0时Matlab会得出值NaN，所以需要加以修正。m(w)=1;---------------------------------------------------------------------------------------------------?T变换：[M,mn,dfy]=fftseq(m,ts,df);%对序列m进行DFT,fftseq()为自定义函数，代码在下面。M=M/fs;%频率缩放f=[0:dfy:dfy*length(mn)-dfy]-fs/2;%定义频率轴，将频谱搬移到0频附近。----------------------------------------------------------------------------------------------------%绘图：pause;subplot(2,1,1);plot(t,m);xlabel('时间');axis([-0。15,0。15,-0。5,2]);subplot(2,1,2);plot(f,abs(fftshift(M)));?tshift见说明4xlabel('频率');axis([-50,50,0,0。02]);-------------------------------------------------------------------------------------------%序列的DFT函数function[M,m,dfy]=fftseq(m,tz,df)%m:时域序列%tz:采样周期?:变换所要求达到的最低频谱分辨率%M:变换后的频域序列?y:实际的频谱分辨率%fz=1/tz;ifnargin==2%nargin函数表示函数原参数的个数，即看有没有要求频谱分辨率n1=0;elsen1=fz/df;%n1表示满足频谱分辨率的最小采样点数endn2=length(m);%n2表示满足频域采样定理(见说明2)的最小采样点数。n=2^(max(nextpow2(n1),nextpow2(n2)));%n表示实际采样点数，取n1和n2二者中的大值，而且进行DFT变换时采用Matlab自带的FFT变换函数，因此需要n为2的幂次。Nextpow2()见说明3M=fft(m,n);dfy=fz/length(M);%实际的频谱分辨率=采样频率fz/实际采样点数length从图中可以看出，在频率函数的拐角处有细微的波动，这是因为我们一开始说的，截取(-5≤t≤5)时间段做DFT产生的原因。说明1：频谱分辨力----谱分析中能够分辨的两个频谱分量的最小间隔。N点DFT就是对信号的频谱在[0-fs](fs指采样频率)上的N点等间隔采样，那么频谱分辨率df=fs/N。说明2：频域采样定理----如果序列时域x(n)的长度为M，则只有当频域采样点数N≥M时，才可由频域采样X(k)恢复原序列x(n),否则产生时域混叠现象。说明3：nextpow2(x)----取大于并最接近x的2次幂。说明4：matlab中的fftshift的功能是零频移到频谱中心,其实就是将一个数组的前一半和后一半对调。具体点说，做n(n为偶数)点FFT不用FFTSHIFT时，第1点对应的模拟频率是零频，第2点是Fs/n，第n/2+1点是Fs/2，第n点是Fs(n-1)/n。用FFTSHIFT后，将Fs/2到Fs(n-1)/n的频点，也就是第n/2+1点到第n点搬移到第1到第n/2点，将第1点到第n/2点搬移到第n/2+1到第n点。所以原来的第1点(模拟频率是零频)搬移到第n/2+1点。说晕了吧，看下面两幅图就明白了，前一个是没有进行fftshift变换的，后一个是进行fftshift变换之后的。全部
展开全文
• DFT计算线性卷积用DFT计算线性卷积1 基本原理1.1用 DFT实现线性卷积的原理线性与圆周卷积分别由下式给出其中 x[n] : 0≤n ≤P －1 ( 0≤m ≤P －1y[n]: 0≤n ≤L －1 ( 0≤n － m ≤L －1w[n]的最大长度为 ：L+P-1...
用DFT计算线性卷积用DFT计算线性卷积1 基本原理1.1用 DFT实现线性卷积的原理线性与圆周卷积分别由下式给出其中 x[n] : 0≤n ≤P －1   (  0≤m ≤P －1y[n]:   0≤n ≤L －1  (  0≤n － m ≤L －1w[n]的最大长度为 ：L+P-1，单 wp[n] 的长度为 N。当N≥L+P －1 ,  wp[n] = w[n]; 当 N ≤ L+P －1, wp[n] ≠ w[n];所以要使圆周卷积等于线性卷积而不产生混叠的必要条件为：N ≥ P+L－1即线性与圆周卷积一致的样本为:       P+L － N－1≤ n ≤N －11.2 重叠保留法原理设h(n)的点数为M，信号x(n)为很长的序列。我们将x(n)分解为很多段，每段为L点，L选择成和M的数量级相同，用xi(n)表示x(n)的第i段：要求x(n)和h(n)的卷积时，若x(n)的点数很多，远大于h(n)的点数M时，通常不允许等x(n)全部采集齐后再进行卷积，否则，使输出相对于输入有较长的延时。因此需要采用分段卷积或称分段过滤的办法，即将x(n)分成点数和h(n)相仿的段，分别求出每段的卷积结果，然后用一定方式把它们合在一起，便得到总的输出，一种分段卷积的方法就是重叠保留法。设h(n)的点数为M，信号x(n)为很长的序列。我们将x(n)分解为很多段，每段为L点，L选择成和M的数量级相同，取N=L+M-1用xi(n)表示x(n)的第i段。重叠保留法先将x(n)分段，每段L=N-M+1个点，由于xi(n)*h(n)为L+M-1 点，故先对xi(n)及h(n)补零值点，补到N点不同之处是，序列中补零处不补零，而在每一段的前边补上前一段保留下来的(M-1)个输入序列值， 组成L+M-1点序列xi(n)，如图8-27(a)所示。如果L+M-1<2m， 则可在每段序列末端补零值点，补到长度为2m，这时如果用DFT实现h(n)和xi(n)圆周卷积，则其每段圆周卷积结果的前(M-1)个点的值不等于线性卷积值，必须舍去。为了说明以上说法的正确性，我们来看一看图8-28。任一段xi(n)(为N点)与h(n)(原为M点，补零值后也为N点)的N点圆周卷积由于h(m)为M点，补零后作N点圆周移位时，在n=0,1,…,M-2的每一种情况下，h((n-m))NRN(m)在0≤m≤N-1范围的末端出现非零值， 而此处xi(m)是有数值存在的，图8-28(c)，(d)为n=0, n=M-2的情况，所以在0≤n≤M-2这一部分的yi(n)值中将混入xi(m)尾部与h((n-m))N·RN(m)尾部的乘积值，从而使这些点的yi(n)不同于线性卷积结果。但是从n=M-1开始到n=N-1，h((n-m))NRN(m)=h(n-m)(如图8-28(e)，(f)所示)，圆周卷积值完全与线性卷积值一样，yi(n)就是正确的线性卷积值。因而必须把每一段圆周卷积结果的前(M-1)个值去掉， 如图8-28(g)所示。  ?因此，为了不造成输出信号的遗漏，对输入分段时，就需要使相邻两段有M-1个点重叠(对于第一段，即x0(n)，由于没有前一段保留信号，则需要在序列前填充M-1 个零值点)，这样，若原输入序列为x′(n)(n≥0 时有值)，则应重新定义输入序列0≤n≤N-1其他n              ( i=0, 1, … )在这一公式中，已经把每一段的时间原点放在该段的起始点，而不是x(n)的原点。这种分段方法示于图8-27中，每段xi(n)和h(n)的圆周卷积结果以yi(n)表示，如图 8-27(b)所示，图中已标出每一段输出段开始的(M-1)个点，0≤n≤M-2部分舍掉不用。把相邻各输出段留下的序列衔接起来，就构成了最后的正确输出， 即式中:M-1≤n≤N-1其他n这时，每段输出的时间原点放在yi ′ (n)的起始点，而不是y(n)的原点。图1-1 用保留信号代替补零后的局部混叠现象图1-2 重叠保留法示意图2函数说明由于是用重叠保留法计算线性卷积，根据重叠保留法的原理，在MATLAB软件的环境下可以创造一个相应的函数求x(n)和h(n)的线性卷积。设h(n)的点数为M，信号x(n)为很长的序列。把x(n)分成长为L 的小段xi(n),每段与前一段重叠M-1 个样本的多段,保留后面的(L-M+1)个输出样本,最后把这些输出连成一个序列，结果即为x(n)和h
展开全文
• 现代电子技术 ModernElectronicsTechnique 2013年6月1日 第36卷第11期 Jun.2013 Vol.36 No.11 0 引 言 频谱分析在数字信号处理中用途广泛：如滤波、检测等方面，这些都需要DFT(Discrete Fourier Transform)运算[1-3]...
• title('DFT N=60') %%%%%%%%%%%%注：X(k)为x(n)的DFT(x(ejw))在区间[0,2pi]上的N点等间隔采样1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 3.对2，进一步增加截取长度和DFT点数，如...
• matlab-DFT

2014-05-14 09:30:51
matlab编写的DFT程序，很实用哟
• 使用matlab做任意长度的DFT，绘制时域频域图像，对比。更改N为时域信号长度，L为做DFT点数。N，则补零。N,L可更改参数。
• MATLAB编程DFT

2014-12-30 09:21:44
function [XK]=DFT(xn) N=length(xn); n=0:1:N-1; k=0:1:N-1; WN=exp(-1j*2*pi/N); nk=n'*k; WNnk=WN^nk; XK=xn*WNnk; end
• DFTmatlab源代码DFT 使用MATLAB的离散傅立叶变换 （dft.m）：使用MATLAB的离散傅立叶变换代码。 （amplitudes.dat）：matlab DFT算法的输入是一个文件（amplitudes.dat）。 （output.txt）：将DFT频率值保存在...
• MATLAB实现DFT-matlab程序.txt 如题。希望能够抛砖引玉。
• Matlab实现DFT

万次阅读 多人点赞 2018-01-10 14:17:31
掌握DFT的概念和用法(DFT实质：有限长序列M傅里叶变换的有限点N的离散采样) % 在频域分析信号分两种： % （1）.对确定性信号进行傅里叶变换，分析频谱信息。 % （2）.随机信号的傅里叶信号不存在，转向研究它...
• 2.5 利用matlab计算DFT

千次阅读 2017-06-10 12:03:51
2.5 利用matlab计算DFT
• signal.slx为simulink的一个仿真模块，用作对信号采样 ...myDFT.m为DFT的实现 n1为选取的一个周期点数（与simulink模块采样周期匹配,点数=T/Ts） T:最小周期 Ts：采样周期 运行：先运行signal.slx，再运行myDFT.m
• 用快速卷积法计算两个有限长度序列的线性卷积
• 基于MatlabDFT及FFT频谱分析.pdf
• %DFTMATLAB实现%xn: input length_limited sequence%N: length of sequence%XK: DFT coefficients for xnfunction[XK]=dft(xn,N)n=[0:N-1]k=[0:N-1]wnk=exp(-j*2*pi/N).^(n’*k);XK=xn*wnk%在序列两点之间插入r-1...
• DFTMatlab代码

2014-04-08 22:13:11
Matlab代码开发DFT,里面有详细的过程和照片，是课程作业的一部分
• MatlabDFT频谱误差分析中的应用.pdf

...

matlab 订阅