Question

In: Electrical Engineering

Write Matlab code (with detailed comments) to perform spectral analysis of 1KHz sine wave, noise and...

  1. Write Matlab code (with detailed comments) to perform spectral analysis of 1KHz sine wave, noise and noise corrupted sine wave. Consider the sampling frequency Fs=10KHz.                                                                                                                                                  
  2. What should be the ideal frequency response of filter required to remove noise? Justify your answer                                                                                                                           

Solutions

Expert Solution

(a) MATLAB code is given below:

fsin = 1000;%% sine wave frequency
fs = 10000;%% sampling frequency
fbin = fsin/100;%% bin frequency of FFT
npoints = fs/fbin*15;% Total length of sequence
nfft = fs/fbin;% No of points of FFT
A = 1;% amplitude of sinewave
vsin = A*sin(2*pi*fsin/fs*(0:1:npoints-1));% sine wave defined
noise = wgn(1,length(vsin),-40);% noise witj -40dB power defined
nfft_total = 10*nfft;% total length of sequence used for calculating PSD
vsin_final = vsin(end-nfft_total+1:end);
noise_final = noise(end-nfft_total+1:end);
noise_plus_sine = noise+vsin;% noise + signal
noise_plus_sine_final = noise_plus_sine(end-nfft_total+1:end);

%%% Generating 10 different FFT's by dividing sequence into ten segments
%%% and then taking FFT of each segment
fft_vsin(nfft_total/nfft,nfft) = 0;
fft_noise(nfft_total/nfft,nfft) = 0;
fft_noise_plus_sine(nfft_total/nfft,nfft) = 0;
for i = 1:nfft_total/nfft
fft_vsin(i,:) = fft(vsin_final((i-1)*nfft+1:i*nfft));
fft_noise(i,:) = fft(noise_final((i-1)*nfft+1:i*nfft));
fft_noise_plus_sine(i,:) = fft(noise_plus_sine_final((i-1)*nfft+1:i*nfft));
end
freq = fs/nfft*(0:1:nfft-1);

%%%%
psd_vsin_avg(1,nfft) = 0;
psd_noise_avg(1,nfft) = 0;
psd_noise_plus_sine_avg(1,nfft) = 0;
for i = 1:nfft_total/nfft
psd_vsin_avg = psd_vsin_avg + abs(fft_vsin(i,:)).^(2);
psd_noise_avg = psd_noise_avg + abs(fft_noise(i,:)).^(2);
psd_noise_plus_sine_avg = psd_noise_plus_sine_avg + abs(fft_noise_plus_sine(i,:)).^(2);
end
psd_vsin_avg = psd_vsin_avg(1:nfft/2)/(2000*2000);% scaling factor to normalize PSD
psd_noise_avg = psd_noise_avg(1:nfft/2)/(2000*2000);% scaling factor to normalize PSD
psd_noise_plus_sine_avg = psd_noise_plus_sine_avg(1:nfft/2)/(2000*2000);% scaling factor to normalize PSD
frequency = freq(1:nfft/2);

PSD of signal, PSD of noise and PSD of signal + noise is plotted below:

(b) From plot, we can see that signal is single sinusoid but noise spread over whole frequency range. So ideal filter to filter out noise will be a bandpass filter centered at 1kHz and infinite Q such that its bandwidth = 0.


Related Solutions

write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio...
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds), takes Fourier transform of the signal (probably FFT).
Use the sine wave and scope in the Simulink library (MATLAB) to generate and observe the...
Use the sine wave and scope in the Simulink library (MATLAB) to generate and observe the following waves: a. ?1 (?) = sin ?? b. ?2 (?) = cos ?? c. ?2 (?) = 0.5 cos ?? d. ?3 (?) = cos (?? − ?) ? = 1 ???/s
In a single Matlab script, plot a sine wave and cosine wave over 2 periods (0...
In a single Matlab script, plot a sine wave and cosine wave over 2 periods (0 to 4π). Checkpoints of the requirements: Generate your independent variables first; the step size should be no larger than 0.1 so that it has enough samples to get smooth lines. Plot the two waves on the same graph.   Specify the line color and styles: red dashed line for sine & blue solid line with dot markers for cosine. Include axis labels and a descriptive...
The function Sine is defined as: where x is an angle in radians Write a Matlab...
The function Sine is defined as: where x is an angle in radians Write a Matlab script program to compute the sinus value of any angle as the following: - The program should run always until the user enters - 1 to exit from the program. - A sk user to enter: Number of elements (N) that should be included in the sum - C heck that N is a positive integer . [ Hint: use ( round (N) -...
Design a matlab code that: 1-play sound 2- add noise to the sound 3- filter the...
Design a matlab code that: 1-play sound 2- add noise to the sound 3- filter the noised signal using fir or iir filter Note: FIR: Finite impulse response filter IIR: Infinite impulse response filter
Complete the code below by finishing up the tasks detailed in the comments. ArrayList<String> fruits =...
Complete the code below by finishing up the tasks detailed in the comments. ArrayList<String> fruits = new ArrayList<>(); Scanner sc = new Scanner(System.in); String fruit = "?"; while (!fruit.isEmpty()) { // prompt the user to enter a fruit // read the fruit using "sc", saving it into variable "fruit" // convert the fruit entered to lowercase // if the fruit is NOT empty and it is a new fruit, add it to ArrayList "fruits" } // display all fruits
write code with proper comments for ever step the code should be in form of pseudocode                            &
write code with proper comments for ever step the code should be in form of pseudocode                                    To Print Triangle of any size, by taking size as input. To Print Triangle of any size, by taking size as input. If size is 4 then triangle is: To calculate Factorial of any number. To calculate the power of any given number. To Print Table of Any Number up till 10: as shown in this figure. for a program which reads 10 integers...
MATLAB Question Write a script to plot the function 'x times sine-squared of x' over a...
MATLAB Question Write a script to plot the function 'x times sine-squared of x' over a user-specified interval. It should prompt the user to enter the starting and stopping values of x, perform the calculation, and plot the result. Test the script using start/stop values 28 and 42.
write a matlab code to simulate fiber optics communication system on matlab simulink
write a matlab code to simulate fiber optics communication system on matlab simulink
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT