필터 지우기
필터 지우기

FFT multiple input waves and plot on same graph

조회 수: 3 (최근 30일)
S
S 2024년 6월 29일
댓글: S 2024년 6월 29일
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일
%% 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일
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일
Thank you!! @Paul

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by