Add 2 sec. of noise as a reference for a spectrogram infront of a 2 second long sinus function.
2 次查看(过去 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 中查找有关 Spectral Measurements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!