Question

In: Computer Science

clear all close all % %*******Parameter Settings******** %********************************* Fs=8192; %Sampling frequency (MATLAB's default) Ts=1/Fs; %Sampling time...

clear all

close all

%

%*******Parameter Settings********

%*********************************

Fs=8192; %Sampling frequency (MATLAB's default)

Ts=1/Fs; %Sampling time or sampling period

Vx=1; %Chirp signal time duration in seconds

A=1; %Amplitude of chirp signal

a=2*pi*3000; %Angular chirp rate (natural chirp rate is 3000)

b=1000; %Initial natural frequency in Hertz

%

Nx=Vx*Fs; %Number of samples of the generated chirp signal

Nxseg=round(Nx/16); %Length of a segment(1/16) of the chirp signal

txaxis=0:Ts:Nx*Ts-Ts; %Time-sampled axis (vector of time values)

Psx=1; %Pointer (>0) to the beginning of the segment sample

txseg=(Psx-1)*Ts:Ts:(Psx+Nxseg-2)*Ts; %Time-sampled axis for signal segment

fxinc=Fs/Nx; %Spectral resolution of x(t)

fxaxis=-(Fs/2):fxinc:(Fs/2)-fxinc; %Frequency axis

fsxinc=Fs/Nxseg; %Segment spectral resolution

fsxaxis=-(Fs/2):fsxinc:(Fs/2)-fsxinc; %Seg. freq. axis

%

%********Signals Generation*******

%*********************************

x=A*cos((0.5*a)*(txaxis.*txaxis)+2*pi*b*txaxis);

xseg=x(Psx:Psx+Nxseg-1); %Segment (1/16) of chirp signal

%

%*******Filtering Operations*******

%*********************************

Nh=251; %Bandpass filter order

Nhm1=Nh-1; %Filter parameter for fir1

Wn=[2*2000/Fs 2*(3500/Fs)]; %Nomalized cutoff frequency vector

hB=fir1(Nhm1,Wn); %Impulse response funtion

y=conv(x,hB); %Filtering the chirp signal

%

Ny=length(y); %Order or length of filtered signal

Nyseg=round(Ny/16); %Length of filtered signal segment(1/16)

Psy=1; %Pointer (>0) to the first filtered signal segment sample

yseg=y(Psy:Psy+Nyseg-1); %Segment (1/16) of filtered signal

tyaxis=0:Ts:Ny*Ts-Ts; %Time axis of filtered signal

tyseg=(Psy-1)*Ts:Ts:(Psy+Nyseg-2)*Ts;%Time-sampled axis for segment

fyinc=Fs/Ny; %Spectral resolution of y(t)

fyaxis=-(Fs/2):fyinc:(Fs/2)-fyinc; %Frequency axis

fsyinc=Fs/Nyseg; %Segment spectral resolution

fsyaxis=-(Fs/2):fsyinc:(Fs/2)-fsyinc; %Seg. freq. axis

%

%********Spectra Generation*******

%*********************************

X=fft(x); %Spectrum of x

sX=fftshift(X); %Change to the principal region

asX=abs(sX); %Magnitude of spectrum of x(t)

Xseg=fft(xseg); %Spectrum of xseg

sXseg=fftshift(Xseg); %Change to the principal region

asXseg=abs(sXseg); %Magnitude of spectrum of xseg(t)

%

Y=fft(y); %Spectrum of y

sY=fftshift(Y); %Change to the principal region

asY=abs(sY); %Magnitude of spectrum of y(t)

Yseg=fft(yseg); %Spectrum of yseg

sYseg=fftshift(Yseg); %Change to the principal region

asYseg=abs(sYseg); %Magnitude of spectrum of yseg(t)

%**********Signals Plots**********

%*********************************

plot(txaxis,x) %Chirp time-sampled input signal

xlabel('Time in Seconds')

ylabel('Amplitude')

title('Time-Sampled Chirp Input Signal x(t)')

grid

%

figure

plot(txseg,xseg) %Chirp time-sampled signal segment

xlabel('Time in Seconds')

ylabel('Amplitude')

title('Time-Sampled Chirp Input Signal Segment xseg(t)')

grid

%

figure

plot(tyaxis,y) %Chirp time-sampled filtered output signal

xlabel('Time in Seconds')

ylabel('Amplitude')

title('Time-Sampled Filtered Chirp Output Signal y(t)')

grid

%

figure

plot(tyseg,yseg) %Chirp time-sampled signal segment

xlabel('Time in Seconds')

ylabel('Amplitude')

title('Time-Sampled Filtered Chirp Output Signal Segment yseg(t)')

grid

%

figure

plot(fxaxis,asX)

xlabel('Frequency in Hertz')

ylabel('Magnitude')

title('Spectrum of Time-Sampled Chirp Input Signal x(t)')

grid

%

figure

plot(fsxaxis,asXseg)

xlabel('Frequency in Hertz')

ylabel('Magnitude in dB')

title('Spectrum of Time-Sampled Chirp Input Signal Segment xseg(t)')

grid

%

figure

plot(fyaxis,asY)

xlabel('Frequency in Hertz')

ylabel('Magnitude')

title('Spectrum of Time-Sampled Filtered Chirp Output Signal y(t)')

grid

%

figure

plot(fsyaxis,asYseg)

xlabel('Frequency in Hertz')

ylabel('Magnitude in dB')

title('Spectrum of Filtered Chirp Output Signal Segment yseg(t)')

grid

%

%**********Signals Sounds*********

%*********************************

disp('Sound of Generated Input Chirp Signal')

sound(x,Fs)

pause(05)

disp('Sound of Filtered Output Chirp Signal')

sound(y,Fs)

%

1. From the code above change the filter from a band-pass filter to a band-stop. You should also change the name of the impulse response function of the filter from hB to hS.

I JUST NEED THE MATLAB CODE that shows the change of filter.

Solutions

Expert Solution

ANSWER:

  • For bandstop filter, we use fir1 function with ftype="stop".
  • I have provided the properly commented code in both text and image format so you can easily copy the code as well as check for correct indentation.
  • Have a nice and healthy day!!

CODE TEXT

clear all

close all

%

%*******Parameter Settings********

%*********************************

Fs=8192; %Sampling frequency (MATLAB's default)

Ts=1/Fs; %Sampling time or sampling period

Vx=1; %Chirp signal time duration in second

A=1; %Amplitude of chirp signal

a=2*pi*3000; %Angular chirp rate (natural chirp rate is 3000)

b=1000; %Initial natural frequency in Hertz

%

Nx=Vx*Fs; %Number of samples of the generated chirp signal

Nxseg=round(Nx/16); %Length of a segment(1/16) of the chirp signal

txaxis=0:Ts:Nx*Ts-Ts; %Time-sampled axis (vector of time values)

Psx=1; %Pointer (>0) to the beginning of the segment sample

txseg=(Psx-1)*Ts:Ts:(Psx+Nxseg-2)*Ts; %Time-sampled axis for signal segment

fxinc=Fs/Nx; %Spectral resolution of x(t)

fxaxis=-(Fs/2):fxinc:(Fs/2)-fxinc; %Frequency axis

fsxinc=Fs/Nxseg; %Segment spectral resolution

fsxaxis=-(Fs/2):fsxinc:(Fs/2)-fsxinc; %Seg. freq. axis

%

%********Signals Generation*******

%*********************************

x=A*cos((0.5*a)*(txaxis.*txaxis)+2*pi*b*txaxis);

xseg=x(Psx:Psx+Nxseg-1); %Segment (1/16) of chirp signal

%

%*******Filtering Operations*******

%*********************************

Nh=251; %Bandpass filter order

Nhm1=Nh-1; %Filter parameter for fir1

Wn=[2*2000/Fs 2*(3500/Fs)]; %Nomalized cutoff frequency vector

% using ftype -> 'stop' in fir1 function to generate Band-Stop Filter

hS=fir1(Nhm1,Wn,'stop'); %Impulse response funtion

y=conv(x,hS); %Filtering the chirp signal

%

Ny=length(y); %Order or length of filtered signal

Nyseg=round(Ny/16); %Length of filtered signal segment(1/16)

Psy=1; %Pointer (>0) to the first filtered signal segment sample

yseg=y(Psy:Psy+Nyseg-1); %Segment (1/16) of filtered signal

tyaxis=0:Ts:Ny*Ts-Ts; %Time axis of filtered signal

tyseg=(Psy-1)*Ts:Ts:(Psy+Nyseg-2)*Ts;%Time-sampled axis for segment

fyinc=Fs/Ny; %Spectral resolution of y(t)

fyaxis=-(Fs/2):fyinc:(Fs/2)-fyinc; %Frequency axis

fsyinc=Fs/Nyseg; %Segment spectral resolution

fsyaxis=-(Fs/2):fsyinc:(Fs/2)-fsyinc; %Seg. freq. axis

%

%********Spectra Generation*******

%*********************************

X=fft(x); %Spectrum of x

sX=fftshift(X); %Change to the principal region

asX=abs(sX); %Magnitude of spectrum of x(t)

Xseg=fft(xseg); %Spectrum of xseg

sXseg=fftshift(Xseg); %Change to the principal region

asXseg=abs(sXseg); %Magnitude of spectrum of xseg(t)

%

Y=fft(y); %Spectrum of y

sY=fftshift(Y); %Change to the principal region

asY=abs(sY); %Magnitude of spectrum of y(t)

Yseg=fft(yseg); %Spectrum of yseg

sYseg=fftshift(Yseg); %Change to the principal region

asYseg=abs(sYseg); %Magnitude of spectrum of yseg(t)

%**********Signals Plots**********

%*********************************

plot(txaxis,x) %Chirp time-sampled input signal

xlabel('Time in Seconds')

ylabel('Amplitude')

title('Time-Sampled Chirp Input Signal x(t)')

grid

%

figure

plot(txseg,xseg) %Chirp time-sampled signal segment

xlabel('Time in Seconds')

ylabel('Amplitude')

title('Time-Sampled Chirp Input Signal Segment xseg(t)')

grid

%

figure

plot(tyaxis,y) %Chirp time-sampled filtered output signal

xlabel('Time in Seconds')

ylabel('Amplitude')

title('Time-Sampled Filtered Chirp Output Signal y(t)')

grid

%

figure

plot(tyseg,yseg) %Chirp time-sampled signal segment

xlabel('Time in Seconds')

ylabel('Amplitude')

title('Time-Sampled Filtered Chirp Output Signal Segment yseg(t)')

grid

%

figure

plot(fxaxis,asX)

xlabel('Frequency in Hertz')

ylabel('Magnitude')

title('Spectrum of Time-Sampled Chirp Input Signal x(t)')

grid

%

figure

plot(fsxaxis,asXseg)

xlabel('Frequency in Hertz')

ylabel('Magnitude in dB')

title('Spectrum of Time-Sampled Chirp Input Signal Segment xseg(t)')

grid

%

figure

plot(fyaxis,asY)

xlabel('Frequency in Hertz')

ylabel('Magnitude')

title('Spectrum of Time-Sampled Filtered Chirp Output Signal y(t)')

grid

%

figure

plot(fsyaxis,asYseg)

xlabel('Frequency in Hertz')

ylabel('Magnitude in dB')

title('Spectrum of Filtered Chirp Output Signal Segment yseg(t)')

grid

%

%**********Signals Sounds*********

%*********************************

disp('Sound of Generated Input Chirp Signal')

sound(x,Fs)

pause(05)

disp('Sound of Filtered Output Chirp Signal')

sound(y,Fs)

%

CODE IMAGE (OF CHANGED PORTION)


Related Solutions

Run a Principal Axis Factor Analysis (PFA), with default settings for the “Eigenvalue greater than 1”...
Run a Principal Axis Factor Analysis (PFA), with default settings for the “Eigenvalue greater than 1” option. Just use the default rotation of ‘orthogonal’ for now. a.)Considering at least two rules-of-thumb discussed, what do the eigenvalues (you will need to “eyeball” these values from the plots) and scree plot suggest about the number of factors underlying the variables? Explain your answer (10 points) b.)Interpret and explain the communality variables (Hint: remember communality = 1 – uniqueness)? In what way do...
1. Clear statement of hypotheses, with the correct parameter(s) 2. An indication of the test used...
1. Clear statement of hypotheses, with the correct parameter(s) 2. An indication of the test used 3. The test statistic and p-value 4. An indication of the statistical decision (i.e. whether or not to reject Ho)      along with an explanation. 5. An interpretation of the statistical decision in the context of the problem. #1)   The annual salaries for a random sample of 16 actuaries working in New York have a standard deviation of $16,000.   The annual salaries of a...
Sensor Specification: 1- What's the parameter related to how close your sensor readings are from a...
Sensor Specification: 1- What's the parameter related to how close your sensor readings are from a reference method readings? 2- What's the parameter related to the dispersion of your sensor's multiple readings in a single simple?
1. Generate a sine wave with frequency 100 Hz. a. Sample the signal with a sampling...
1. Generate a sine wave with frequency 100 Hz. a. Sample the signal with a sampling frequency (i) 1000 Hz and (ii) 1050 Hz. b. For each frequency in Question 1(a), perform DFT for ONE (1) cycle and ONE and a HALF (1.5) cycles of the waveform. Comment on your observation.
using matlab Show the two formals or figures in time domin and z dominclc clear all...
using matlab Show the two formals or figures in time domin and z dominclc clear all b=[1,-4,5] a=[1,-6,11,-6] [R,P,C]=residuez(b,a) Ez=tf(b,a,1,'variable','z') zplane(b,a)
1. Bernard ran an experiment to test optimum power and time settings for microwave popcorn. His...
1. Bernard ran an experiment to test optimum power and time settings for microwave popcorn. His goal was to deliver popcorn with fewer than 11​% of the kernels left​ unpopped, on average. He determined that power 9 at 4 minutes was the best combination. To be sure that the method was​ successful, he popped 8 more bags of popcorn​ (selected at​ random) at this setting. All were of high​quality, with the percentages of unpopped kernels shown below. 3.3, 7.5, 11.3,...
Space Probe #1 passes very close to Earth at a time that both we (on Earth)...
Space Probe #1 passes very close to Earth at a time that both we (on Earth) and the onboard computer on Probe 1 decide to call t = 0 in our respective frames. The probe moves at a constant speed of 0.5c away from Earth. When the clock aboard Probe 1 reads t = 60 sec, it sends a light signal straight back to Earth. a) At what time was the signal sent, according to the earth’s rest frame? b)...
1. The Federal Deposit Insurance Corporation insures all deposits against default. True or False
1. The Federal Deposit Insurance Corporation insures all deposits against default. True or False
(1) default constructor which initalizes all the coefficients to 0 (2) a constructor that takes three...
(1) default constructor which initalizes all the coefficients to 0 (2) a constructor that takes three parameters public QuadraticExpression(double a, double b, double c) (3) a toString() method that returns the expression as a string. (4) evaluate method that returns the value of the expression at x public double evaluate(double x) (5) set method of a, b, c public void setA(double newA) public void setB(double newB) public void setC(double newC) (6) public static QuadraticExpression scale( double r, QuadraticExpression q) returns...
1. The sampling distribution of the sample mean is approximately normal for all sample sizes. a....
1. The sampling distribution of the sample mean is approximately normal for all sample sizes. a. true b. false 2. If all possible samples of the same size have the same chance of being selected, these samples are said to be random samples. a. true b. false 3. The population of sample means of every possible sample size (n) is known as the ______ distribution of the mean. 4. A sample size of 49 drawn from a population with a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT