%<--- LOAD SIGNAL (FILENAME:mydata.mat) %data = ('mydata.mat') Fs=100; t= 0: 1/Fs: 20; S = load('mydata.mat'); signal = S.td; x= signal SNR = 0; % Generate Gaussian Noise with zero mean and unit variance %function [y] = add_noise (signal, SNR) x_var=var (x); x_lng=length(x)
w = Fc/(2*Fs); % Normalized frequency %design a low pass fitler with above mentioned specifications [b,a]=butter(2,w,'low'); %5th order butterworth LPF [h,w]=freqz(b,a,1024); %Frequency response of the filter
y=filter(b,a,mix); % pass the input signal through the filter % y is your output.
%Plot the Frequency response of the filter (Optional) %subplot(5,1,5); figure(4); g = length(w/pi*2*Fs) i = length(abs(h)) plotHandle=plot(w/pi*2*Fs,abs(h)); set(plotHandle,'LineWidth',2.5); title('Frequency Response of a 5th Order Butterworth LPF'); xlabel('Frequency (Hz)') ylabel('Magnitude'); grid;
figure(6); %subplot(4,1,2); v = noise; NFFT = 100; V = fft(v, NFFT); plot(-NFFT/2:NFFT/2 - 1, fftshift(abs(V))) title('PSD Generated Noise');
%subplot(4,1,3); figure(7); w = mix; NFFT = 100; W = fft(w, NFFT); plot(-NFFT/2:NFFT/2 - 1, fftshift(abs(W))) title(['PSD Signal + Noise for SNR= 30 dB']);
%subplot(4,1,4); figure(8); m = y; NFFT = 100; M = fft(m, NFFT); plot(-NFFT/2:NFFT/2 - 1, fftshift(abs(M))) title('PSD Filtered Signal');
anyone <ieGJnr4aQXRb!uzEL@z³> wrote in message <email@example.com>... > On Tue, 01 Jan 2013 20:41:08 +0000, Wan wrote: > > > Hi, > > > > I have a problem to run a script for SNR. Here the details. > > > > By using the given signal, the signal should be embended with noise with > > with different Signal-to-noise ration (SNR) of 0dB, 5dB, 10dB, 15dB, > > 20dB, 25 dB and 30 dB. Details of the programming should include: > > 1. How SNR of the noisy signal is calculated 2. Comparison of time > > domain and Power Spectrum Density (PSD) of original signal, noisy signal > > and filtered signal for each SNR. > > > > Anyone know how to write script for this SNR using given signal? > > Yes, I can think of a few ways one could do that. First, you should get > started on your homework, then come back with an update on what you tried > to do and what actually happened.