FFT multiple input waves and plot on same graph
조회 수: 8 (최근 30일)
이전 댓글 표시
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)
댓글 수: 0
채택된 답변
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])
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!