Plotting results of DFT loop

조회 수: 3 (최근 30일)
Alexandr Lozak
Alexandr Lozak 2019년 9월 23일
답변: Guru Mohanty 2020년 1월 13일
I am trying to make multiple DFT from the code of single DFT. But cant figure out how to change plot inputs to see results as it was for single DFT.
%% Plotting single graph of DFT
va= DifVD(1:end); %DifDr(ss(1):ss(2),1);%
y = va; %the signal you want to fft
L = length(y);
Fs=10;
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
fg=figure('Renderer', 'painters', 'Position', [100 100 700 500]);
plot(f,2*abs(Y(1:NFFT/2+1))) % semilogx(f,2*abs(Y(1:NFFT/2+1)))%
%% Plotting multiple graphs of DFT
ss=300000:6000:525158;
k=length(ss);
for i=1:k
va(:,i)= DifDr(ss(i):ss(i+1),1);
y = va;
L = length(y(1));
Fs=10;
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y(:,i) = fft(y(:,i),NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
fg=figure('Renderer', 'painters', 'Position', [100 100 700 500]);
plot(f,2*abs(Y(1:NFFT/2+1,i)))
end
How should i change last line to plot multiple results?
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 9월 23일
Multiple DFT with respect to whcih parameters (In this multiple inputs)?
Alexandr Lozak
Alexandr Lozak 2019년 9월 24일
In general it should look like
plot(f, Y(1:NFFT/2+1,i));
but i dont understand why it doesnt work for many plots

댓글을 달려면 로그인하십시오.

채택된 답변

Guru Mohanty
Guru Mohanty 2020년 1월 13일
Hi, it is difficult to provide an exact solution without your original data. However, when I executed your code using random data, at last iteration it is trying to access beyond the last element. After modifying the loop parameter, the code should work.
clc;
clear all;
DifDr=randi(100,525158,5); % Demo data
ss=300000:6000:525158;
k=length(ss);
for i=1:k-1
va(:,i)= DifDr(ss(i):ss(i+1),1); %
y = va;
[L , ~]= size(y);
Fs=10;
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
f = Fs/2*linspace(0,1,NFFT/2+1);
Y(:,i) = fft(y(:,i),NFFT)/L;
% Plot single-sided amplitude spectrum.
fg=figure('Renderer', 'painters', 'Position', [100 100 700 500]);
plot(f,2*abs(Y(1:NFFT/2+1,i))); % semilogx(f,2*abs(Y(1:NFFT/2+1)))%
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by