Add 2 sec. of noise as a reference for a spectrogram infront of a 2 second long sinus function.
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Star Strider
on 14 Sep 2022
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 Comments
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!