Generate pure tone sequence in frequence domain

13 vues (au cours des 30 derniers jours)
D2snc
D2snc le 24 Oct 2021
Commenté : D2snc le 26 Oct 2021
Hi, i'm trying to generate a sequence of pure tones in the frequency domain and later on, convert to the time domain and execute the sound. The frequencies are 1000 Hz, 2000 Hz, 3000 Hz, 4000 Hz and 5000 Hz. I already managed to do this using only time domain, but i am having a very hard time to do this in the frequency domain. Can someone help me ?
  1 commentaire
Bjorn Gustavsson
Bjorn Gustavsson le 25 Oct 2021
Why not do it in the time-domain and Fourier-transform it.

Connectez-vous pour commenter.

Réponse acceptée

Scott MacKenzie
Scott MacKenzie le 25 Oct 2021
Modifié(e) : Scott MacKenzie le 25 Oct 2021
Seems you want to start by specifying your signals in the frequency domain, then convert to the time domain. I think this does the trick:
% system spec's (adjust as needed)
sRate = 16584; % sampling rate
sPeriod = 1 / sRate;
n1 = sRate/2; % number of samples in one-sided freq spectrum
% create spectrum in frequency domain
fOneSide = (1:n1)';
specOneSide = zeros(n1,1);
% add sinusoids with varying amplitudes
specOneSide(1000) = 1.0;
specOneSide(2000) = 0.5;
specOneSide(3000) = 0.4;
specOneSide(4000) = 0.6;
specOneSide(5000) = 0.3;
% plot the frequency spectrum
figure;
set(gcf, 'color', 'w', 'units', 'normalized', 'Position', [.2 .4 .6 .4]);
tiledlayout(1,3);
nexttile;
plot(fOneSide,specOneSide);
title('One-sided Frequency Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude Spectrum');
% create the two-sided frequency spectrum
specTwoSide = [flip(specOneSide(1:end)); specOneSide(2:end-1)];
n2 = length(specTwoSide);
f = (-sRate/2:sRate/n2:sRate/2-sRate/n2)';
% plot it
nexttile;
plot(f, specTwoSide);
title('Two-sided Frequency Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude Spectrum');
% ifft the two-sided frequency spectrum to get signals in the time domain
y = ifft(fftshift(specTwoSide));
t = (0:n2-1) / sRate;
% plot it
nexttile;
plot(y(1:100)); % part of the signal only (better visual)
title('Time Domain Signal');
xlabel('Time');
ylabel('Amplitude');
% play it
soundsc(y, sRate);
  6 commentaires
Scott MacKenzie
Scott MacKenzie le 26 Oct 2021
Yes, and as an example, if you add
n1 = 10*n1;
after the initialization of n1, you are increasing the size of the spectrum by a factor or 10. So, with this, each frequency is specified x10. To get 326.6 Hz, use
specOneSide(3266) = 1.0; % frequency = 326.6 Hz, amplitude = 1
D2snc
D2snc le 26 Oct 2021
thanks for the help, i understand very well, grateful !

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by