image thumbnail

EXPO 2011 Signal Processing Workflow Demo Files

by

 

MATLAB EXPO 2011 Signal Processing Workflow Demo Files

spectrum_demo.m
%% eXyNg͎@ɂ錋ʂ̈Ⴂ
%%
% 
clear all, close all

%% p[^ݒƃTvg`
Fs = 1000;                % Sampling frequency
t = (0:499)/Fs;            % One second worth of samples
A = [1 2];                % Sinusoid amplitudes (row vector)
f = [150;140];            % Sinusoid frequencies (column vector)
xn = A*sin(2*pi*f*t) + 0.1*randn(size(t));

%% FFTDFT̈Ⴂɂ‚
% MATLABŎgFFTx[X̃XyNg͂O
% FFT֐ɂ‚Đ܂B
% FFT֐́AFFT_ɂďeύX܂B
% FFT_2ׂ̂̏ꍇFFTiFast Fourier Transformj
% łȂꍇDFTiDiscrete Fourier Transformjgp܂B
tic
sprintf('\n 131072_FFToߎ')
Xn0 = fft(xn,2^17);
toc
tic
sprintf('\n\n 131071_DFToߎ')
Xn1 = fft(xn,2^17-1);
toc
Xnsp0 = (abs(Xn0)).^2/length(xn);
f0 = (0:length(Xn0)-1)/length(Xn0)*Fs;
figure, plot(f0, 20*log10(Xnsp0)),grid on
xlim([0 Fs/2])

%% ֐x[X̃XyNǵi֐L薳j
% ֐ɂăTCh[u͌A_Ci~bNW
% シ邪AC[u͑ȂAg\͒ቺB
figure
subplot(2,1,1)
periodogram(xn,[],1024,Fs)
subplot(2,1,2)
periodogram(xn,hamming(length(xn)),1024,Fs)

%% IuWFNgꂽXyNg͋@\
% p[^ύX⎎s낷ꍇ͂̂ق
% ₷B
figure
Hs = spectrum.periodogram;
psd(Hs,xn,'Fs',Fs,'NFFT',1024,'SpectrumType','onesided')

%% M̃Tv炷
% TCh[ủe傫Ȃg\ቺ
t = (0:Fs/10)/Fs;            % One second worth of samples
xn = A*sin(2*pi*f*t) + 0.1*randn(size(t));
% IuWFNgꂽXyNg͋@\
% p[^ύX⎎s낷ꍇ͂̂ق₷
figure
subplot(2,1,1)
Hs = spectrum.periodogram;
psd(Hs,xn,'Fs',Fs,'NFFT',1024,'SpectrumType','onesided')

%% ֐ɂăTCh[ủe͒ጸ”\
subplot(2,1,2)
Hs = spectrum.periodogram('Hamming');
psd(Hs,xn,'Fs',Fs,'NFFT',1024,'SpectrumType','onesided')
shg
%% EF`@ɂXyNg
% EF`@ł͎nf[^ZOgɕ
% eZOgɂ‚ďCsIhOvZA
% ̌APSD ̕ςvẐłB
% ̕UX܂B
% ZOgԂ̃I[o[bv͏璷ȏ𓱓܂A
% ̉éA`EBhEgp邱ƂŌył܂B
t = (0:Fs/3)/Fs;            % One second worth of samples
A = [2 8];
xn = A*sin(2*pi*f*t) + 5*randn(size(t));

%% sIhOWelch@̔r
figure
subplot(1,2,1)
Hs = spectrum.periodogram;
psd(Hs,xn,'Fs',Fs,'NFFT',512,'SpectrumType','onesided')
ylim([-40 10])

% Welch@̓s[N̕LȂĂ܂
% mCYƂ̋ʂ₷ȂĂ
subplot(1,2,2)
Hs2 = spectrum.welch('rectangular',150,50);		% Segment150sample, Overlap50sample
psd(Hs2,xn,'Fs',Fs,'NFFT',512);
ylim([-40 10])

%% Welch@ŃZOgጸ
% ɕUጸɂ̓ZOg̃Tv炵
% I[o[bv𑝂₹΂悢As[N͍LȂߐڂg
% ̋ʂɂȂĂ܂B
% figure
hold on
subplot(1,2,2)
Hs2 = spectrum.welch('rectangular',100,75);		% Segment150sample, Overlap50sample
A=psd(Hs2,xn,'Fs',Fs,'NFFT',512);
% set(gca,'LineWidth',8)
ylim([-80 10])

%% }`e[p[@ɂXyNg
% el𖞂œKȑ֐߂ďsƂ
% UƉ𑜓xƂコB
close all
Fs = 1000;                % Sampling frequency
t = (0:Fs)/Fs;            % One second worth of samples
A = [1 2];                % Sinusoid amplitudes
f = [150;140];            % Sinusoid frequencies
xn = A*sin(2*pi*f*t) + 0.1*randn(size(t));

figure
subplot(1,2,1)
Hsp = spectrum.periodogram;
psd(Hsp,xn,'Fs',Fs,'NFFT',1024,'SpectrumType','onesided')
ylim([-60 10])
subplot(1,2,2)
Hsmt1 = spectrum.mtm(3/2,'adapt');	% 
psd(Hsmt1,xn,'Fs',Fs,'NFFT',1024)
ylim([-60 10])

%% }`e[p[@Ńp[^
%  - ш敝̐ςŗ^p[^ɂ蕪UƉ𑜓x
% oX𒲐邱ƂoB
% sIhOƔrƕUȂ
% 𑜓xコB
figure
subplot(1,2,1)
Hsmt1 = spectrum.mtm(4,'adapt');
psd(Hsmt1,xn,'Fs',Fs,'NFFT',1024)
ylim([-60 10])
subplot(1,2,2)
Hsmt2 = spectrum.mtm(3/2,'adapt');
psd(Hsmt2,xn,'Fs',Fs,'NFFT',1024)
ylim([-60 10])

%% pgbN@
% MZꍇɃmpgbN@pgbN@
% 𑜓xłB
% mpgbN@f[^璼 PSD 𐄒肷ɁA
% pgbN@̓f[^zCgmCY`VXe
% ͂ʂ̏o͂Ƃăf̂ŁAʂƂĂ̐`
% f̃p[^[𐄒肷B
% ʓIɐ`VXeƂ͑SɃf1/A(z)ŁA_͑Szʂ̌_ɂB
% ͎ȉAiARjfȂ̂ŁApgbN@̓XyNg
% ARfƂ݂ȂB
close all
%% [-EH[J[AR@
% [-EH[J[`VXeƂɂA
% ARp[^[vZ܂B
% SɃf̂߃XyNgX[YɂȂB
load mtlb
figure
subplot(1,2,1)
Hwl = spectrum.welch('hamming',256,50);
psd(Hwl,mtlb,'Fs',Fs,'NFFT',1024)
subplot(1,2,2)
Hyl = spectrum.yulear(14);
psd(Hyl,mtlb,'Fs',Fs,'NFFT',1024)

%% o[O@
% ARp[^Levinson-DurbinA[@𖞑鐧̂ƂŁA
% tH[[hAobN[h\̍ŏ덷ŏɂ邱
% ɂAȉAfMɓK܂B

%% Mɑ΂o[O@̓Kp
% ̃fAf[^̒́AS/N 䂪̂ɑ΂Ă
% xႢBʂ̓[-EH[J[AR@ƂقړɂȂB
close all
figure
subplot(1,2,1)
Hyl = spectrum.yulear(14);
psd(Hyl,mtlb,'Fs',Fs,'NFFT',1024)
subplot(1,2,2)
Hbrg = spectrum.burg(14);      % 14th order model
psd(Hbrg,mtlb,'Fs',Fs,'NFFT',1024)

%% gMɑ΂o[O@̓Kp
% o[O@̊{IȒ́AmCYxႭf[^Zꍇ
% M̒ɑ݂ɋ߂g̐g𕪉ł邱ƂłB
% ʑUɉe^̂ZB
Fs = 1000;               % Sampling frequency
t = (0:Fs)/Fs;           % One second worth of samples
A = [1 2];               % Sinusoid amplitudes
f = [160;140];           % Sinusoid frequencies
xn = A*sin(2*pi*f*t+(0)) + 0.1*randn(size(t));
% ʑ+/-ĐUω邱ƂmF
figure %#
subplot(1,2,1)
% Hwlc = spectrum.welch('hamming',256,50);	%#
% psd(Hwlc,xn,'Fs',fs,'NFFT',1024)			%#
Hyl = spectrum.yulear(14);		%#
psd(Hyl,xn,'Fs',Fs,'NFFT',1024)	%#
ylim([-60 0])
subplot(1,2,2)
Hbrg = spectrum.burg(14);
psd(Hbrg,xn,'Fs',Fs,'NFFT',1024)
ylim([-60 0])

%% U@
% U@́AO\덷ŏɂ悤ARfvZ܂B
load mtlb
figure
subplot(1,2,1)
Hyl = spectrum.yulear(14);
psd(Hyl,mtlb(1:64),'Fs',Fs,'NFFT',1024)
ylim([-90 -30])
subplot(1,2,2)
Hcov = spectrum.cov(14);	      % 14th order model
psd(Hcov,mtlb(1:64),'Fs',Fs,'NFFT',1024)
ylim([-90 -30])

%% CU@
% CU@́AO/\덷ŏɂ悤ARfvZ܂B
figure
subplot(1,2,1)
Hyl = spectrum.yulear(14);
psd(Hyl,mtlb(1:64),'Fs',Fs,'NFFT',1024)
ylim([-90 -30])
subplot(1,2,2)
Hmsc = spectrum.mcov(14);	      % 14th order model
psd(Hmsc,mtlb(1:64),'Fs',Fs,'NFFT',1024)
ylim([-90 -30])

%% MUSIC@
% ȑ֍šŗL͂x[Xɂg@
% dM (MUSIC) @

Fs = 1000;               % Sampling frequency
t = (0:99)/Fs;           % One second worth of samples
A = [1 2];               % Sinusoid amplitudes
f = [150;190];           % Sinusoid frequencies
xn = A*sin(2*pi*f*t) + 0.8*randn(size(t));
figure
subplot(1,2,1)
Hyl = spectrum.yulear(14);
psd(Hyl,xn,'Fs',Fs,'NFFT',256)
ylim([-55 -5])
% Hwl = spectrum.welch('rectangular',50,10);
% psd(Hwl,xn,'Fs',Fs,'NFFT',1024)
subplot(1,2,2)
Hmsc = spectrum.music(4,22,84);			% g, ZOg, I[o[bv
pseudospectrum(Hmsc,xn,'Fs',Fs)			% ^XyNg̕\
ylim([-35 15])

%% ŗLxNg@
% Schmidt ̌ŗLԉ͖@瓱oMUSICASY
% dݕto[WgpāAM܂͑֍s񂩂[XyNg𐄒
clc
% figure
subplot(1,2,1)
Hyl = spectrum.yulear(14);
psd(Hyl,xn,'Fs',Fs,'NFFT',256)
ylim([-55 -5])
% Hwl = spectrum.welch('rectangular',50,10);
% psd(Hwl,xn,'Fs',Fs,'NFFT',1024)
subplot(1,2,2)
Heig = spectrum.eigenvector(4,22,84,'Rectangular',5);	% g, ZOg, I[o[bv
pseudospectrum(Heig,xn,'Fs',Fs)			% ^XyNg̕\
ylim([-65 -15])

Contact us