Generate pure tone sequence in frequence domain

조회 수: 10 (최근 30일)
D2snc
D2snc 2021년 10월 24일
댓글: D2snc 2021년 10월 26일
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
Bjorn Gustavsson
Bjorn Gustavsson 2021년 10월 25일
Why not do it in the time-domain and Fourier-transform it.

댓글을 달려면 로그인하십시오.

채택된 답변

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