Generate pure tone sequence in frequence domain

6 次查看(过去 30 天)
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 ?

采纳的回答

Scott MacKenzie
Scott MacKenzie 2021-10-25
编辑:Scott MacKenzie 2021-10-25
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 个评论
Scott MacKenzie
Scott MacKenzie 2021-10-26
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 2021-10-26
thanks for the help, i understand very well, grateful !

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by