Prev: spectrogram
Next: mixed model anova
From: Martin on 10 May 2010 04:55 Hi Wayne, yes, I am plotting the spectrogram by calling the function with no output arguments. I also tried it with output arguments but then I get only the values and not the diagram (spectrogram), don't I? The explanation with the dB makes sence, it was also one of my ideas. I tried to specify the frequency range as you recommended. I am interested only in the range up to 60 Hz so the following syntax: spectrogram(dc_current,2e4,18e3,2:0.01:60,4e4,'yaxis') I have now the range of frequencies 2...60 Hz with a step of 0.01 Hz. But the spectrogram has the resolution of about 2 Hz. What is the reason? I have to do something wrong... I need the frequencies for resonance investigation and such a resolution doesn't tell me anything... Do you have any idea? It would help me a lot. "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs79s3$ng9$1(a)fred.mathworks.com>... > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs4ias$7a$1(a)fred.mathworks.com>... > > > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs4hih$bn6$1(a)fred.mathworks.com>... > > > > Hi everyone > > > > > > > > I need a help with 'spectrogram' function. It makes FFT of my signal and plots it with time and frequency on the axis and the magnitude of frequency showed with color. > > > > The frequency range of FFT algorithm depends on the sampling frequency. > > > > In my case the sampling frequency is very high (160 kHz), but as the result I focus just on the range 0-60 Hz. Can I modify spectrogram to compute the fft only up to 60 Hz? > > > > I can change the range in Axes properties but in this way I loose the information of magnitude (displayed with color) because I just cut a very small piece from wide frequency range > > > > > > > > Thank you for your help and tips. > > > > > > > > Martin Bruha > > > > > > Hi Martin, you can use the syntax > > > > > > [S,F,T]=spectrogram(x,window,noverlap,F,fs) > > > > > > See the documentation. You can specify a vector of frequencies,F, at which to compute the short-time Fourier transform. > > > > > > Also, you can always manipulate the colormap, or use caxis() so that you color your plot the way you wish. > > > > > > Hope that helps, > > > Wayne > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs6ui8$1em$1(a)fred.mathworks.com>... > > Hi Waine > > thanks for the tips, I will check it now. Maybe one more question: I get the diagram using spectrogram function and then in the options I choose to add a colorbar. I wonder why about 60% of the range in colorbar is negative (like -100...+60). The color represents the magnitude of certain frequency component at certain time. How can it be negative? Or is there something wrong in my point of view? > > Thanks again, > > Martin > > > Hi Martin, Are you plotting the spectrogram by calling the function with no output arguments? If so, you are seeing that the magnitudes are plotted in dB, in which case magnitudes less than 1 result in negative values. > > Wayne
From: Wayne King on 10 May 2010 05:55 "Martin " <martin.bruha(a)gmail.com> wrote in message <hs8hlb$ca0$1(a)fred.mathworks.com>... > Hi Wayne, > > yes, I am plotting the spectrogram by calling the function with no output arguments. I also tried it with output arguments but then I get only the values and not the diagram (spectrogram), don't I? > The explanation with the dB makes sence, it was also one of my ideas. > I tried to specify the frequency range as you recommended. > I am interested only in the range up to 60 Hz so the following syntax: > > spectrogram(dc_current,2e4,18e3,2:0.01:60,4e4,'yaxis') > > I have now the range of frequencies 2...60 Hz with a step of 0.01 Hz. But the spectrogram has the resolution of about 2 Hz. What is the reason? I have to do something wrong... I need the frequencies for resonance investigation and such a resolution doesn't tell me anything... > Do you have any idea? It would help me a lot. > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs79s3$ng9$1(a)fred.mathworks.com>... > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs4ias$7a$1(a)fred.mathworks.com>... > > > > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs4hih$bn6$1(a)fred.mathworks.com>... > > > > > Hi everyone > > > > > > > > > > I need a help with 'spectrogram' function. It makes FFT of my signal and plots it with time and frequency on the axis and the magnitude of frequency showed with color. > > > > > The frequency range of FFT algorithm depends on the sampling frequency. > > > > > In my case the sampling frequency is very high (160 kHz), but as the result I focus just on the range 0-60 Hz. Can I modify spectrogram to compute the fft only up to 60 Hz? > > > > > I can change the range in Axes properties but in this way I loose the information of magnitude (displayed with color) because I just cut a very small piece from wide frequency range > > > > > > > > > > Thank you for your help and tips. > > > > > > > > > > Martin Bruha > > > > > > > > Hi Martin, you can use the syntax > > > > > > > > [S,F,T]=spectrogram(x,window,noverlap,F,fs) > > > > > > > > See the documentation. You can specify a vector of frequencies,F, at which to compute the short-time Fourier transform. > > > > > > > > Also, you can always manipulate the colormap, or use caxis() so that you color your plot the way you wish. > > > > > > > > Hope that helps, > > > > Wayne > > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs6ui8$1em$1(a)fred.mathworks.com>... > > > Hi Waine > > > thanks for the tips, I will check it now. Maybe one more question: I get the diagram using spectrogram function and then in the options I choose to add a colorbar. I wonder why about 60% of the range in colorbar is negative (like -100...+60). The color represents the magnitude of certain frequency component at certain time. How can it be negative? Or is there something wrong in my point of view? > > > Thanks again, > > > Martin > > > > > Hi Martin, Are you plotting the spectrogram by calling the function with no output arguments? If so, you are seeing that the magnitudes are plotted in dB, in which case magnitudes less than 1 result in negative values. > > > > Wayne Hi Martin, the frequency resolution of the spectrogram depends on the number of points and the sampling frequency. Since you have specified your segment length as 20,000 and your sampling frequency as 40,000, your frequency resolution is 2 Hz. There is an inevitable trade off between time and frequency resolution: the longer your segment length, the better the frequency resolution, but within each segment you lose all time resolution. Therefore the shorter the segment length, the better the time resolution, but the poorer the frequency resolution. If you require better frequency resolution, you will need to increase your segment length, but you will lose time resolution. Then specify your vector of frequencies accordingly. If you know your frequency resolution is 1 Hz (say you have doubled your segment length to 40,000 points), then specify your frequencies: f = 2:60; Hope that helps, Wayne
From: Martin on 10 May 2010 08:47 "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs8l6b$q30$1(a)fred.mathworks.com>... > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs8hlb$ca0$1(a)fred.mathworks.com>... > > Hi Wayne, > > > > yes, I am plotting the spectrogram by calling the function with no output arguments. I also tried it with output arguments but then I get only the values and not the diagram (spectrogram), don't I? > > The explanation with the dB makes sence, it was also one of my ideas. > > I tried to specify the frequency range as you recommended. > > I am interested only in the range up to 60 Hz so the following syntax: > > > > spectrogram(dc_current,2e4,18e3,2:0.01:60,4e4,'yaxis') > > > > I have now the range of frequencies 2...60 Hz with a step of 0.01 Hz. But the spectrogram has the resolution of about 2 Hz. What is the reason? I have to do something wrong... I need the frequencies for resonance investigation and such a resolution doesn't tell me anything... > > Do you have any idea? It would help me a lot. > > > > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs79s3$ng9$1(a)fred.mathworks.com>... > > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs4ias$7a$1(a)fred.mathworks.com>... > > > > > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs4hih$bn6$1(a)fred.mathworks.com>... > > > > > > Hi everyone > > > > > > > > > > > > I need a help with 'spectrogram' function. It makes FFT of my signal and plots it with time and frequency on the axis and the magnitude of frequency showed with color. > > > > > > The frequency range of FFT algorithm depends on the sampling frequency. > > > > > > In my case the sampling frequency is very high (160 kHz), but as the result I focus just on the range 0-60 Hz. Can I modify spectrogram to compute the fft only up to 60 Hz? > > > > > > I can change the range in Axes properties but in this way I loose the information of magnitude (displayed with color) because I just cut a very small piece from wide frequency range > > > > > > > > > > > > Thank you for your help and tips. > > > > > > > > > > > > Martin Bruha > > > > > > > > > > Hi Martin, you can use the syntax > > > > > > > > > > [S,F,T]=spectrogram(x,window,noverlap,F,fs) > > > > > > > > > > See the documentation. You can specify a vector of frequencies,F, at which to compute the short-time Fourier transform. > > > > > > > > > > Also, you can always manipulate the colormap, or use caxis() so that you color your plot the way you wish. > > > > > > > > > > Hope that helps, > > > > > Wayne > > > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs6ui8$1em$1(a)fred.mathworks.com>... > > > > Hi Waine > > > > thanks for the tips, I will check it now. Maybe one more question: I get the diagram using spectrogram function and then in the options I choose to add a colorbar. I wonder why about 60% of the range in colorbar is negative (like -100...+60). The color represents the magnitude of certain frequency component at certain time. How can it be negative? Or is there something wrong in my point of view? > > > > Thanks again, > > > > Martin > > > > > > > Hi Martin, Are you plotting the spectrogram by calling the function with no output arguments? If so, you are seeing that the magnitudes are plotted in dB, in which case magnitudes less than 1 result in negative values. > > > > > > Wayne > > Hi Martin, the frequency resolution of the spectrogram depends on the number of points and the sampling frequency. Since you have specified your segment length as 20,000 and your sampling frequency as 40,000, your frequency resolution is 2 Hz. There is an inevitable trade off between time and frequency resolution: the longer your segment length, the better the frequency resolution, but within each segment you lose all time resolution. Therefore the shorter the segment length, the better the time resolution, but the poorer the frequency resolution. If you require better frequency resolution, you will need to increase your segment length, but you will lose time resolution. Then specify your vector of frequencies accordingly. If you know your frequency resolution is 1 Hz (say you have doubled your segment length to 40,000 points), then specify your frequencies: > > f = 2:60; > > Hope that helps, > Wayne Ok, I start to understand it. Unfortunately I have still 2 more problems: 1) the first one is that I need to adjust the colors in the spectrogram diagram. I tried to use the caxis() command as you recommended. I noticed that by changing the cmin and cmax in caxis([cmin,cmax]) I can change the colors of the point in spectrogram but the range in the colorbar remains the same. So I understand it that certain point changes the color but also the magnitude which destroys the original information from the recorded signal. 2) the other problem is that I would prefer to have the magnitude axis linear instead of log. Could you advise me how to do it? Thank you so much for the huge help so far. Martin
From: Martin on 10 May 2010 09:24 "Martin " <martin.bruha(a)gmail.com> wrote in message <hs8v8p$haa$1(a)fred.mathworks.com>... > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs8l6b$q30$1(a)fred.mathworks.com>... > > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs8hlb$ca0$1(a)fred.mathworks.com>... > > > Hi Wayne, > > > > > > yes, I am plotting the spectrogram by calling the function with no output arguments. I also tried it with output arguments but then I get only the values and not the diagram (spectrogram), don't I? > > > The explanation with the dB makes sence, it was also one of my ideas. > > > I tried to specify the frequency range as you recommended. > > > I am interested only in the range up to 60 Hz so the following syntax: > > > > > > spectrogram(dc_current,2e4,18e3,2:0.01:60,4e4,'yaxis') > > > > > > I have now the range of frequencies 2...60 Hz with a step of 0.01 Hz. But the spectrogram has the resolution of about 2 Hz. What is the reason? I have to do something wrong... I need the frequencies for resonance investigation and such a resolution doesn't tell me anything... > > > Do you have any idea? It would help me a lot. > > > > > > > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs79s3$ng9$1(a)fred.mathworks.com>... > > > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs4ias$7a$1(a)fred.mathworks.com>... > > > > > > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs4hih$bn6$1(a)fred.mathworks.com>... > > > > > > > Hi everyone > > > > > > > > > > > > > > I need a help with 'spectrogram' function. It makes FFT of my signal and plots it with time and frequency on the axis and the magnitude of frequency showed with color. > > > > > > > The frequency range of FFT algorithm depends on the sampling frequency. > > > > > > > In my case the sampling frequency is very high (160 kHz), but as the result I focus just on the range 0-60 Hz. Can I modify spectrogram to compute the fft only up to 60 Hz? > > > > > > > I can change the range in Axes properties but in this way I loose the information of magnitude (displayed with color) because I just cut a very small piece from wide frequency range > > > > > > > > > > > > > > Thank you for your help and tips. > > > > > > > > > > > > > > Martin Bruha > > > > > > > > > > > > Hi Martin, you can use the syntax > > > > > > > > > > > > [S,F,T]=spectrogram(x,window,noverlap,F,fs) > > > > > > > > > > > > See the documentation. You can specify a vector of frequencies,F, at which to compute the short-time Fourier transform. > > > > > > > > > > > > Also, you can always manipulate the colormap, or use caxis() so that you color your plot the way you wish. > > > > > > > > > > > > Hope that helps, > > > > > > Wayne > > > > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs6ui8$1em$1(a)fred.mathworks.com>... > > > > > Hi Waine > > > > > thanks for the tips, I will check it now. Maybe one more question: I get the diagram using spectrogram function and then in the options I choose to add a colorbar. I wonder why about 60% of the range in colorbar is negative (like -100...+60). The color represents the magnitude of certain frequency component at certain time. How can it be negative? Or is there something wrong in my point of view? > > > > > Thanks again, > > > > > Martin > > > > > > > > > Hi Martin, Are you plotting the spectrogram by calling the function with no output arguments? If so, you are seeing that the magnitudes are plotted in dB, in which case magnitudes less than 1 result in negative values. > > > > > > > > Wayne > > > > Hi Martin, the frequency resolution of the spectrogram depends on the number of points and the sampling frequency. Since you have specified your segment length as 20,000 and your sampling frequency as 40,000, your frequency resolution is 2 Hz. There is an inevitable trade off between time and frequency resolution: the longer your segment length, the better the frequency resolution, but within each segment you lose all time resolution. Therefore the shorter the segment length, the better the time resolution, but the poorer the frequency resolution. If you require better frequency resolution, you will need to increase your segment length, but you will lose time resolution. Then specify your vector of frequencies accordingly. If you know your frequency resolution is 1 Hz (say you have doubled your segment length to 40,000 points), then specify your frequencies: > > > > f = 2:60; > > > > Hope that helps, > > Wayne > > Ok, I start to understand it. Unfortunately I have still 2 more problems: > 1) the first one is that I need to adjust the colors in the spectrogram diagram. I tried to use the caxis() command as you recommended. I noticed that by changing the cmin and cmax in caxis([cmin,cmax]) I can change the colors of the point in spectrogram but the range in the colorbar remains the same. So I understand it that certain point changes the color but also the magnitude which destroys the original information from the recorded signal. > 2) the other problem is that I would prefer to have the magnitude axis linear instead of log. Could you advise me how to do it? > Thank you so much for the huge help so far. > Martin I have a correction: The range in the colorbar changes too. I just have to remove the colorbar and add it again, after that it is updated. Anyway, the magnitude of certain point is different by changing the colors with caxis() command. I need to change the color and keep the magnitude information. Martin
From: Martin on 10 May 2010 09:27
"Martin " <martin.bruha(a)gmail.com> wrote in message <hs8v8p$haa$1(a)fred.mathworks.com>... > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs8l6b$q30$1(a)fred.mathworks.com>... > > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs8hlb$ca0$1(a)fred.mathworks.com>... > > > Hi Wayne, > > > > > > yes, I am plotting the spectrogram by calling the function with no output arguments. I also tried it with output arguments but then I get only the values and not the diagram (spectrogram), don't I? > > > The explanation with the dB makes sence, it was also one of my ideas. > > > I tried to specify the frequency range as you recommended. > > > I am interested only in the range up to 60 Hz so the following syntax: > > > > > > spectrogram(dc_current,2e4,18e3,2:0.01:60,4e4,'yaxis') > > > > > > I have now the range of frequencies 2...60 Hz with a step of 0.01 Hz. But the spectrogram has the resolution of about 2 Hz. What is the reason? I have to do something wrong... I need the frequencies for resonance investigation and such a resolution doesn't tell me anything... > > > Do you have any idea? It would help me a lot. > > > > > > > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs79s3$ng9$1(a)fred.mathworks.com>... > > > > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hs4ias$7a$1(a)fred.mathworks.com>... > > > > > > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs4hih$bn6$1(a)fred.mathworks.com>... > > > > > > > Hi everyone > > > > > > > > > > > > > > I need a help with 'spectrogram' function. It makes FFT of my signal and plots it with time and frequency on the axis and the magnitude of frequency showed with color. > > > > > > > The frequency range of FFT algorithm depends on the sampling frequency. > > > > > > > In my case the sampling frequency is very high (160 kHz), but as the result I focus just on the range 0-60 Hz. Can I modify spectrogram to compute the fft only up to 60 Hz? > > > > > > > I can change the range in Axes properties but in this way I loose the information of magnitude (displayed with color) because I just cut a very small piece from wide frequency range > > > > > > > > > > > > > > Thank you for your help and tips. > > > > > > > > > > > > > > Martin Bruha > > > > > > > > > > > > Hi Martin, you can use the syntax > > > > > > > > > > > > [S,F,T]=spectrogram(x,window,noverlap,F,fs) > > > > > > > > > > > > See the documentation. You can specify a vector of frequencies,F, at which to compute the short-time Fourier transform. > > > > > > > > > > > > Also, you can always manipulate the colormap, or use caxis() so that you color your plot the way you wish. > > > > > > > > > > > > Hope that helps, > > > > > > Wayne > > > > "Martin " <martin.bruha(a)gmail.com> wrote in message <hs6ui8$1em$1(a)fred.mathworks.com>... > > > > > Hi Waine > > > > > thanks for the tips, I will check it now. Maybe one more question: I get the diagram using spectrogram function and then in the options I choose to add a colorbar. I wonder why about 60% of the range in colorbar is negative (like -100...+60). The color represents the magnitude of certain frequency component at certain time. How can it be negative? Or is there something wrong in my point of view? > > > > > Thanks again, > > > > > Martin > > > > > > > > > Hi Martin, Are you plotting the spectrogram by calling the function with no output arguments? If so, you are seeing that the magnitudes are plotted in dB, in which case magnitudes less than 1 result in negative values. > > > > > > > > Wayne > > > > Hi Martin, the frequency resolution of the spectrogram depends on the number of points and the sampling frequency. Since you have specified your segment length as 20,000 and your sampling frequency as 40,000, your frequency resolution is 2 Hz. There is an inevitable trade off between time and frequency resolution: the longer your segment length, the better the frequency resolution, but within each segment you lose all time resolution. Therefore the shorter the segment length, the better the time resolution, but the poorer the frequency resolution. If you require better frequency resolution, you will need to increase your segment length, but you will lose time resolution. Then specify your vector of frequencies accordingly. If you know your frequency resolution is 1 Hz (say you have doubled your segment length to 40,000 points), then specify your frequencies: > > > > f = 2:60; > > > > Hope that helps, > > Wayne > > Ok, I start to understand it. Unfortunately I have still 2 more problems: > 1) the first one is that I need to adjust the colors in the spectrogram diagram. I tried to use the caxis() command as you recommended. I noticed that by changing the cmin and cmax in caxis([cmin,cmax]) I can change the colors of the point in spectrogram but the range in the colorbar remains the same. So I understand it that certain point changes the color but also the magnitude which destroys the original information from the recorded signal. > 2) the other problem is that I would prefer to have the magnitude axis linear instead of log. Could you advise me how to do it? > Thank you so much for the huge help so far. > Martin ***************************************************************** Uuups, sorry, I was wrong, please forget the last 2 threads.It works good with caxis()! Now I just need to change the range from log to linear. Martin |