Generate pure tone sequence in frequence domain
12 ビュー (過去 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 ?
1 件のコメント
採用された回答
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
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spectral Measurements についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!