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 Center および File ExchangeSmoothing and Denoising についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by