User Tools

Site Tools


matlab

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

matlab [2023/01/14 21:23]
scott MATLAB
matlab [2023/01/18 16:12] (current)
scott Figure scale
Line 61: Line 61:
  
 The resulting plot should look like the following. The resulting plot should look like the following.
-{{ :​example1.jpg?​100 |}}+{{ :​example1.jpg?​600 |}}
  
  
Line 132: Line 132:
  
 You should get a plot that looks like  You should get a plot that looks like 
-{{ :​matlab_help_fig1.jpg?​100 |}}+{{ :​matlab_help_fig1.jpg?​600 |}}
  
 If we create a low pass filter with a cutoff frequency of //​fcut=1.5kHz//​ then the signal should pass through the filter. Let’s make some mistakes and see what happens and see if we can figure out what we did wrong. We are doing this to learn about debugging.  ​ If we create a low pass filter with a cutoff frequency of //​fcut=1.5kHz//​ then the signal should pass through the filter. Let’s make some mistakes and see what happens and see if we can figure out what we did wrong. We are doing this to learn about debugging.  ​
Line 162: Line 162:
 </​code>​ </​code>​
 The resulting plot should look something like. The resulting plot should look something like.
-{{ :​matlab_help_fig2.jpg?​100 |}}+{{ :​matlab_help_fig2.jpg?​600 |}}
  
 The signal y has a lower amplitude. This mean that it is being filtered. We must have made an error in the cutoff frequency. If we make the following change The signal y has a lower amplitude. This mean that it is being filtered. We must have made an error in the cutoff frequency. If we make the following change
Line 169: Line 169:
 </​code>​ </​code>​
 The following plot shows that it is now worse because we were supposed to divide by Fs/2 not 2*Fs. The following plot shows that it is now worse because we were supposed to divide by Fs/2 not 2*Fs.
-{{ :​matlab_help_fig3.jpg?​100 |}}+{{ :​matlab_help_fig3.jpg?​600 |}}
  
 The correct value is The correct value is
Line 177: Line 177:
  
 Resulting in the correct plot. Resulting in the correct plot.
-{{ :​matlab_help_fig4.jpg?​100 |}}+{{ :​matlab_help_fig4.jpg?​600 |}}
  
 To finish up let’s make sure that we can use the butter command to perform a bandpass filter. Create a signal that is x=sin(2*pi*1e3*t) + sin(2*pi*2e3*t) + sin(2*pi*3e3*t) and has the same sampling frequency of Fs=10kHz. Use a bandpass filter to pass the f=2kHz signal through and attenuate the other two. The resulting plots should look like the following. To finish up let’s make sure that we can use the butter command to perform a bandpass filter. Create a signal that is x=sin(2*pi*1e3*t) + sin(2*pi*2e3*t) + sin(2*pi*3e3*t) and has the same sampling frequency of Fs=10kHz. Use a bandpass filter to pass the f=2kHz signal through and attenuate the other two. The resulting plots should look like the following.
  
-{{ :​matlab_help_fig5.jpg?​100 |}}+{{ :​matlab_help_fig5.jpg?​600 |}}
  
 ===== Using the fft command ===== ===== Using the fft command =====
Line 206: Line 206:
 Here is the plot of our signal. Here is the plot of our signal.
  
-{{ :​fft_example1.jpg?​200 |}}+{{ :​fft_example1.jpg?​600 |}}
  
 Now you need to create the Fourier transform of the signal using the FFT command. ​ Now you need to create the Fourier transform of the signal using the FFT command. ​
Line 215: Line 215:
 Notice that we plotted the absolute value of Y since it is complex. Notice that we plotted the absolute value of Y since it is complex.
  
-{{ :​fft_example2.jpg?​200 |}}+{{ :​fft_example2.jpg?​600 |}}
  
 Notice that there are two spikes and that the amplitude is not equal to our amplitude of 1. Notice that there are two spikes and that the amplitude is not equal to our amplitude of 1.
Line 227: Line 227:
 </​code>​ </​code>​
 The linspace command creates a vector with equally spaced elements between a starting and an ending value and with a specified number of elements. Here is the resulting plot. The linspace command creates a vector with equally spaced elements between a starting and an ending value and with a specified number of elements. Here is the resulting plot.
-{{ :​fft_example3.jpg?​200 |}}+{{ :​fft_example3.jpg?​600 |}}
 You can zoom in on the spike and verify that it has a frequency close to 3kHz.  ​ You can zoom in on the spike and verify that it has a frequency close to 3kHz.  ​
  
Line 236: Line 236:
 </​code>​ </​code>​
 Here is the resulting plot. Here is the resulting plot.
-{{ :​fft_example4.jpg?​200 |}}+{{ :​fft_example4.jpg?​600 |}}
  
 Zoom in on the spike to make sure that it is centered close to 3kHz.  ​ Zoom in on the spike to make sure that it is centered close to 3kHz.  ​
Line 262: Line 262:
 </​code>​ </​code>​
 Here are the resulting time domain and frequency domain plots. Here are the resulting time domain and frequency domain plots.
-{{ :​fft_example5.jpg?​200 |}}+{{ :​fft_example5.jpg?​600 |}}
  
 This MATLAB code produces a sine wave with 100 periods and a corresponding frequency resolution of 29.9 Hz. This MATLAB code produces a sine wave with 100 periods and a corresponding frequency resolution of 29.9 Hz.
Line 282: Line 282:
 </​code>​ </​code>​
 Here are the resulting plots. Here are the resulting plots.
-{{ :​fft_example6.jpg?​200 |}}+{{ :​fft_example6.jpg?​600 |}}
  
  
Line 332: Line 332:
  
 Here is the resulting plot. Here is the resulting plot.
-{{ :​freqz_1.jpg?​200 |}}+{{ :​freqz_1.jpg?​600 |}}
  
 Notice how the filter is flat over the band between the two frequencies and then slopes down outside of this band. This is the shape of the frequency response of a bandpass filter. Notice how the filter is flat over the band between the two frequencies and then slopes down outside of this band. This is the shape of the frequency response of a bandpass filter.
Line 344: Line 344:
 Here is the plot in decibel scale. You can zoom in on the 1kHz and 2kHz frequencies and see that these are the 3dB points. Here is the plot in decibel scale. You can zoom in on the 1kHz and 2kHz frequencies and see that these are the 3dB points.
  
-{{ :​freqz_3.jpg?​200 |}}+{{ :​freqz_3.jpg?​600 |}}
  
 You can change the order of the filter and see that the filter becomes steeper and change the frequency corners and see the change in the width of the filter. You can change the order of the filter and see that the filter becomes steeper and change the frequency corners and see the change in the width of the filter.
  
  
matlab.1673756592.txt.gz · Last modified: 2023/01/14 21:23 (external edit)