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)

采纳的回答

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.

请先登录,再进行评论。

更多回答(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