Add 2 sec. of noise as a reference for a spectrogram infront of a 2 second long sinus function.
조회 수: 5 (최근 30일)
이전 댓글 표시
Hey,
I want to test some spectrogram technics, so my plan was to use the standard C major scale as an example for.
So, I generate a sine function with the frequencies for the tones of the scale.
My question is how can i add a for example randome noise, or white noise or something as a reference nois for the sine wave infront of it. In the end i want to have a 4 sec. long signal, the first 2 sec. should be just reference noise folllowed by 2 secs. of sine wave.
Thats how i code the sine function:
clear all
clc
fs = 44200; % Sampling frequency (samples per second)
dt = 1/fs; % seconds per sample
StopTime = 2; % seconds
t = (0:dt:StopTime-dt)'; % seconds
F = 432; % Sine wave frequency (hertz)
data = sin(2*pi*F*t);
Thank you very much.
댓글 수: 0
답변 (1개)
Star Strider
2022년 9월 14일
Try this —
fs = 44200; % Sampling frequency (samples per second)
dt = 1/fs; % seconds per sample
StopTime = 2; % seconds
noisev = randn(2*fs,1)*0.35; % Length = Samples/sec * sec (Column Vector)
t = (0:dt:StopTime-dt)'; % seconds
F = 432; % Sine wave frequency (hertz)
data = sin(2*pi*F*t);
data = [noisev; data]; % Concatenate
L = numel(data);
t_new = linspace(0, L-1, L)/fs; % Seconds
figure
plot(t_new, data)
grid
xlabel('Time (s)')
ylabel('Amplitude')
It might be appropriate to further scale the ‘noisev’ vector to avoid clipping and saturation.
.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
