资源简介
matlab画频谱图很方便的一个函数,无须每次画频谱时进行fft变换!
代码片段和文件信息
% plotspec(xTs) plots the spectrum of the signal x
% Ts = time (in seconds) between adjacent samples in x
function plotspec(xTs)
N=length(x); % length of the signal x
t=Ts*(1:N); % define a time vector
ssf=(-N/2:N/2-1)/(Ts*N); % frequency vector
fx=fft(x(1:N)); % do DFT/FFT
fxs=fftshift(fx); % shift it for plotting
subplot(211) plot(tx) % plot the waveform
xlabel(‘seconds‘); ylabel(‘amplitude‘) % label the axes
subplot(212) plot(ssfabs(fxs)) % plot magnitude spectrum
xlabel(‘frequency‘); ylabel(‘magnitude‘) % label the axes
%verify parseval equalize power using
%sum(abs(fxs).^2)/N
%sum(abs(x).^2)
% use axis([02-1.11.1]) for specsquare.eps
% %% Reading Arbitrary Format Text Files with TEXTSCAN
% % This example shows how to read an arbitrary format text file with
% % % |textscan|. This function is similar to |textread| however it also
% % allows you to read the file one block at a time and each block can have
% % a different format. The information in the text file test80211.txt is
% % the result from a wireless network communication quality test. Each block
% % is a different environment (e.g. mobile indoor outdoor). The numerical
% % results show the data error rate over a range of noise levels for a
% % number of independent tests.
%
% % Copyright 1984-2006 The MathWorks Inc.
% % $Revision: 1.1.6.7 $ $Date: 2007/10/15 22:53:31 $
%
% %% File Format
% % After 4 lines of introduction this particular file is made up of a
% % number blocks of data each with the following format:
% %
% % * Two headerlines of description
% % * A parameter m
% % * A p x m table of data
% %
% % All the information is read into cell arrays allowing the storage
% % of different size blocks.
%
% %% Open the Text File for Reading
% fid = fopen(‘tes
评论
共有 条评论