MATLAB Answers

0

need help with this

turn all the amplitudes of frequencies which are higher than 3500 Hz into 0’s and amplify the rest of the spectrum (by just multiplying the spectrum by some large number so that the amplitudes are around 2000-3000 in magnitude
how do i do this ? like what would the code be like?

  0 Comments

Sign in to comment.

1 Answer

 Accepted Answer

a = [10;15;3600;4500;45;67;100];
[ind,~] = find(a>=3500);
b = a;
b(ind) = 0;
c = b*30

  16 Comments

Walter Roberson
on 16 Apr 2019
Mohamed, you are correct that it would be best if the multiplier was determined from the signal. However, the instructions were,
"by just multiplying the spectrum by some large number so that the amplitudes are around 2000-3000 in magnitude"
so apparently the assignment expects the user to put in an arbitrary constant similar to your suggested 30, or what I seem to have slipped using as 3000, as long as the amplitudes come out in the right range. dulanga should apparently be plotting abs( c) to check the magnitudes and adjust the multiplier (the 30 or 3000) to give an acceptable range.
dulanga on 16 Apr 2019
walter is freqs like nqysuist or smthing ?
and i am confused with mirroring
the L is even so its is f(2:end-1) used but how
and you find in Freqs what is greater than 3500 but what happens to f where the fft is used ?
this was the guide given
Capture.JPG
Walter Roberson
on 16 Apr 2019
discrete fourier transform theory says that you can take a function, f(x), and represent it as a sum of coefficients, each associated with a frequency -- essentially a sum of sine waves. The first slot of fft output is associated with "0 Hz", the DC constant. The second slot of fft output is for one cycle over the signal; the third slot is for two cycles over the signal; the third slot is for three cycles over the signal, and so on until you get to the middle slot, which for signal length L is associated with L/2 cycles per signal. The fact that you do not go on from there to (L/2+1), (L/2+2) and so on does have to do with Nyquist: Nyquist tells you that you cannot resolve anything more than L/2 cycles in a signal length L.
Once you get to the middle, then you start counting down again, possibly a repeat of L/2 (but not necessarily), and then L/2-1, L/2-2 and so on down to 1 (but not down to 0). When the input signal was entirely real-valued, then the coefficient in fft output array location K is the complex conjugate of the coefficient in location end-K+2. In the case of an input signal known to be entirely real-valued, you can reconstruct the entire signal from the first half of the fft() output, but it is easier to use the setup the way it is, as the current setup extends naturally to complex signals.
Now, when I say "one cycle over the signal, two cycles over the signal", and so on, I know that sounds like "Hz". But Hz is "cycles per second", and the signal is not necessarily one second long. If the signal were 2 seconds long, then "one cycle over the signal" would be 1 cycle in 2 seconds, which would be 1/2 Hz, for example. Two cycles over the signal would be 2 cycles in 2 seconds, 1 Hz. Three cycles over the signal would be 3 cycles in 2 seconds, 3/2 Hz. And so on. Notice that the adjacent slots are a constant frequency apart from each other. To know how many Hz each slot in the fft output represent, you need to do a small calculation. The calculation can be done if you know the total time that the signal represents, but it can also be done without that total time (directly) if you know the sampling frequency of the original signal, fs, which you get as the second output of audioread(). If you have more than one second of input, then the slots will correspond to frequencies less than fs apart; if you have less than one second of input, then the slots will correspond to frequencies more than fs apart.
For your task, you need to convert the bin numbers (cycles per signal) into absolute frequencies, because you are asked to filter based upon absolute frequencies. The Freqs calculation I posted earlier calculates the first half of that array, but does not continue on to count backwards down to lower frequencies again.
For mirroring: suppose you had an input vector x1 = [0 -1 2 -3 4] . Now, what expression would you write to get out [0 -1 2 -3 4 4 -3 2 -1] (case where original signal was odd length) ? What expression would you write to get out [0 -1 2 -3 4 -3 2 -1] (case where original signal was even length) ?

Sign in to comment.