
finding new frequencies of a signal with respect to another and plotting
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
xp1=sin(2*pi*(50/fs)*t);
xp2=sin(2*pi*(49.98/fs)*t)+sin(2*pi*(50.01/fs)*t)+sin(2*pi*(49.99/fs)*t)+sin(2*pi*(50.01/fs)*t);
how to plot new measured frequencies of xp2 with respect to xp1?
0 Kommentare
Antworten (1)
Mathieu NOE
am 11 Jan. 2023
hello
first a comment : not sure why your frequencies are all normalized by fs...i changed that in my code below
you need to perform a fft to see the frequencies of your signal
notice that you need a frequency resolution of 0.01 Hz to separate the components of xp2
the length of the signal is computed with that freq resolution of 0.01 Hz in mind
FFT plot

clc
clearvars
fs = 200; % sampling freq in Hz (so Nyquist freq = 100 Hz > your signal highest frequency)
dt = 1/fs; % seconds
df = 0.01; % freq resolution (Hz)
samples = ceil(fs/df); % make sure the signal is long enough to get the required freq resolution (fft freq points are separated by df = fs/nfft , here nfft = samples)
t=(0:samples-1)*dt;
xp1=sin(2*pi*(50)*t);
xp2=sin(2*pi*(49.98)*t)+sin(2*pi*(50.01)*t)+sin(2*pi*(49.99)*t)+sin(2*pi*(50.01)*t);
% FFT plot
[f1,fft_spectrum1] = do_fft(t,xp1);
[f2,fft_spectrum2] = do_fft(t,xp2);
figure(1)
plot(f1,fft_spectrum1,'*--',f2,fft_spectrum2,'*--')
title('FFT Spectrum')
ylabel('|X(f)|')
xlabel('Frequency[hz]')
legend('xp1','xp2');
xlim([49.9 50.1]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [freq_vector,fft_spectrum] = do_fft(time,data)
time = time(:);
data = data(:);
dt = mean(diff(time));
Fs = 1/dt;
nfft = length(data); % maximise freq resolution => nfft equals signal length
%% use windowing or not at your conveniance
% no window
fft_spectrum = abs(fft(data))*2/nfft;
% % hanning window
% window = hanning(nfft);
% window = window(:);
% fft_spectrum = abs(fft(data.*window))*4/nfft;
% one sidded fft spectrum % Select first half
if rem(nfft,2) % nfft odd
select = (1:(nfft+1)/2)';
else
select = (1:nfft/2+1)';
end
fft_spectrum = fft_spectrum(select,:);
freq_vector = (select - 1)*Fs/nfft;
end
1 Kommentar
Siehe auch
Kategorien
Mehr zu Audio Processing Algorithm Design finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!