generate white noise signal with certain bandwidth?

17 views (last 30 days)
ANAS HAMZAH
ANAS HAMZAH on 17 Nov 2024 at 11:35
Commented: Star Strider on 17 Nov 2024 at 13:22
i am trying to generate noise with 5uvrms and the frequncy bandwidth 100hz . then i want to add two noise block to calculate the total rms.
can any one help to generate this ?

Answers (1)

Star Strider
Star Strider on 17 Nov 2024 at 11:56
The filtered signal iis no longer a white-noise signal, although the original signal is.
Try this —
Fs = 1000; % Sampling Frequency (Hz)
t = linspace(0, 1E4-1, 1E4).'/Fs; % Time Vector
ns = randn(1E+4, 1); % Noise Signal
nsf = lowpass(ns, 100, Fs, ImpulseResponse='iir'); % Filter Noise Signal
[FTns,Fv] = FFT1(ns,t); % Fourier Transform Of Original Noise Signal
[FTnsf,Fv] = FFT1(nsf,t); % Fourier Transform Of Filtered Noise Signal
figure
tiledlayout(2,1)
nexttile
plot(Fv, abs(FTns)*2)
grid
title('Original')
nexttile
plot(Fv, abs(FTnsf)*2)
grid
title('Filtered')
function [FTs1,Fv] = FFT1(s,t)
% Arguments:
% s: Signal Vector Or Matrix
% t: Associated Time Vector
t = t(:);
L = numel(t);
if size(s,2) == L
s = s.';
end
Fs = 1/mean(diff(t));
Fn = Fs/2;
NFFT = 2^nextpow2(L);
FTs = fft((s - mean(s)) .* hann(L).*ones(1,size(s,2)), NFFT)/sum(hann(L));
Fv = Fs*(0:(NFFT/2))/NFFT;
% Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
Fv = Fv(:);
FTs1 = FTs(Iv,:);
end
.
  3 Comments
Star Strider
Star Strider on 17 Nov 2024 at 13:22
You can also use —
Fs = 1000; % Sampling Frequency (Hz)
Fn = Fs/2;
Wp = 100/Fn; % Stopband Frequency (Normalised)
Ws = 101/Fn; % Passband Frequency (Normalised)
Rp = 1; % Passband Ripple
Rs = 60; % Passband Ripple (Attenuation)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Elliptic Order Calculation
[z,p,k] = ellip(n,Rp,Rs,Wp); % Elliptic Filter Design: Zero-Pole-Gain
[sos,g] = zp2sos(z,p,k);
t = linspace(0, 1E4-1, 1E4).'/Fs; % Time Vector
ns = randn(1E+4, 1); % Noise Signal
nsf = filtfilt(sos, g, ns); % Filter Noise Signal
[FTns,Fv] = FFT1(ns,t); % Fourier Transform Of Original Noise Signal
[FTnsf,Fv] = FFT1(nsf,t); % Fourier Transform Of Filtered Noise Signal
figure
tiledlayout(2,1)
nexttile
plot(Fv, abs(FTns)*2)
grid
title('Original')
nexttile
plot(Fv, abs(FTnsf)*2)
grid
title('Filtered')
function [FTs1,Fv] = FFT1(s,t)
% Arguments:
% s: Signal Vector Or Matrix
% t: Associated Time Vector
t = t(:);
L = numel(t);
if size(s,2) == L
s = s.';
end
Fs = 1/mean(diff(t));
Fn = Fs/2;
NFFT = 2^nextpow2(L);
FTs = fft((s - mean(s)) .* hann(L).*ones(1,size(s,2)), NFFT)/sum(hann(L));
Fv = Fs*(0:(NFFT/2))/NFFT;
% Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
Fv = Fv(:);
FTs1 = FTs(Iv,:);
end
Unless you also have the DSP System Toolbox, you may need to use the transfer function implementation (b,a vectors) for this filter, instead of the second-order-section implemntation I use here. It is relatively straightforward to change my code to create that. See the documentation on ellip for that information.
Use the Signal Processing Toolbox filt2block function to create the block.
.

Sign in to comment.

Tags

Products


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!