# FFT multiple input waves and plot on same graph

4 vues (au cours des 30 derniers jours)
S le 29 Juin 2024
Commenté : S le 29 Juin 2024
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 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Paul le 29 Juin 2024
%% 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 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Paul le 29 Juin 2024
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 le 29 Juin 2024
Thank you!! @Paul

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by