フィルターのクリア

FFT multiple input waves and plot on same graph

21 ビュー (過去 30 日間)
S
S 2024 年 6 月 29 日 19:15
コメント済み: S 2024 年 6 月 29 日 23:14
I am trying to plot the fft of multiple input waves on the same graph. The input epquation is the same but I want varying A values (A1,A2,...An) and varying freq values (freq1,freq2,...,freqn). I want to first plot these equations all on one graph, and plot all of the ffts of these inputs on another plot. This is what I have, I feel that there is a more efficient/better way to do this, as I want to have about 10 inputs. Thank you for your time!
%% Input Signal
fs = 20e3;
numFilts = 32; %
filter_number = numFilts;
freq1 = 1000; % Hz
Nperiods = 15; % we need more than 1 period of signal to reach the steady state output (look a the IR samples)
t = linspace(0,Nperiods/freq1,200*Nperiods); %
A1=1;
input1 = A1*sin(2*pi*freq1*t) + 0*rand(size(t));
A2=3;
freq2=2000;
input2 = A2*sin(2*pi*freq2*t) + 0*rand(size(t));
%FFT Input
FFT_Input1=fft(input1);
plot(t,FFT_Input1)
FFT_Input2=fft(input2);
plot(t,FFT_Input2)

採用された回答

Paul
Paul 2024 年 6 月 29 日 19:40
%% Input Signal
fs = 20e3;
numFilts = 32; %
filter_number = numFilts;
freq1 = 1000; % Hz
Nperiods = 15; % we need more than 1 period of signal to reach the steady state output (look a the IR samples)
t = linspace(0,Nperiods/freq1,200*Nperiods); %
dt = t(2); Fs = 1/dt;
N = numel(t);
f = (0:N-1)/N*Fs;
The following code can be vectorized. The FFTs should be plotted against frequency, not time. Probably want to plot abs(FFT)
%{
A1=1;
input1 = A1*sin(2*pi*freq1*t) + 0*rand(size(t));
A2=3;
freq2=2000;
input2 = A2*sin(2*pi*freq2*t) + 0*rand(size(t));
%FFT Input
FFT_Input1=fft(input1);
plot(t,FFT_Input1)
FFT_Input2=fft(input2);
plot(t,FFT_Input2)
%}
% A and freq are columne vectors because t is a row vector
A = [1; 3];
freq = [1000; 2000];
inputdata = A.*sin(2*pi.*freq.*t);
FFT = fft(inputdata,[],2); % fft across the columns
plot(f,abs(FFT))
% zoom in
copyobj(gca,figure)
xlim([0 5000])
  3 件のコメント
Paul
Paul 2024 年 6 月 29 日 22:36
That's how f (Hz) is defined when using the output of fft as uniformly spaced samples in frequency of one period of the Discrete Time Fourier Transform of a signal that's uniformly sampled in time.
We could have made a new plot using plot. Instead, I just used copyobj to copy the current axes (and all of its childrend) obtained from gca into a new figure.
S
S 2024 年 6 月 29 日 23:14
Thank you!! @Paul

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by